Skip to content

add SysBlockDeviceQueueStat #711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions blockdevice/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,15 @@ func (fs FS) SysBlockDeviceQueueStats(device string) (BlockQueueStats, error) {
return stat, nil
}

// SysBlockDeviceQueueStat returns a single stat from /sys/block/xxx/queue where xxx is a device name and stat is a file.
func (fs FS) SysBlockDeviceQueueStat(device string, file string) (string, error) {
stat, err := util.SysReadFile(fs.sys.Path(sysBlockPath, device, sysBlockQueue, file))
if err != nil {
return "", err
}
return stat, nil
}

func (fs FS) SysBlockDeviceMapperInfo(device string) (DeviceMapperInfo, error) {
info := DeviceMapperInfo{}
// Files with uint64 fields
Expand Down
7 changes: 7 additions & 0 deletions blockdevice/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ func TestBlockDevice(t *testing.T) {
if !reflect.DeepEqual(blockQueueStat, blockQueueStatExpected) {
t.Errorf("Incorrect BlockQueueStat, expected: \n%+v, got: \n%+v", blockQueueStatExpected, blockQueueStat)
}
rotational, err := blockdevice.SysBlockDeviceQueueStat(devices[7], "rotational")
if err != nil {
t.Fatal(err)
}
if rotational != "1" {
t.Errorf("Incorrect BlockQueueStat('rotational'), expected: \n%+v, got: \n%+v", 1, rotational)
}
}

func TestBlockDmInfo(t *testing.T) {
Expand Down