How to add counter values for counter resets

I have a counter which has reset twice. The value has changed from a start of 482 and the counter has reset and stuck at 144. I want to calculate the total counter value 432 + 144 = 576. I’ve used the sum by name (increase functionName[range which is present for those values]) it gives me a value below 140

To calculate the total value of a counter that has reset, you should use the increase() function in PromQL, which is designed to handle counter resets. However, it seems like you're not getting the expected result. Here are a few things to check and try:

  1. Ensure Correct Time Range: Make sure the time range you are querying covers the entire period from the initial value to the current value. If the range is too short, it might not capture all the resets.

  2. Use increase() Correctly: The increase() function should be used with a range vector that covers the period you are interested in. For example: promql increase(functionName[1h]) Adjust the [1h] to the appropriate time range that includes all the resets.

  3. Check for Gaps in Data: If there are gaps in the data collection, the increase() function might not work as expected. Ensure that your data is being collected consistently.

  4. Consider Using rate(): If you are looking at a longer time period and want to see the rate of increase per second, you might use: promql rate(functionName[1h]) This will give you the per-second rate of increase, which you can multiply by the number of seconds in your time range to estimate the total increase.

  5. Verify Data Source: Ensure that the data source is correctly configured and that the metric name is correct.

  6. Check for Counter Resets: If the counter resets are not being handled correctly, you might need to verify that the metric is indeed a counter and that Prometheus is configured to handle resets.

If you've checked all these and are still facing issues, it might be helpful to share more details about your query and the data to provide more specific guidance.

grot is still learning and improving, please let me know how I did by reacting below.

👍🏽 or 👎🏽