本文整理匯總了Golang中github.com/google/cadvisor/utils/sysfs.SysFs.GetBlockDeviceScheduler方法的典型用法代碼示例。如果您正苦於以下問題:Golang SysFs.GetBlockDeviceScheduler方法的具體用法?Golang SysFs.GetBlockDeviceScheduler怎麽用?Golang SysFs.GetBlockDeviceScheduler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/google/cadvisor/utils/sysfs.SysFs
的用法示例。
在下文中一共展示了SysFs.GetBlockDeviceScheduler方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetBlockDeviceInfo
// Get information about block devices present on the system.
// Uses the passed in system interface to retrieve the low level OS information.
func GetBlockDeviceInfo(sysfs sysfs.SysFs) (map[string]info.DiskInfo, error) {
disks, err := sysfs.GetBlockDevices()
if err != nil {
return nil, err
}
diskMap := make(map[string]info.DiskInfo)
for _, disk := range disks {
name := disk.Name()
// Ignore non-disk devices.
// TODO(rjnagal): Maybe just match hd, sd, and dm prefixes.
if strings.HasPrefix(name, "loop") || strings.HasPrefix(name, "ram") || strings.HasPrefix(name, "sr") {
continue
}
disk_info := info.DiskInfo{
Name: name,
}
dev, err := sysfs.GetBlockDeviceNumbers(name)
if err != nil {
return nil, err
}
n, err := fmt.Sscanf(dev, "%d:%d", &disk_info.Major, &disk_info.Minor)
if err != nil || n != 2 {
return nil, fmt.Errorf("could not parse device numbers from %s for device %s", dev, name)
}
out, err := sysfs.GetBlockDeviceSize(name)
if err != nil {
return nil, err
}
// Remove trailing newline before conversion.
size, err := strconv.ParseUint(strings.TrimSpace(out), 10, 64)
if err != nil {
return nil, err
}
// size is in 512 bytes blocks.
disk_info.Size = size * 512
sched, err := sysfs.GetBlockDeviceScheduler(name)
if err != nil {
sched = "none"
} else {
matches := schedulerRegExp.FindSubmatch([]byte(sched))
if len(matches) < 2 {
sched = "none"
} else {
sched = string(matches[1])
}
}
disk_info.Scheduler = sched
device := fmt.Sprintf("%d:%d", disk_info.Major, disk_info.Minor)
diskMap[device] = disk_info
}
return diskMap, nil
}