Reputation: 457
I've been work on Loki for centralized logging with Grafana. I want to 'Explore' log by query without using time control on top of the Grafana. I wonder if its possible to add range time manually by query (not the time control provided by grafana)?
It's probably like
{job=docker-container} |~ "error" | startsAt = formatTime | endsAt = formatTime
I didn't found any variables that can describe control time range though, also for the labels
Upvotes: 5
Views: 2216
Reputation: 31
The below snippet can be used to override the dashboard range . Idea here is to get the timestamp of the log line , compare it with the range that is passed as argument and ensure that the timestamp of the log line falls in betweend the passed arguments. Conversion to unixEpoch is just for comparison.
{job="xyz"}
| label_format log_message_time="{{ __timestamp__|unixEpoch}}"
| label_format from_time=`{{toDate "02 Jan 06 15:04 -0700" "25 Apr 24 10:00 -0700" |unixEpoch}}`
| label_format to_time=`{{toDate "02 Jan 06 15:04 -0700" "25 Apr 24 10:01 -0700" |unixEpoch}}`
|label_format delta1="{{sub .log_message_time .from_time}}"
|label_format delta2="{{sub .log_message_time .to_time}}"
|delta1>0|delta2<0
Upvotes: 3
Reputation: 11649
You can always setup the date and time in the top right hand side of Grafana and click on "Apply time range" as the below image:
Upvotes: 0