statsd_exporter icon indicating copy to clipboard operation
statsd_exporter copied to clipboard

Gauge to track the current number of metrics known [was: metricsCount metric remain the same after metric been deleted by RemoveStaleMetrics]

Open LeoQuote opened this issue 1 year ago • 4 comments

I was using https://github.com/prometheus/statsd_exporter/blob/58769c7b4d128e7ceae1cf8d893260ed5b5afa4d/main.go#L167-L173 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 https://github.com/prometheus/statsd_exporter/blob/58769c7b4d128e7ceae1cf8d893260ed5b5afa4d/pkg/registry/registry.go#L381-L396

So I think if we add a decrease in this function, the metric number would show the real number of metric number

LeoQuote avatar Jul 23 '24 03:07 LeoQuote

This is a counter, it represents the total number of metrics seen by the exporter, and by definition counters cannot decrease. I think what you are looking for is a metric for the current number of metrics the exporter knows about, which would have to be a separate gauge. Let's call it statsd_exporter_metrics_current or something? I'm happy to take a contribution to add that.

matthiasr avatar Aug 18 '24 15:08 matthiasr

The metric name looks good to me, thanks for your contribution in advance!

LeoQuote avatar Aug 19 '24 05:08 LeoQuote

@matthiasr Isn't that already captured by scrape_samples_scraped and scrape_samples_post_metric_relabeling?

SuperQ avatar Aug 19 '24 06:08 SuperQ

@SuperQ the original metric statsd_exporter_metrics_total provides separated counters for each metric type, including counter, gauge, and observer, this could be useful

LeoQuote avatar Aug 19 '24 19:08 LeoQuote