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

add timestamp on metrics #58

Closed
achilles42 opened this issue Aug 23, 2019 · 2 comments
Closed

add timestamp on metrics #58

achilles42 opened this issue Aug 23, 2019 · 2 comments

Comments

@achilles42
Copy link

achilles42 commented Aug 23, 2019

the current implementation of stackdriver_exporter doesn't add timestamp on metrics. if a timestamp is not added to metrics, Prometheus adds the scrape timestamp on the metrics scraped from /metrics endpoint on stackdriver_exporter. This implementation doesn't allow us to show the Stackdriver data collection lag on the metrics(which we are storing on Prometheus) as Prometheus is adding the timestamp of scrape time.

prometheus/client_golang has feature released on v0.9 version, which allows users to add timestamp on the metrics.

We can use NewMetricWithTimestamp, which is a wrapper on top of existing metrics type which prometheus_client library provides.

prometheus.NewMetricWithTimestamp(
               reportTime,  // Get the timestamp from stackdriver metrics data
               prometheus.MustNewConstHistogram(
                       t.newMetricDesc(fqName, labelKeys),
                       uint64(dist.Count),
                       dist.Mean*float64(dist.Count),fake it
                       buckets,
                      labelValues...,
                ),
)
@SuperQ
Copy link
Contributor

SuperQ commented Oct 3, 2019

One word of warning when using timestamps on exported metrics, you can easily run into staleness problems which will create gaps in Prometheus. Or if the timestamp is too far off, Prometheus will drop the data entirely.

@SuperQ
Copy link
Contributor

SuperQ commented Jun 29, 2020

This is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants