qisejiutian
qisejiutian

Reputation: 11

How query metric value at 0:00 of the day by using Prometheus PromQL

prometheus gets metric value at 0:00 of the day for example: the metric name is eseal_num_total, Why write like 'eseal_num_total @ (time()-(time()+28800)%86400)' and execute Promql 'eseal_num_total @ (time()-(time()+28800)%86400)',this get an syntax error? Why is the syntax wrong? Can it be written correctly? who can help me,thank you?

I added an metric named eseal_num_total, and the PromQL query expression I tried was 'eseal_num_total @ (time()-(time()+28800)%86400)', and I wanted to get the metric value at 0:00 of the day.

Upvotes: 1

Views: 554

Answers (1)

valyala
valyala

Reputation: 18056

Unfortunately Prometheus doesn't support arbitrary expressions as an argument to @ modifier. That's why it returns syntax error for eseal_num_total @ (time()-(time()+28800)%86400).

If you need this functionality, then try VictoriaMetrics - this is Prometheus-like monitoring solution I work on. It supports math expressions for @ modifier, so the query above works as expected. Additionally, it supports duration constants in arbitrary places of the query. For example, the following query returns the eseal_num_total metric value at 08:00 UTC:

eseal_num_total @ (time() - (time() + 8h) % 1d)

You can try this functionality at VictoriaMetrics playground.

Additionally, VictoriaMetrics provides convenient function for working with timezone offsets - timezone_offset().

Upvotes: -1

Related Questions