Skip to content

Commit 17c5bf7

Browse files
committed
Update the metric names to match Prometheus conventions
I found a few improvements to the metrics based on https://prometheus.io/docs/practices/naming/ These are good recommendations in general, and having standard units makes it easier to use the metrics in queries. For example, having everything in bytes, means you can just divide one metric by another without conversion. Having the timestamp in seconds allows easy use with the `time()` function. Signed-off-by: Goutham <[email protected]>
1 parent 692cbdf commit 17c5bf7

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ It exposes the following metrics:
4646
| Metric | Description |
4747
|-|-|
4848
| `unused_disks_count` | How many unused disks are in this provider |
49-
| `unused_disks_size_gb` | Total size of unused disks in this provider in GB |
49+
| `unused_disks_total_size_bytes` | Total size of unused disks in this provider in bytes |
5050
| `unused_disk_size_bytes` | Size of each disk in bytes |
51-
| `unused_disks_last_used_at` | Last timestamp (unix ms) when this disk was used. GCP only! |
52-
| `unused_provider_duration_ms` | How long in milliseconds took to fetch this provider information |
51+
| `unused_disks_last_used_timestamp_seconds` | Last timestamp (unix seconds) when this disk was used. GCP only! |
52+
| `unused_provider_duration_seconds` | How long in milliseconds took to fetch this provider information |
5353
| `unused_provider_info` | CSP information |
5454
| `unused_provider_success` | Static metric indicating if collecting the metrics succeeded or not |
5555

5656
All metrics have the `provider` and `provider_id` labels to identify to which provider instance they belong.
57-
The `unused_disks_count` and `unused_disks_size_gb` metrics have an additional `k8s_namespace` metric mapped to the `kubernetes.io/created-for/pvc/namespace` annotation assigned to persistent disks created by Kubernetes.
57+
The `unused_disks_count` and `unused_disks_total_size_bytes` metrics have an additional `k8s_namespace` metric mapped to the `kubernetes.io/created-for/pvc/namespace` annotation assigned to persistent disks created by Kubernetes.
5858

5959
Information about each unused disk is currently logged to stdout given that it contains more changing information that could lead to cardinality explosion.
6060

cmd/unused-exporter/exporter.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ func registerExporter(ctx context.Context, providers []unused.Provider, cfg conf
7474
nil),
7575

7676
size: prometheus.NewDesc(
77-
prometheus.BuildFQName(namespace, "disks", "size_gb"),
78-
"Total size of unused disks in this provider in GB",
77+
prometheus.BuildFQName(namespace, "disks", "total_size_bytes"),
78+
"Total size of unused disks in this provider in bytes",
7979
append(labels, "k8s_namespace", "type"),
8080
nil),
8181

8282
dur: prometheus.NewDesc(
83-
prometheus.BuildFQName(namespace, "provider", "duration_ms"),
84-
"How long in milliseconds took to fetch this provider information",
83+
prometheus.BuildFQName(namespace, "provider", "duration_seconds"),
84+
"How long in seconds took to fetch this provider information",
8585
labels,
8686
nil),
8787

@@ -92,7 +92,7 @@ func registerExporter(ctx context.Context, providers []unused.Provider, cfg conf
9292
nil),
9393

9494
dlu: prometheus.NewDesc(
95-
prometheus.BuildFQName(namespace, "disks", "last_used_at"),
95+
prometheus.BuildFQName(namespace, "disks", "last_used_timestamp_seconds"),
9696
"Kubernetes metadata associated with each unused disk, with the value as the last time the disk was used (if available)",
9797
append(labels, []string{"disk", "created_for_pv", "created_for_pvc", "zone"}...),
9898
nil),
@@ -176,7 +176,7 @@ func (e *exporter) pollProvider(p unused.Provider) {
176176
diskInfoByNamespace[ns] = di
177177
}
178178
di.Count += 1
179-
di.SizeByType[d.DiskType()] += float64(d.SizeGB())
179+
di.SizeByType[d.DiskType()] += float64(d.SizeBytes())
180180

181181
e.logger.Info(fmt.Sprintf("Disk %s last used at %v", d.Name(), d.LastUsedAt()))
182182

@@ -190,7 +190,7 @@ func (e *exporter) pollProvider(p unused.Provider) {
190190
}
191191

192192
addMetric(&ms, p, e.info, 1)
193-
addMetric(&ms, p, e.dur, float64(dur.Milliseconds()))
193+
addMetric(&ms, p, e.dur, float64(dur.Seconds()))
194194
addMetric(&ms, p, e.suc, float64(success))
195195

196196
for ns, di := range diskInfoByNamespace {
@@ -290,7 +290,7 @@ func lastUsedTS(d unused.Disk) float64 {
290290
return 0
291291
}
292292

293-
return float64(lastUsed.UnixMilli())
293+
return float64(lastUsed.Unix())
294294
}
295295

296296
func getRegionFromZone(p unused.Provider, z string) string {

0 commit comments

Comments
 (0)