Skip to content

Commit 0d0bba9

Browse files
authored
Merge pull request #402 from gmemcc/master
Ignore first collected disk stats to prevent metric distortion
2 parents 7819ffd + 5a4ac81 commit 0d0bba9

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

pkg/systemstatsmonitor/disk_collector.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,12 @@ func (dc *diskCollector) collect() {
109109

110110
for deviceName, ioCountersStat := range ioCountersStats {
111111
// Calculate average IO queue length since last measurement.
112-
lastIOTime := dc.historyIOTime[deviceName]
112+
lastIOTime, historyExist := dc.historyIOTime[deviceName]
113113
lastWeightedIO := dc.historyWeightedIO[deviceName]
114114

115115
dc.historyIOTime[deviceName] = ioCountersStat.IoTime
116116
dc.historyWeightedIO[deviceName] = ioCountersStat.WeightedIO
117117

118-
avgQueueLen := float64(0.0)
119-
if lastIOTime != ioCountersStat.IoTime {
120-
avgQueueLen = float64(ioCountersStat.WeightedIO-lastWeightedIO) / float64(ioCountersStat.IoTime-lastIOTime)
121-
}
122-
123118
// Attach label {"device_name": deviceName} to the metrics.
124119
tags := map[string]string{deviceNameLabel: deviceName}
125120
if dc.mIOTime != nil {
@@ -128,8 +123,14 @@ func (dc *diskCollector) collect() {
128123
if dc.mWeightedIO != nil {
129124
dc.mWeightedIO.Record(tags, int64(ioCountersStat.WeightedIO-lastWeightedIO))
130125
}
131-
if dc.mAvgQueueLen != nil {
132-
dc.mAvgQueueLen.Record(tags, avgQueueLen)
126+
if historyExist {
127+
avgQueueLen := float64(0.0)
128+
if lastIOTime != ioCountersStat.IoTime {
129+
avgQueueLen = float64(ioCountersStat.WeightedIO-lastWeightedIO) / float64(ioCountersStat.IoTime-lastIOTime)
130+
}
131+
if dc.mAvgQueueLen != nil {
132+
dc.mAvgQueueLen.Record(tags, avgQueueLen)
133+
}
133134
}
134135
}
135136
}

0 commit comments

Comments
 (0)