0

I have a graph over time (mostly "today so far") and would like to start the graph based on prometheus data at zero. Of course the base value changes everytime the range differs so a static value is useless.

Example:

max_over_time(my_metric_counter[${__interval}])

This returns a graph starting somewhere (for example 120 in the current time range). Substracting a static value makes no sense here:

max_over_time(my_metric_counter[${__interval}]) - 120

I already found out what to do - but it took me quite a while. So I want to share this with you...

1 Answer 1

2

I am adding a grafana variable as follows:

Name: my_metric_counter_start_value

Type: Query

Hide: Variable

Datasource: MyPrometheusDatasourceName

Refresh: "On time range change"

Query: query_result(min_over_time(my_metric_counter[${__range}]))

Regex: /.} ([0-9]+) ./

The I change my graphs query:

max_over_time(my_metric_counter[${__interval}]) - $my_metric_counter_start_value

And that's it! Hopefully this will help you too ;-)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.