The way I sorted this problem was doing the following prometheus query for Grafana. This query allows me to identify the total_processing_time consumed by an individual customer across all PODs in a K8s cluster within a given time range. The catch is that this query handles the following corner cases:

  • If the querying time_range encompasses only the last 1h but there are older timeseries that were started before that, the query below "offsets to zero" these timeseries by removing the value of the first measurement point within the time_range. This way these series are considered as if they have started within the time range.

  • If a new timeseries (due to a new POD) show up within the querying time_range, and the first measurement value is greater than 0, then the first measurement value of the new timeseries is added to the calculation to fulfill the gap from the increment function.

sum(
    # Calculates the difference between the last measurement 
    # and the first measurement in the given time_range for each 
    # timeseries, this helps identify how much additional resources
    # were consumed in the given time_range
    increase(
        total_processing_time{customer_id="$customer_id"}[$__range]
    )
    # Adds to the difference the minimum value of each timeseries, 
    # this helps to account for the timeseries that started within 
    # the given time_range with the first measurement greater than 0
    # (not considered by the previous increase function)
    + min_over_time(
        total_processing_time{customer_id="$customer_id"}[$__range]
    )
)
# Removes the timeseries measurements being carried over from before 
# the start of the time_range, this offsets the running timeseries
# as if they had started from zero within the time_range
- sum(
    total_processing_time{customer_id="$customer_id"} @ start() or vector(0)
)
Answer from João Pedro Schmitt on Stack Overflow
🌐
Reddit
reddit.com › r/prometheusmonitoring › how to deal with increase function and no data points
r/PrometheusMonitoring on Reddit: How to deal with Increase function and no data points
September 3, 2021 -

I need to use the increase function, but the metric is very rare and when service restarts the counter is null for long time. The increase metric doesn’t play nicely with the null value and I can find a solution to consider null as zero.

Increase(my_counter[1h])

Works only if there are no null data points. Any other query I tried do not work like

Increase(my_metrics[1h] or vector(0))
Discussions

increase function returns null for some data points, resulting in gaps
I have complete data for "mymetric" in prometheus for every second, with no nulls. I use increase function on a counter metric over a period of 1m to see the increase for every minute: in... More on github.com
🌐 github.com
15
April 26, 2017
prometheus - Why is increase() showing only zero values when I can see the metric value increasing? - Stack Overflow
The solution is the following, as each sample of the requests occurred in the prometheus Scrap Interval, you should then use the same interval to fetch that sample. But keeping this value in your hand, for example mine has 15s would not be feasible, since when increasing the range to 1d or ... More on stackoverflow.com
🌐 stackoverflow.com
rate()[1m] does not return any data
What did you expect to see? Rate of increase of the time series in the range vector. What did you see instead? Under which circumstances? No datapoints found. ... Prometheus running on kubernetes 1.7.0 from helm chart (version stable/4.5.0). More on github.com
🌐 github.com
4
September 20, 2017
Increase issue
What did you do? Tried to get increase over one minute. What did you expect to see? Increase values What did you see instead? Under which circumstances? I've got No datapoints found Environment Sys... More on github.com
🌐 github.com
5
October 4, 2016
Top answer
1 of 3
6

The way I sorted this problem was doing the following prometheus query for Grafana. This query allows me to identify the total_processing_time consumed by an individual customer across all PODs in a K8s cluster within a given time range. The catch is that this query handles the following corner cases:

  • If the querying time_range encompasses only the last 1h but there are older timeseries that were started before that, the query below "offsets to zero" these timeseries by removing the value of the first measurement point within the time_range. This way these series are considered as if they have started within the time range.

  • If a new timeseries (due to a new POD) show up within the querying time_range, and the first measurement value is greater than 0, then the first measurement value of the new timeseries is added to the calculation to fulfill the gap from the increment function.

