Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/system-stats-monitor.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
"disk/bytes_used": {
"displayName": "disk/bytes_used"
},
"disk/percent_used": {
"displayName": "disk/percent_used"
},
"disk/io_time": {
"displayName": "disk/io_time"
},
Expand Down
1 change: 1 addition & 0 deletions pkg/exporters/stackdriver/stackdriver_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var NPDMetricToSDMetric = map[metrics.MetricID]string{
metrics.CPULoad15m: "compute.googleapis.com/guest/cpu/load_15m",
metrics.DiskAvgQueueLenID: "compute.googleapis.com/guest/disk/queue_length",
metrics.DiskBytesUsedID: "compute.googleapis.com/guest/disk/bytes_used",
metrics.DiskPercentUsedID: "custom.googleapis.com/guest/disk/percent_used",
metrics.DiskIOTimeID: "compute.googleapis.com/guest/disk/io_time",
metrics.DiskMergedOpsCountID: "compute.googleapis.com/guest/disk/merged_operation_count",
metrics.DiskOpsBytesID: "compute.googleapis.com/guest/disk/operation_bytes_count",
Expand Down
1 change: 1 addition & 0 deletions pkg/systemstatsmonitor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Below metrics are collected from `disk` component:
* `disk_operation_bytes_count`: # of Bytes used for reads/writes on this device
* `disk_operation_time`: [# of milliseconds spent reading/writing][iostat doc]
* `disk_bytes_used`: Disk usage in Bytes. The usage state is reported under the `state` metric label (e.g. `used`, `free`). Summing values of all states yields the disk size.
* `disk_percent_used`: Disk utilization percentage. The usage state is reported under the `state` metric label (e.g. `used`, `free`). The utilization is between 0.0 and 100.0.
FSType and MountOptions are also reported as additional information.

The name of the disk block device is reported in the `device_name` metric label (e.g. `sda`).
Expand Down
13 changes: 13 additions & 0 deletions pkg/systemstatsmonitor/disk_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type diskCollector struct {
mOpsBytes *metrics.Int64Metric
mOpsTime *metrics.Int64Metric
mBytesUsed *metrics.Int64Metric
mPercentUsed *metrics.Float64Metric

config *ssmtypes.DiskStatsConfig

Expand Down Expand Up @@ -149,6 +150,16 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
if err != nil {
klog.Fatalf("Error initializing metric for %q: %v", metrics.DiskBytesUsedID, err)
}
dc.mPercentUsed, err = metrics.NewFloat64Metric(
metrics.DiskPercentUsedID,
diskConfig.MetricsConfigs[string(metrics.DiskPercentUsedID)].DisplayName,
"Disk utilization percentage",
"%",
metrics.LastValue,
[]string{deviceNameLabel, fsTypeLabel, mountOptionLabel, stateLabel})
if err != nil {
klog.Fatalf("Error initializing metric for %q: %v", metrics.DiskPercentUsedID, err)
}

dc.lastIOTime = make(map[string]uint64)
dc.lastWeightedIO = make(map[string]uint64)
Expand Down Expand Up @@ -291,6 +302,8 @@ func (dc *diskCollector) collect() {
opttypes := strings.Join(partition.Opts, ",")
dc.mBytesUsed.Record(map[string]string{deviceNameLabel: deviceName, fsTypeLabel: fstype, mountOptionLabel: opttypes, stateLabel: "free"}, int64(usageStat.Free))
dc.mBytesUsed.Record(map[string]string{deviceNameLabel: deviceName, fsTypeLabel: fstype, mountOptionLabel: opttypes, stateLabel: "used"}, int64(usageStat.Used))
dc.mPercentUsed.Record(map[string]string{deviceNameLabel: deviceName, fsTypeLabel: fstype, mountOptionLabel: opttypes, stateLabel: "free"}, float64(100 - usageStat.UsedPercent))
dc.mPercentUsed.Record(map[string]string{deviceNameLabel: deviceName, fsTypeLabel: fstype, mountOptionLabel: opttypes, stateLabel: "used"}, float64(usageStat.UsedPercent))
}

}
Expand Down
1 change: 1 addition & 0 deletions pkg/util/metrics/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
DiskOpsBytesID MetricID = "disk/operation_bytes_count"
DiskOpsTimeID MetricID = "disk/operation_time"
DiskBytesUsedID MetricID = "disk/bytes_used"
DiskPercentUsedID MetricID = "disk/percent_used"
HostUptimeID MetricID = "host/uptime"
MemoryBytesUsedID MetricID = "memory/bytes_used"
MemoryAnonymousUsedID MetricID = "memory/anonymous_used"
Expand Down
1 change: 1 addition & 0 deletions test/e2e/metriconly/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ var _ = ginkgo.Describe("NPD should export Prometheus metrics.", func() {
assertMetricExist(gotMetrics, "disk_operation_bytes_count", map[string]string{}, false)
assertMetricExist(gotMetrics, "disk_operation_time", map[string]string{}, false)
assertMetricExist(gotMetrics, "disk_bytes_used", map[string]string{}, false)
assertMetricExist(gotMetrics, "disk_percent_used", map[string]string{}, false)
assertMetricExist(gotMetrics, "disk_io_time", map[string]string{}, false)
assertMetricExist(gotMetrics, "disk_weighted_io", map[string]string{}, false)
assertMetricExist(gotMetrics, "memory_bytes_used", map[string]string{}, false)
Expand Down