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

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

Open
LeoQuote opened this issue Jul 23, 2024 · 4 comments
Labels
enhancement help wanted PRs for this issue are especially welcome

Comments

@LeoQuote
Copy link

I was using

statsd_exporter/main.go

Lines 167 to 173 in 58769c7

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

@matthiasr
Copy link
Contributor

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 matthiasr changed the title metricsCount metric remain the same after metric been deleted by RemoveStaleMetrics Gauge to track the current number of metrics known [was: metricsCount metric remain the same after metric been deleted by RemoveStaleMetrics] Aug 18, 2024
@matthiasr matthiasr added enhancement help wanted PRs for this issue are especially welcome labels Aug 18, 2024
@LeoQuote
Copy link
Author

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

@SuperQ
Copy link
Member

SuperQ commented Aug 19, 2024

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

@LeoQuote
Copy link
Author

LeoQuote commented Aug 19, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted PRs for this issue are especially welcome
Projects
None yet
Development

No branches or pull requests

3 participants