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

Pushing multiple values for the same metric sequentially #53

Open
pavlepredic opened this issue Aug 20, 2020 · 3 comments
Open

Pushing multiple values for the same metric sequentially #53

pavlepredic opened this issue Aug 20, 2020 · 3 comments

Comments

@pavlepredic
Copy link

Perhaps I'm misunderstanding some fundamental concept here, but it seems to me there is a bug in the way metrics are handled by provided adapters. I would expect that setting the value of the gauge metric to two different values in sequence would result in both those values being present in the MetricFamilySamples object. Instead, the second value overwrites the first one. Also, no timestamp seems to be included with any of the metrics, so I'm guessing Prometheus will assign the timestamp when scraping. This all means that, in order to have accurate metrics, you need to configure Prometheus to scrape your data once every second, which does not seem very efficient.

Here's a test case I wrote to demonstrate what I'm saying: https://github.com/pavlepredic/prometheus_client_php_test/blob/master/src/GaugeTest.php. In the test, I use InMemory adapter (because it's easier to set up), but I'm getting the same behaviour with Redis adapter.

Am I missing something or is there a design flaw in the library?

@skydiablo
Copy link

skydiablo commented Aug 31, 2020

try to add an label with current datetime. you will get new entry for any new combination of label-values...

@pavlepredic
Copy link
Author

try to add an label with current datetime. you will get new entry for any new combination of label-values...

But that label will not act as the metric timestamp, right? Prometheus will still assign the same timestamp to all those metrics based on the time of scraping. Or am I wrong?

@skydiablo
Copy link

yes, prometheus use the scraping timestamp. but i have also an PR (#54) to handle this, so you can set your own TS.

on the other hand, you have to strip this datetime-label so that prometheus/grafana can better handle this samples and recognize that this is one stream:

scrape_configs:
  - job_name: 'XXXXXXXX'
# ...
    metric_relabel_configs:
      - regex: 'datetime' 
        action: labeldrop

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

No branches or pull requests

2 participants