From acf3fef0368d1e46bb06cc1f59e72e17a1d733d0 Mon Sep 17 00:00:00 2001 From: Marc Magnin Date: Wed, 21 Sep 2016 23:48:49 +0200 Subject: [PATCH 1/2] added weightedIO field to disk IOCountersStat (last field of /etc/mtab) --- disk/disk.go | 1 + disk/disk_linux.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/disk/disk.go b/disk/disk.go index 0f310e7..a2c4720 100644 --- a/disk/disk.go +++ b/disk/disk.go @@ -43,6 +43,7 @@ type IOCountersStat struct { WriteTime uint64 `json:"writeTime"` IopsInProgress uint64 `json:"iopsInProgress"` IoTime uint64 `json:"ioTime"` + WeightedIO uint64 `json:"weightedIO"` Name string `json:"name"` SerialNumber string `json:"serialNumber"` } diff --git a/disk/disk_linux.go b/disk/disk_linux.go index a9c1bc8..51f17cd 100644 --- a/disk/disk_linux.go +++ b/disk/disk_linux.go @@ -328,6 +328,10 @@ func IOCounters() (map[string]IOCountersStat, error) { if err != nil { return ret, err } + weightedIO, err := strconv.ParseUint((fields[13]), 10, 64) + if err != nil { + return ret, err + } d := IOCountersStat{ ReadBytes: rbytes * SectorSize, WriteBytes: wbytes * SectorSize, @@ -339,6 +343,7 @@ func IOCounters() (map[string]IOCountersStat, error) { WriteTime: wtime, IopsInProgress: iopsInProgress, IoTime: iotime, + WeightedIO: weightedIO, } if d == empty { continue From 31f4fb8deec880cf0a8b06234ccd4b9c9ec1575f Mon Sep 17 00:00:00 2001 From: Marc Magnin Date: Thu, 22 Sep 2016 00:03:48 +0200 Subject: [PATCH 2/2] fixed test TestDiskIOCountersStat_String to consider new weightedIO field --- disk/disk_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/disk/disk_test.go b/disk/disk_test.go index 6806ef4..436b8a5 100644 --- a/disk/disk_test.go +++ b/disk/disk_test.go @@ -93,7 +93,7 @@ func TestDiskIOCountersStat_String(t *testing.T) { WriteBytes: 400, SerialNumber: "SERIAL", } - e := `{"readCount":100,"mergedReadCount":0,"writeCount":200,"mergedWriteCount":0,"readBytes":300,"writeBytes":400,"readTime":0,"writeTime":0,"iopsInProgress":0,"ioTime":0,"name":"sd01","serialNumber":"SERIAL"}` + e := `{"readCount":100,"mergedReadCount":0,"writeCount":200,"mergedWriteCount":0,"readBytes":300,"writeBytes":400,"readTime":0,"writeTime":0,"iopsInProgress":0,"ioTime":0,"weightedIO":0,"name":"sd01","serialNumber":"SERIAL"}` if e != fmt.Sprintf("%v", v) { t.Errorf("DiskUsageStat string is invalid: %v", v) }