@@ -109,17 +109,12 @@ func (dc *diskCollector) collect() {
109
109
110
110
for deviceName , ioCountersStat := range ioCountersStats {
111
111
// Calculate average IO queue length since last measurement.
112
- lastIOTime := dc .historyIOTime [deviceName ]
112
+ lastIOTime , historyExist := dc .historyIOTime [deviceName ]
113
113
lastWeightedIO := dc .historyWeightedIO [deviceName ]
114
114
115
115
dc .historyIOTime [deviceName ] = ioCountersStat .IoTime
116
116
dc .historyWeightedIO [deviceName ] = ioCountersStat .WeightedIO
117
117
118
- avgQueueLen := float64 (0.0 )
119
- if lastIOTime != ioCountersStat .IoTime {
120
- avgQueueLen = float64 (ioCountersStat .WeightedIO - lastWeightedIO ) / float64 (ioCountersStat .IoTime - lastIOTime )
121
- }
122
-
123
118
// Attach label {"device_name": deviceName} to the metrics.
124
119
tags := map [string ]string {deviceNameLabel : deviceName }
125
120
if dc .mIOTime != nil {
@@ -128,8 +123,14 @@ func (dc *diskCollector) collect() {
128
123
if dc .mWeightedIO != nil {
129
124
dc .mWeightedIO .Record (tags , int64 (ioCountersStat .WeightedIO - lastWeightedIO ))
130
125
}
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
+ }
133
134
}
134
135
}
135
136
}
0 commit comments