From 6986fd5e3db6debafae5b56592529f5afd71a8a1 Mon Sep 17 00:00:00 2001 From: Ma Shimiao Date: Wed, 8 Jul 2015 19:06:48 +0800 Subject: [PATCH] Add support for blkio read/write bps device Signed-off-by: Ma Shimiao --- blkiodev/blkiodev.go | 10 ++++++++++ sysinfo/sysinfo.go | 6 ++++++ sysinfo/sysinfo_linux.go | 16 ++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/blkiodev/blkiodev.go b/blkiodev/blkiodev.go index 84cdbd7..e9a3649 100644 --- a/blkiodev/blkiodev.go +++ b/blkiodev/blkiodev.go @@ -13,3 +13,13 @@ type WeightDevice struct { func (w *WeightDevice) String() string { return fmt.Sprintf("%s:%d", w.Path, w.Weight) } + +// ThrottleDevice is a structure that hold device:rate_per_second pair +type ThrottleDevice struct { + Path string + Rate uint64 +} + +func (t *ThrottleDevice) String() string { + return fmt.Sprintf("%s:%d", t.Path, t.Rate) +} diff --git a/sysinfo/sysinfo.go b/sysinfo/sysinfo.go index 580b6ba..c12619f 100644 --- a/sysinfo/sysinfo.go +++ b/sysinfo/sysinfo.go @@ -63,6 +63,12 @@ type cgroupBlkioInfo struct { // Whether Block IO weight_device is supported or not BlkioWeightDevice bool + + // Whether Block IO read limit in bytes per second is supported or not + BlkioReadBpsDevice bool + + // Whether Block IO write limit in bytes per second is supported or not + BlkioWriteBpsDevice bool } type cgroupCpusetInfo struct { diff --git a/sysinfo/sysinfo_linux.go b/sysinfo/sysinfo_linux.go index a93e781..e30e79a 100644 --- a/sysinfo/sysinfo_linux.go +++ b/sysinfo/sysinfo_linux.go @@ -126,9 +126,21 @@ func checkCgroupBlkioInfo(quiet bool) cgroupBlkioInfo { if !quiet && !weightDevice { logrus.Warn("Your kernel does not support cgroup blkio weight_device") } + + readBpsDevice := cgroupEnabled(mountPoint, "blkio.throttle.read_bps_device") + if !quiet && !readBpsDevice { + logrus.Warn("Your kernel does not support cgroup blkio throttle.read_bps_device") + } + + writeBpsDevice := cgroupEnabled(mountPoint, "blkio.throttle.write_bps_device") + if !quiet && !writeBpsDevice { + logrus.Warn("Your kernel does not support cgroup blkio throttle.write_bps_device") + } return cgroupBlkioInfo{ - BlkioWeight: weight, - BlkioWeightDevice: weightDevice, + BlkioWeight: weight, + BlkioWeightDevice: weightDevice, + BlkioReadBpsDevice: readBpsDevice, + BlkioWriteBpsDevice: writeBpsDevice, } }