@@ -40,6 +40,7 @@ type diskCollector struct {
40
40
41
41
historyIOTime map [string ]uint64
42
42
historyWeightedIO map [string ]uint64
43
+ lastSampleTime time.Time
43
44
}
44
45
45
46
func NewDiskCollectorOrDie (diskConfig * ssmtypes.DiskStatsConfig ) * diskCollector {
@@ -52,7 +53,7 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
52
53
metrics .DiskIOTimeID ,
53
54
diskConfig .MetricsConfigs [string (metrics .DiskIOTimeID )].DisplayName ,
54
55
"The IO time spent on the disk" ,
55
- "second " ,
56
+ "ms " ,
56
57
metrics .Sum ,
57
58
[]string {deviceNameLabel })
58
59
if err != nil {
@@ -64,7 +65,7 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
64
65
metrics .DiskWeightedIOID ,
65
66
diskConfig .MetricsConfigs [string (metrics .DiskWeightedIOID )].DisplayName ,
66
67
"The weighted IO on the disk" ,
67
- "second " ,
68
+ "ms " ,
68
69
metrics .Sum ,
69
70
[]string {deviceNameLabel })
70
71
if err != nil {
@@ -75,7 +76,7 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
75
76
metrics .DiskAvgQueueLenID ,
76
77
diskConfig .MetricsConfigs [string (metrics .DiskAvgQueueLenID )].DisplayName ,
77
78
"The average queue length on the disk" ,
78
- "second " ,
79
+ "1 " ,
79
80
metrics .LastValue ,
80
81
[]string {deviceNameLabel })
81
82
if err != nil {
@@ -107,13 +108,17 @@ func (dc *diskCollector) collect() {
107
108
return
108
109
}
109
110
111
+ sampleTime := time .Now ()
112
+
110
113
for deviceName , ioCountersStat := range ioCountersStats {
111
114
// Calculate average IO queue length since last measurement.
112
115
lastIOTime , historyExist := dc .historyIOTime [deviceName ]
113
116
lastWeightedIO := dc .historyWeightedIO [deviceName ]
117
+ lastSampleTime := dc .lastSampleTime
114
118
115
119
dc .historyIOTime [deviceName ] = ioCountersStat .IoTime
116
120
dc .historyWeightedIO [deviceName ] = ioCountersStat .WeightedIO
121
+ dc .lastSampleTime = sampleTime
117
122
118
123
// Attach label {"device_name": deviceName} to the metrics.
119
124
tags := map [string ]string {deviceNameLabel : deviceName }
@@ -125,8 +130,9 @@ func (dc *diskCollector) collect() {
125
130
}
126
131
if historyExist {
127
132
avgQueueLen := float64 (0.0 )
128
- if lastIOTime != ioCountersStat .IoTime {
129
- avgQueueLen = float64 (ioCountersStat .WeightedIO - lastWeightedIO ) / float64 (ioCountersStat .IoTime - lastIOTime )
133
+ if lastWeightedIO != ioCountersStat .WeightedIO {
134
+ diffSampleTimeMs := sampleTime .Sub (lastSampleTime ).Seconds () * 1000
135
+ avgQueueLen = float64 (ioCountersStat .WeightedIO - lastWeightedIO ) / diffSampleTimeMs
130
136
}
131
137
if dc .mAvgQueueLen != nil {
132
138
dc .mAvgQueueLen .Record (tags , avgQueueLen )
0 commit comments