I was using
|
metricsCount = promauto.NewGaugeVec( |
|
prometheus.GaugeOpts{ |
|
Name: "statsd_exporter_metrics_total", |
|
Help: "The total number of metrics.", |
|
}, |
|
[]string{"type"}, |
|
) |
to track the metric number of statsd exporter, but found that this metric never drops, even if I set the ttl parameter in config file.
Then I noticed, across all the reference of the metrics, these's no place to decrease the gauge.
even in the
|
func (r *Registry) RemoveStaleMetrics() { |
|
now := clock.Now() |
|
// delete timeseries with expired ttl |
|
for _, metric := range r.Metrics { |
|
for hash, rm := range metric.Metrics { |
|
if rm.TTL == 0 { |
|
continue |
|
} |
|
if rm.LastRegisteredAt.Add(rm.TTL).Before(now) { |
|
metric.Vectors[rm.VecKey].Holder.Delete(rm.Labels) |
|
metric.Vectors[rm.VecKey].RefCount-- |
|
delete(metric.Metrics, hash) |
|
} |
|
} |
|
} |
|
} |
So I think if we add a decrease in this function, the metric number would show the real number of metric number
I was using
statsd_exporter/main.go
Lines 167 to 173 in 58769c7
Then I noticed, across all the reference of the metrics, these's no place to decrease the gauge.
even in the
statsd_exporter/pkg/registry/registry.go
Lines 381 to 396 in 58769c7
So I think if we add a decrease in this function, the metric number would show the real number of metric number