Codebase list golang-procfs / 7a44272
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
3 changed file(s) with 26 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
6868 DiscardSectors uint64
6969 // DiscardTicks is the total number of milliseconds spent by all discards.
7070 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
7175 }
7276
7377 // Diskstats combines the device Info and IOStats
7478 type Diskstats struct {
7579 Info
7680 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
7984 // will be 14 because the discard values are not available.
8085 IoStatsCount int
8186 }
8287
8388 const (
8489 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"
8691 sysBlockPath = "block"
8792 sysBlockStatFormat = "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"
8893 )
152157 &d.DiscardMerges,
153158 &d.DiscardSectors,
154159 &d.DiscardTicks,
160 &d.FlushRequestsCompleted,
161 &d.TimeSpentFlushing,
155162 )
156163 // 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.
158165 if err != nil && err != io.EOF {
159166 return diskstats, err
160167 }
161 if d.IoStatsCount == 14 || d.IoStatsCount == 18 {
168 if d.IoStatsCount >= 14 {
162169 diskstats = append(diskstats, *d)
163170 }
164171 }
3131 if err != nil {
3232 t.Fatal(err)
3333 }
34 expectedNumOfDevices := 49
34 expectedNumOfDevices := 52
3535 if len(diskstats) != expectedNumOfDevices {
3636 t.Errorf(failMsgFormat, "Incorrect number of devices", expectedNumOfDevices, len(diskstats))
3737 }
4949 }
5050 if diskstats[48].IoStatsCount != 18 {
5151 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)
5261 }
5362 }
5463
18401840 Mode: 444
18411841 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
18421842 Path: fixtures/proc/diskstats
1843 Lines: 49
1843 Lines: 52
18441844 1 0 ram0 0 0 0 0 0 0 0 0 0 0 0
18451845 1 1 ram1 0 0 0 0 0 0 0 0 0 0 0
18461846 1 2 ram2 0 0 0 0 0 0 0 0 0 0 0
18901890 8 0 sdb 326552 841 9657779 84 41822 2895 1972905 5007 0 60730 67070 68851 0 1925173784 11130
18911891 8 1 sdb1 231 3 34466 4 24 23 106 0 0 64 64 0 0 0 0
18921892 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
18931896 Mode: 664
18941897 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
18951898 Directory: fixtures/proc/fs