@@ -29,6 +29,8 @@ import (
29
29
"k8s.io/node-problem-detector/pkg/util/metrics"
30
30
)
31
31
32
+ const deviceNameLabel = "device_name"
33
+
32
34
type diskCollector struct {
33
35
mIOTime * metrics.Int64Metric
34
36
mWeightedIO * metrics.Int64Metric
@@ -44,22 +46,25 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
44
46
dc := diskCollector {config : diskConfig }
45
47
46
48
var err error
49
+
50
+ // Use metrics.Sum aggregation method to ensure the metric is a counter/cumulative metric.
47
51
dc .mIOTime , err = metrics .NewInt64Metric (
48
52
diskConfig .MetricsConfigs ["disk/io_time" ].DisplayName ,
49
53
"The IO time spent on the disk" ,
50
54
"second" ,
51
- metrics .LastValue ,
52
- []string {"device" })
55
+ metrics .Sum ,
56
+ []string {deviceNameLabel })
53
57
if err != nil {
54
58
glog .Fatalf ("Error initializing metric for disk/io_time: %v" , err )
55
59
}
56
60
61
+ // Use metrics.Sum aggregation method to ensure the metric is a counter/cumulative metric.
57
62
dc .mWeightedIO , err = metrics .NewInt64Metric (
58
63
diskConfig .MetricsConfigs ["disk/weighted_io" ].DisplayName ,
59
64
"The weighted IO on the disk" ,
60
65
"second" ,
61
- metrics .LastValue ,
62
- []string {"device" })
66
+ metrics .Sum ,
67
+ []string {deviceNameLabel })
63
68
if err != nil {
64
69
glog .Fatalf ("Error initializing metric for disk/weighted_io: %v" , err )
65
70
}
@@ -69,7 +74,7 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
69
74
"The average queue length on the disk" ,
70
75
"second" ,
71
76
metrics .LastValue ,
72
- []string {"device" })
77
+ []string {deviceNameLabel })
73
78
if err != nil {
74
79
glog .Fatalf ("Error initializing metric for disk/avg_queue_len: %v" , err )
75
80
}
@@ -112,13 +117,13 @@ func (dc *diskCollector) collect() {
112
117
avgQueueLen = float64 (ioCountersStat .WeightedIO - lastWeightedIO ) / float64 (ioCountersStat .IoTime - lastIOTime )
113
118
}
114
119
115
- // Attach label {"device ": deviceName} to the metrics.
116
- tags := map [string ]string {"device" : deviceName }
120
+ // Attach label {"device_name ": deviceName} to the metrics.
121
+ tags := map [string ]string {deviceNameLabel : deviceName }
117
122
if dc .mIOTime != nil {
118
- dc .mIOTime .Record (tags , int64 (ioCountersStat .IoTime ))
123
+ dc .mIOTime .Record (tags , int64 (ioCountersStat .IoTime - lastIOTime ))
119
124
}
120
125
if dc .mWeightedIO != nil {
121
- dc .mWeightedIO .Record (tags , int64 (ioCountersStat .WeightedIO ))
126
+ dc .mWeightedIO .Record (tags , int64 (ioCountersStat .WeightedIO - lastWeightedIO ))
122
127
}
123
128
if dc .mAvgQueueLen != nil {
124
129
dc .mAvgQueueLen .Record (tags , avgQueueLen )
0 commit comments