VictoriaMetrics / metrics

Lightweight alternative to github.com/prometheus/client_golang
MIT License
543 stars 63 forks source link

Specify timestamp when pushing metrics #57

Closed monotok closed 11 months ago

monotok commented 1 year ago

Hello,

I haven't been able to get the client_golang package to push anything into my Victoria Metrics instance and therefore I tried this package. This package was a lot simpler and I could push data into my Victoria Metrics instance.

However in my particular case I want to set the timestamp for each metric I push into Victoria Metrics. The client_golang client supports this via NewMetricWithTimestamp but I wasn't able to find any information about pushing a metric with a set timestamp in this package.

Is this something that this package supports?

Thank you

valyala commented 11 months ago

The github.com/VictoriaMetrics/metrics package doesn't support the ability to set timestamps on purpose, since these timestamps are frequently set to improper values at the application side. This may result in hard-to-debug issues at the monitoring system side like this one.

Even if metric timestamps are correctly set at the application side, they may mismatch metric timestamps from another applications or timestamps at the monitoring system side if they run on different hosts with different local times.

It is expected that the metric values provided by the application are associated with the scrape or push time, so the timestamps are consistently set to the current time by the monitoring system, which store these metrics.

@monotok , could you share more details on your particular use case which needs setting metric timestamps at application side?

monotok commented 11 months ago

Thanks for the explanation. In my particular use case I was migrating data (weather sensors) from my old Timescale DB to Victoria. I wrote a quick go app to pull the data from the DB and wanted to use the client library to push the data into Victoria. I ended up pushing the data in JSON format with the timestamp using the standard http library.