influxdata / docs-v2

InfluxData Documentation that covers InfluxDB Cloud, InfluxDB OSS 2.x, InfluxDB OSS 1.x, InfluxDB Enterprise, Telegraf, Chronograf, Kapacitor, and Flux.
https://docs.influxdata.com
MIT License
73 stars 277 forks source link

Please share a thread safe method to increment integers. #4763

Open byjus-vaibhav opened 1 year ago

byjus-vaibhav commented 1 year ago

Describe the issue here.

Relevant URLs
sanderson commented 1 year ago

@byjus-vaibhav I don't know if this matches your use case, but the way to increment integers based on the previous value is to use cumulativeSum(). I'm not familiar with a prometheus counter function and there isn't one listed in the function documentation.

There is a section in the Flux documentation that specifically walks through using Flux to work with Prometheus metrics: https://docs.influxdata.com/flux/v0.x/prometheus/metric-types/

byjus-vaibhav commented 1 year ago

Counter is a metric or you can say a 'data-type' in prometheus which holds one value at time. It is meant to store the count of metrics that can only increase, for example - service requests, total hits on a page or an API. It only has one method increment which increments the value of the metric based on the previous value.

Is there a way I can update a metric's value in a threadsafe manner instead of making multiple entries and adding them everytime? Thanks!