Skip to content

Commit 140a850

Browse files
authored
Merge pull request #404 from xueweiz/queue
Fix disk metrics unit and queue_length calculation
2 parents 0d0bba9 + fa7a3d7 commit 140a850

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pkg/systemstatsmonitor/disk_collector.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type diskCollector struct {
4040

4141
historyIOTime map[string]uint64
4242
historyWeightedIO map[string]uint64
43+
lastSampleTime time.Time
4344
}
4445

4546
func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector {
@@ -52,7 +53,7 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
5253
metrics.DiskIOTimeID,
5354
diskConfig.MetricsConfigs[string(metrics.DiskIOTimeID)].DisplayName,
5455
"The IO time spent on the disk",
55-
"second",
56+
"ms",
5657
metrics.Sum,
5758
[]string{deviceNameLabel})
5859
if err != nil {
@@ -64,7 +65,7 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
6465
metrics.DiskWeightedIOID,
6566
diskConfig.MetricsConfigs[string(metrics.DiskWeightedIOID)].DisplayName,
6667
"The weighted IO on the disk",
67-
"second",
68+
"ms",
6869
metrics.Sum,
6970
[]string{deviceNameLabel})
7071
if err != nil {
@@ -75,7 +76,7 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
7576
metrics.DiskAvgQueueLenID,
7677
diskConfig.MetricsConfigs[string(metrics.DiskAvgQueueLenID)].DisplayName,
7778
"The average queue length on the disk",
78-
"second",
79+
"1",
7980
metrics.LastValue,
8081
[]string{deviceNameLabel})
8182
if err != nil {
@@ -107,13 +108,17 @@ func (dc *diskCollector) collect() {
107108
return
108109
}
109110

111+
sampleTime := time.Now()
112+
110113
for deviceName, ioCountersStat := range ioCountersStats {
111114
// Calculate average IO queue length since last measurement.
112115
lastIOTime, historyExist := dc.historyIOTime[deviceName]
113116
lastWeightedIO := dc.historyWeightedIO[deviceName]
117+
lastSampleTime := dc.lastSampleTime
114118

115119
dc.historyIOTime[deviceName] = ioCountersStat.IoTime
116120
dc.historyWeightedIO[deviceName] = ioCountersStat.WeightedIO
121+
dc.lastSampleTime = sampleTime
117122

118123
// Attach label {"device_name": deviceName} to the metrics.
119124
tags := map[string]string{deviceNameLabel: deviceName}
@@ -125,8 +130,9 @@ func (dc *diskCollector) collect() {
125130
}
126131
if historyExist {
127132
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
130136
}
131137
if dc.mAvgQueueLen != nil {
132138
dc.mAvgQueueLen.Record(tags, avgQueueLen)

0 commit comments

Comments
 (0)