English | 中文
Dubbo-Go Pushgateway Cleaner is a tool designed to solve the “zombie metrics” issue in Prometheus Pushgateway. It provides an operation-side cleanup solution.
(This solution is based on the job_pushed_at_seconds metric in Prometheus Pushgateway.)
| Parameter | Short | Default | Description |
|---|---|---|---|
-pushgw | - | Required | Pushgateway address |
-ttl | - | 3600 | Metric retention time (seconds) |
-job-prefix | - | * | Job name prefix filter |
-daemon | - | false | Enable daemon mode |
-interval | - | 60 | Cleanup interval (seconds) |
./pgw-cleaner \ -pushgw http://pushgateway:9091 \ -ttl 3600 \ -job-prefix dubbo_
./pgw-cleaner \ -pushgw http://pushgateway:9091 \ -ttl 3600 \ -job-prefix dubbo_ \ -daemon \ -interval 300
http://<ip>:9105/metricsdocker build . -t pgw-cleaner:latest
docker run --rm pgw-cleaner:latest \ -pushgw http://127.0.0.1:9091 \ -job-prefix dubbo_ \ -ttl 3600
docker run -d -p 9105:9105 pgw-cleaner:latest \ -pushgw http://127.0.0.1:9091 \ -job-prefix dubbo_ \ -ttl 3600 \ -daemon \ -interval 300
A running Kubernetes cluster (minikube / k3s / cloud-based).
kubectl configured to point to the cluster.
Pushgateway deployed inside the cluster and accessible via DNS, e.g.:
http://pushgateway.monitoring.svc.cluster.local:9091
Cleaner image built and pushed to an image registry, e.g.:
pgw-cleaner:latest
Ensure the monitoring namespace exists. If not, create it:
kubectl create namespace monitoring
kubectl apply -f ./deploy/cronjob.yaml
Advantages:
kubectl apply -f ./deploy/deployment.yaml
Advantages:
| Scenario | Recommended TTL | Notes |
|---|---|---|
| Short jobs | 5-10 minutes | Short-lived tasks, quick cleanup |
| Daemons | 1-2 hours | Allows for brief service interruptions |
| Production | 30 minutes | Balance between freshness and cost |
Recommended format: <env>-<service>-
Examples:
prod-order-service-dev-user-service-Benefits:
Metrics exposed in daemon mode:
pgw_cleaner_checked_total: Total number of jobs checkedpgw_cleaner_deleted_total: Total number of jobs deletedpgw_cleaner_errors_total: Total cleanup errorsGrafana example query:
sum(rate(pgw_cleaner_deleted_total[5m])) by (job)
Issue: Metrics not cleaned, expired data still present in Pushgateway
Steps:
job_pushed_at_seconds exists:curl http://pushgateway:9091/metrics | grep job_pushed_at_seconds
Check TTL validity:
date +%s(current_time - metric_time) > TTLVerify job prefix match:
# List all jobs curl http://pushgateway:9091/api/v1/metrics
Issue: job_pushed_at_seconds not reported
Solution:
Dubbo-Go Client Config:
pushedAt := prometheus.NewGauge(prometheus.GaugeOpts{ Name: "job_pushed_at_seconds", Help: "Last push timestamp", }) prometheus.MustRegister(pushedAt) // Update before each push func pushMetrics() { pushedAt.SetToCurrentTime() // ... push logic ... }
Scheduled Verification:
./pgw-cleaner -verify -pushgw http://pushgateway:9091
Issue: 401 Unauthorized
Solution:
# Add authentication in the cleanup command ./pgw-cleaner \ -pushgw http://username:password@pushgateway:9091 \ -ttl 1h
Issue: Cleanup takes too long
Optimization:
./pgw-cleaner -workers=5
# Split by environment - -job-prefix=prod-east- - -job-prefix=prod-west-
# Cleanup within a 1-hour window ./pgw-cleaner -time-window=1h