Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the metric names to match Prometheus conventions #97

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ It exposes the following metrics:
| Metric | Description |
|-|-|
| `unused_disks_count` | How many unused disks are in this provider |
| `unused_disks_size_gb` | Total size of unused disks in this provider in GB |
| `unused_disks_total_size_bytes` | Total size of unused disks in this provider in bytes |
| `unused_disk_size_bytes` | Size of each disk in bytes |
| `unused_disks_last_used_at` | Last timestamp (unix ms) when this disk was used. GCP only! |
| `unused_provider_duration_ms` | How long in milliseconds took to fetch this provider information |
| `unused_disks_last_used_timestamp_seconds` | Last timestamp (unix seconds) when this disk was used. GCP only! |
| `unused_provider_duration_seconds` | How long in milliseconds took to fetch this provider information |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the unit is seconds but the description says milliseconds, we should fix this.

| `unused_provider_info` | CSP information |
| `unused_provider_success` | Static metric indicating if collecting the metrics succeeded or not |

All metrics have the `provider` and `provider_id` labels to identify to which provider instance they belong.
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.
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I didn't see this line when I added unused_disk_size_bytes and it has this label too. Not a blocker in any way, but would you mind adding it here to the list? Thanks a lot! ❤️


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

Expand Down
16 changes: 8 additions & 8 deletions cmd/unused-exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ func registerExporter(ctx context.Context, providers []unused.Provider, cfg conf
nil),

size: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "disks", "size_gb"),
"Total size of unused disks in this provider in GB",
prometheus.BuildFQName(namespace, "disks", "total_size_bytes"),
"Total size of unused disks in this provider in bytes",
append(labels, "k8s_namespace", "type"),
nil),

dur: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "provider", "duration_ms"),
"How long in milliseconds took to fetch this provider information",
prometheus.BuildFQName(namespace, "provider", "duration_seconds"),
"How long in seconds took to fetch this provider information",
labels,
nil),

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

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

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

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

addMetric(&ms, p, e.info, 1)
addMetric(&ms, p, e.dur, float64(dur.Milliseconds()))
addMetric(&ms, p, e.dur, float64(dur.Seconds()))
addMetric(&ms, p, e.suc, float64(success))

for ns, di := range diskInfoByNamespace {
Expand Down Expand Up @@ -290,7 +290,7 @@ func lastUsedTS(d unused.Disk) float64 {
return 0
}

return float64(lastUsed.UnixMilli())
return float64(lastUsed.Unix())
}

func getRegionFromZone(p unused.Provider, z string) string {
Expand Down
Loading