Merge pull request #15320 from hqhq/hq_add_cgroup_check

Check sysinfo for Cpuset cpu.shares and blkio
This commit is contained in:
David Calavera 2015-08-06 14:23:37 -07:00
commit ef9b1b6b70
2 changed files with 53 additions and 0 deletions

View file

@ -8,6 +8,8 @@ type SysInfo struct {
*cgroupMemInfo
*cgroupCPUInfo
*cgroupBlkioInfo
*cgroupCpusetInfo
// Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work
IPv4ForwardingDisabled bool
@ -37,9 +39,22 @@ type cgroupMemInfo struct {
}
type cgroupCPUInfo struct {
// Whether CPU shares is supported or not
CPUShares bool
// Whether CPU CFS(Completely Fair Scheduler) period is supported or not
CPUCfsPeriod bool
// Whether CPU CFS(Completely Fair Scheduler) quota is supported or not
CPUCfsQuota bool
}
type cgroupBlkioInfo struct {
// Whether Block IO weight is supported or not
BlkioWeight bool
}
type cgroupCpusetInfo struct {
// Whether Cpuset is supported or not
Cpuset bool
}

View file

@ -15,6 +15,8 @@ func New(quiet bool) *SysInfo {
sysInfo := &SysInfo{}
sysInfo.cgroupMemInfo = checkCgroupMem(quiet)
sysInfo.cgroupCPUInfo = checkCgroupCPU(quiet)
sysInfo.cgroupBlkioInfo = checkCgroupBlkioInfo(quiet)
sysInfo.cgroupCpusetInfo = checkCgroupCpusetInfo(quiet)
_, err := cgroups.FindCgroupMountpoint("devices")
sysInfo.CgroupDevicesEnabled = err == nil
@ -68,6 +70,11 @@ func checkCgroupCPU(quiet bool) *cgroupCPUInfo {
return info
}
info.CPUShares = cgroupEnabled(mountPoint, "cpu.shares")
if !quiet && !info.CPUShares {
logrus.Warn("Your kernel does not support cgroup cpu shares")
}
info.CPUCfsPeriod = cgroupEnabled(mountPoint, "cpu.cfs_period_us")
if !quiet && !info.CPUCfsPeriod {
logrus.Warn("Your kernel does not support cgroup cfs period")
@ -80,6 +87,37 @@ func checkCgroupCPU(quiet bool) *cgroupCPUInfo {
return info
}
func checkCgroupBlkioInfo(quiet bool) *cgroupBlkioInfo {
info := &cgroupBlkioInfo{}
mountPoint, err := cgroups.FindCgroupMountpoint("blkio")
if err != nil {
if !quiet {
logrus.Warn(err)
}
return info
}
info.BlkioWeight = cgroupEnabled(mountPoint, "blkio.weight")
if !quiet && !info.BlkioWeight {
logrus.Warn("Your kernel does not support cgroup blkio weight")
}
return info
}
func checkCgroupCpusetInfo(quiet bool) *cgroupCpusetInfo {
info := &cgroupCpusetInfo{}
_, err := cgroups.FindCgroupMountpoint("cpuset")
if err != nil {
if !quiet {
logrus.Warn(err)
}
return info
}
info.Cpuset = true
return info
}
func cgroupEnabled(mountPoint, name string) bool {
_, err := os.Stat(path.Join(mountPoint, name))
return err == nil