sum(
    # Calculates the difference between the last measurement 
    # and the first measurement in the given time_range for each 
    # timeseries, this helps identify how much additional resources
    # were consumed in the given time_range
    increase(
        total_processing_time{customer_id="$customer_id"}[$__range]
    )
    # Adds to the difference the minimum value of each timeseries, 
    # this helps to account for the timeseries that started within 
    # the given time_range with the first measurement greater than 0
    # (not considered by the previous increase function)
    + min_over_time(
        total_processing_time{customer_id="$customer_id"}[$__range]
    )
)
# Removes the timeseries measurements being carried over from before 
# the start of the time_range, this offsets the running timeseries
# as if they had started from zero within the time_range
- sum(
    total_processing_time{customer_id="$customer_id"} @ start() or vector(0)
)
2 of 3
2

If you have access to the code where the metric job_invocation_total is created and the cardinality of the metric labels is bound, you can initialize the counter with the value 0.

If this is not the case, you can create a recording rule that is either 0 or equal to the metric job_invocation_total.

🌐
Google Groups
groups.google.com › g › prometheus-users › c › TfsMnT4E5kk
Issue with Prometheus increase()
October 6, 2022 - I believe many of the would have come across the below issue Prometheus increase function. Let me explain with an example: ... Due to some reasons or due to counter reset, we don't have any time series data for the above metrics for some 10 mins or 1hr. Now, when the counter gets increased due to some transactions, since the we don't have the time series data in the past the increase function return 0 even if the counter is at some x value.
🌐
GitHub
github.com › prometheus › prometheus › issues › 2659
increase function returns null for some data points, resulting in gaps · Issue #2659 · prometheus/prometheus
April 26, 2017 - I expect a value of the increase from first to last data point of each minute. When there was no increase, I expect to see a 0. Instead, I often see unexplainable gaps (null values) in the data; even when trying with other functions like delta and rate. Prometheus version: 1.5.2 BuildDate: 20170210-14:41:22 GoVersion: go1.7.5
Author: prometheus
🌐
GitHub
github.com › prometheus › prometheus › issues › 3194
rate()[1m] does not return any data · Issue #3194 · prometheus/prometheus
September 20, 2017 - What did you expect to see? Rate of increase of the time series in the range vector. What did you see instead? Under which circumstances? No datapoints found. ... Prometheus running on kubernetes 1.7.0 from helm chart (version stable/4.5.0).
Author: prometheus
🌐
GitHub
github.com › prometheus › prometheus › issues › 2052
Increase issue · Issue #2052 · prometheus/prometheus
October 4, 2016 - - job_name: 'prometheus' # Override the global default and scrape targets from this job every 5 seconds. # scrape_interval: 5s # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:9091'] Alertmanager configuration file: Logs: Should not I see jumps where value increased? Instead I've got "No datapoints found" Reactions are currently unavailable ·
Author: prometheus
Find elsewhere
🌐
Google Groups
groups.google.com › g › prometheus-users › c › qmutsg1c55g
Increase without extrapolation
If you have this sort of very accurate reporting need you are better working from the raw data directly (or logs) than via PromQL. ... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message ... You can do one of two things. I am also of the opinion that rate()/increase() should not extrapolate, but it doesn't look like that will change anytime soon, so both of these are workarounds to current Prometheus limitations.
🌐
Google Groups
groups.google.com › g › prometheus-users › c › uhJ9UUAF3Hg
First value of increase(Counter[Time]) doesn't count
July 4, 2023 - The counter may have been running and incrementing for a long time, before Prometheus starts scraping it; the first value you see could represent days or years of accumulation. That's why rate() and increase() only give a value if there are two or more adjacent data points.
🌐
SigNoz
signoz.io › guides › how to handle null values in prometheus time series data
How to Handle Null Values in Prometheus Time Series Data | SigNoz
October 14, 2024 - For some types of data, zero might not be an appropriate replacement for a null value. Always consider the nature of your metrics when deciding how to handle null values. For counters, which only increase over time, setting nulls to zero might not be appropriate as it could indicate a reset.
🌐
Prometheus
discuss.prometheus.io › promql
Trigger an alarm when no data received or no more data received - PromQL - Prometheus Monitoring System
October 30, 2023 - Hello I am building a alerting mechanism an also a graph when I need to inform when there is no data coming since 6 hours (missing or no increase). I need to count only office opening hours (from 8am to 7pm, no week-end…
🌐
GitHub
github.com › prometheus › prometheus › issues › 3000
When "increase" is not enough! · Issue #3000 · prometheus/prometheus
July 28, 2017 - In one of my dashboards I show number of requests in last hour. I use increase function but it gives wrong results when data is missing: As you can see status count for "200" shows 1 but increase shows 0. The value of first sample of tha...
Author: prometheus
🌐
DoiT
doit.com › home › blog › making peace with prometheus rate()
Making peace with Prometheus rate() | DoiT
February 17, 2023 - To get the increase over 60 seconds, we ask P8s to calculate one for 75 seconds (with that extra sample that usually falls between the buckets). Of course, Prometheus will extrapolate it to 75 seconds but we de-extrapolate it manually back to 60 and now our charts are both precise and provide us with the data one whole-minute boundaries as well.
Top answer
1 of 3
5

I think your can do some kind of alerting on a metric rate with something like this:

ALERT DropInMetricsFromExporter
  IF rate(<metric_name>[1m]) == 0
  FOR 3m
  ANNOTATIONS {
    summary = "Rate of metrics is 0 {{ $labels.<your_label> }}",
    description = "Rate of metric dropped, actually: {{ $value }}%",
}

The main idea is to alert whenever the metric rate is at 0 for 3 minutes, with the proper metric name and a label somewhere telling from which exporter it comes it should give you the correct information.

Choosing the right metric to monitor by exporter could be complex, without more insight is hard to give a better advice out of vacuum.
This blog post could be an inspiration also for a more generic detection.

2 of 3
1

There are a few reasons which might have caused the gap. Most likely the exporter isn't reachable in which case the up timeseries will be 0. You can alert on this like this (taken from https://prometheus.io/docs/alerting/rules/#templating):

# Alert for any instance that is unreachable for >5 minutes.
ALERT InstanceDown
  IF up == 0
  FOR 5m
  LABELS { severity = "page" }
  ANNOTATIONS {
    summary = "Instance {{ $labels.instance }} down",
    description = "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes.",
  }

On the status page you should also see that it's down including an error message. Unfortunately there is no way to see past error but there is an issue to track this: https://github.com/prometheus/prometheus/issues/2820

Your Prometheus server can be also overloaded causing scraping to stop which too would explain the gaps. In that case you should see Storage needs throttling. Scrapes and rule evaluations will be skipped. errors in the log and increases in the prometheus_target_skipped_scrapes_total metrics. You should alert on that too, e.g:

ALERT PrometheusSkipsScrapes
  IF rate(prometheus_target_skipped_scrapes_total[2m]) > 0
  FOR 5m
🌐
Prometheus
discuss.prometheus.io › general help/support
Prometheus increase result problem - General Help/Support - Prometheus Monitoring System
April 19, 2024 - hi everyone, When I use increase function to calculate the increment, I expected an integer, but a value with a decimal appeared instead. First, I check the value was 913028805. Then I made the value up to 913029005, …
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › functions
Query functions | Prometheus
Use rate in recording rules so that increases are tracked consistently on a per-second basis. The info function is an experiment to improve UX around including labels from info metrics . The behavior of this function may change in future versions of Prometheus, including its removal from PromQL. info has to be enabled via the feature flag --enable-feature=promql-experimental-functions. info(v instant-vector, [data-label-selector instant-vector]) finds, for each time series in v, all info series with matching identifying labels (more on this later), and adds the union of their data (i.e., non-identifying) labels to the time series.
🌐
GitHub
github.com › prometheus › prometheus › issues › 1673
increase() should consider creation of new timeseries as reset · Issue #1673 · prometheus/prometheus
May 27, 2016 - Right now if a time series didn't exist and comes into existence with value 1, increase() returns 0 since Prometheus doesn't know if the counter actually was increased or simply scraped for the first time.
Author: prometheus
🌐
Promlabs
promlabs.com › blog › 2023 › 09 › 13 › dealing-with-missing-time-series-in-prometheus
PromLabs | Blog - Dealing with Missing Time Series in Prometheus
Metrics without labels do not have this issue, since the client library can initialize them to 0 or NaN (depending on the metric type) and expose them immediately after startup. Metrics can also be missing because a target is down, or because Prometheus is not even trying to scrape the target at all for some reason (for example, when the service discovery integration is broken).