Add flush request and time spend flushing diskstats for kernel 5.5+ (#289)
* add flush request and time spend flushing diskstats for kernel 5.5+
Signed-off-by: binjip978 <binjip978@gmail.com>
* add diskstats if at least 14 params are present
Signed-off-by: binjip978 <binjip978@gmail.com>
Sergei Sementchouk authored 4 years ago
GitHub committed 4 years ago
68 | 68 |
DiscardSectors uint64
|
69 | 69 |
// DiscardTicks is the total number of milliseconds spent by all discards.
|
70 | 70 |
DiscardTicks uint64
|
|
71 |
// FlushRequestsCompleted is the total number of flush request completed successfully.
|
|
72 |
FlushRequestsCompleted uint64
|
|
73 |
// TimeSpentFlushing is the total number of milliseconds spent flushing.
|
|
74 |
TimeSpentFlushing uint64
|
71 | 75 |
}
|
72 | 76 |
|
73 | 77 |
// Diskstats combines the device Info and IOStats
|
74 | 78 |
type Diskstats struct {
|
75 | 79 |
Info
|
76 | 80 |
IOStats
|
77 | |
// IoStatsCount contains the number of io stats read. For kernel versions
|
78 | |
// 4.18+, there should be 18 fields read. For earlier kernel versions this
|
|
81 |
// IoStatsCount contains the number of io stats read. For kernel versions 5.5+,
|
|
82 |
// there should be 20 fields read. For kernel versions 4.18+,
|
|
83 |
// there should be 18 fields read. For earlier kernel versions this
|
79 | 84 |
// will be 14 because the discard values are not available.
|
80 | 85 |
IoStatsCount int
|
81 | 86 |
}
|
82 | 87 |
|
83 | 88 |
const (
|
84 | 89 |
procDiskstatsPath = "diskstats"
|
85 | |
procDiskstatsFormat = "%d %d %s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"
|
|
90 |
procDiskstatsFormat = "%d %d %s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"
|
86 | 91 |
sysBlockPath = "block"
|
87 | 92 |
sysBlockStatFormat = "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"
|
88 | 93 |
)
|
|
152 | 157 |
&d.DiscardMerges,
|
153 | 158 |
&d.DiscardSectors,
|
154 | 159 |
&d.DiscardTicks,
|
|
160 |
&d.FlushRequestsCompleted,
|
|
161 |
&d.TimeSpentFlushing,
|
155 | 162 |
)
|
156 | 163 |
// The io.EOF error can be safely ignored because it just means we read fewer than
|
157 | |
// the full 18 fields.
|
|
164 |
// the full 20 fields.
|
158 | 165 |
if err != nil && err != io.EOF {
|
159 | 166 |
return diskstats, err
|
160 | 167 |
}
|
161 | |
if d.IoStatsCount == 14 || d.IoStatsCount == 18 {
|
|
168 |
if d.IoStatsCount >= 14 {
|
162 | 169 |
diskstats = append(diskstats, *d)
|
163 | 170 |
}
|
164 | 171 |
}
|
31 | 31 |
if err != nil {
|
32 | 32 |
t.Fatal(err)
|
33 | 33 |
}
|
34 | |
expectedNumOfDevices := 49
|
|
34 |
expectedNumOfDevices := 52
|
35 | 35 |
if len(diskstats) != expectedNumOfDevices {
|
36 | 36 |
t.Errorf(failMsgFormat, "Incorrect number of devices", expectedNumOfDevices, len(diskstats))
|
37 | 37 |
}
|
|
49 | 49 |
}
|
50 | 50 |
if diskstats[48].IoStatsCount != 18 {
|
51 | 51 |
t.Errorf(failMsgFormat, "Incorrect number of stats read", 18, diskstats[48].IoStatsCount)
|
|
52 |
}
|
|
53 |
if diskstats[49].IoStatsCount != 20 {
|
|
54 |
t.Errorf(failMsgFormat, "Incorrect number of stats read", 20, diskstats[50].IoStatsCount)
|
|
55 |
}
|
|
56 |
if diskstats[49].FlushRequestsCompleted != 127 {
|
|
57 |
t.Errorf(failMsgFormat, "Incorrect number of flash requests completed", 127, diskstats[50].FlushRequestsCompleted)
|
|
58 |
}
|
|
59 |
if diskstats[49].TimeSpentFlushing != 182 {
|
|
60 |
t.Errorf(failMsgFormat, "Incorrect time spend flushing", 182, diskstats[50].TimeSpentFlushing)
|
52 | 61 |
}
|
53 | 62 |
}
|
54 | 63 |
|
1840 | 1840 |
Mode: 444
|
1841 | 1841 |
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
1842 | 1842 |
Path: fixtures/proc/diskstats
|
1843 | |
Lines: 49
|
|
1843 |
Lines: 52
|
1844 | 1844 |
1 0 ram0 0 0 0 0 0 0 0 0 0 0 0
|
1845 | 1845 |
1 1 ram1 0 0 0 0 0 0 0 0 0 0 0
|
1846 | 1846 |
1 2 ram2 0 0 0 0 0 0 0 0 0 0 0
|
|
1890 | 1890 |
8 0 sdb 326552 841 9657779 84 41822 2895 1972905 5007 0 60730 67070 68851 0 1925173784 11130
|
1891 | 1891 |
8 1 sdb1 231 3 34466 4 24 23 106 0 0 64 64 0 0 0 0
|
1892 | 1892 |
8 2 sdb2 326310 838 9622281 67 40726 2872 1972799 4924 0 58250 64567 68851 0 1925173784 11130
|
|
1893 |
8 0 sdc 14202 71 579164 21861 2995 1589 180500 40875 0 11628 55200 0 0 0 0 127 182
|
|
1894 |
8 1 sdc1 1027 0 13795 5021 2 0 4096 3 0 690 4579 0 0 0 0 0 0
|
|
1895 |
8 2 sdc2 13126 71 561749 16802 2830 1589 176404 40620 0 10931 50449 0 0 0 0 0 0
|
1893 | 1896 |
Mode: 664
|
1894 | 1897 |
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
1895 | 1898 |
Directory: fixtures/proc/fs
|