@@ -38,6 +38,7 @@ type diskCollector struct {
3838 mOpsBytes * metrics.Int64Metric
3939 mOpsTime * metrics.Int64Metric
4040 mBytesUsed * metrics.Int64Metric
41+ mPercentUsed * metrics.Float64Metric
4142
4243 config * ssmtypes.DiskStatsConfig
4344
@@ -150,6 +151,17 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
150151 klog .Fatalf ("Error initializing metric for %q: %v" , metrics .DiskBytesUsedID , err )
151152 }
152153
154+ dc .mPercentUsed , err = metrics .NewFloat64Metric (
155+ metrics .DiskPercentUsedID ,
156+ diskConfig .MetricsConfigs [string (metrics .DiskPercentUsedID )].DisplayName ,
157+ "Disk usage in percentage of total space" ,
158+ "%" ,
159+ metrics .LastValue ,
160+ []string {deviceNameLabel })
161+ if err != nil {
162+ klog .Fatalf ("Error initializing metric for %q: %v" , metrics .DiskPercentUsedID , err )
163+ }
164+
153165 dc .lastIOTime = make (map [string ]uint64 )
154166 dc .lastWeightedIO = make (map [string ]uint64 )
155167 dc .lastReadCount = make (map [string ]uint64 )
@@ -291,6 +303,9 @@ func (dc *diskCollector) collect() {
291303 opttypes := strings .Join (partition .Opts , "," )
292304 dc .mBytesUsed .Record (map [string ]string {deviceNameLabel : deviceName , fsTypeLabel : fstype , mountOptionLabel : opttypes , stateLabel : "free" }, int64 (usageStat .Free ))
293305 dc .mBytesUsed .Record (map [string ]string {deviceNameLabel : deviceName , fsTypeLabel : fstype , mountOptionLabel : opttypes , stateLabel : "used" }, int64 (usageStat .Used ))
306+ if dc .mPercentUsed != nil {
307+ dc .mPercentUsed .Record (map [string ]string {deviceNameLabel : deviceName , fsTypeLabel : fstype , mountOptionLabel : opttypes , stateLabel : "used" }, float64 (usageStat .UsedPercent ))
308+ }
294309 }
295310
296311}
0 commit comments