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

Clearing metrics data without removing the metric #145

Closed
mwho opened this issue Jul 27, 2017 · 4 comments
Closed

Clearing metrics data without removing the metric #145

mwho opened this issue Jul 27, 2017 · 4 comments

Comments

@mwho
Copy link

mwho commented Jul 27, 2017

Every time my metric is updated, I'd like to clear all existing data before doing the update. This is because the existing data might be stale, and I want to make sure that the data associated with the metric is fresh.

It seems like the only way to do this is something like the following - removing the metric and then creating it again.

function updateMyGauge(x,y,z,val) {
    register.removeSingleMetric('myMetric');
    myGauge = new promClient.Gauge({name: 'myMetric',
                                           help: 'myMetric_help',
                                           labelNames: ['label1',
                                                        'label2',
                                                        'label3']});
     myGauge.set({label1: x, label2: y, label3: z}, val)
}

Is there a better way? Otherwise, it'd be nice to have a method register.clearMetricData that clears all labels to value mappings but keeps the metric definition itself intact.

@siimon
Copy link
Owner

siimon commented Jul 27, 2017

I've not used timestamps in prometheus myself, but that might be a way forward

@SimenB
Copy link
Collaborator

SimenB commented Jul 28, 2017

Using timestamps should work. I think it then has a 5 minute window before being discarded. Is that enough?

@mwho
Copy link
Author

mwho commented Jul 28, 2017

The sense I'm getting from reading the Prometheus forums (i.e. prometheus/client_golang#187, prometheus/collectd_exporter#24) is that specifying timestamps for metrics is discouraged. The Prometheus philosophy seems to be that the client side endpoint should always provide truthful and up to date data at time of scrape.

@SimenB
Copy link
Collaborator

SimenB commented Oct 15, 2017

This was fixed in #157

@SimenB SimenB closed this as completed Oct 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants