Getting Loki logs for a given period as of a week ago

  • What Grafana version and what operating system are you using? Grafana version - v11.2.2 ; Linux

  • What are you trying to achieve? Have a requirement to build two different pie charts on a Grafana dashboard - (1) Get the percentage of sales done by credit card type for a given period as of now (2) Get the percentage of sales done by credit card for the same period as in Pie chart #1 but as of a week ago. I.e. For example, if Pie chart #1 gets the sales data for last 1 hr as of now then Pie chart #2 should get the sales data for last 1 hr as of a week ago. Like to compare the sales from current week to last week for the same time period.

I’m good with Pie chart #1 but having difficulty getting the logs for Pie chart #2. The Loki query complains where I’m trying to get the logs for the same period but as of a week ago.

  • How are you trying to achieve it? here is the loki query that I’m using
    sum by(cardType) (count_over_time({app=“myapp”} | log_query( { “time”: “[7d - $__auto … 7d]” } ) | json | keep cardType ))

It’s complaining on this: log_query( { “time”: “[7d - $__auto … 7d]” } )

  • What happened?

  • What did you expect to happen? Get the application logs as of a week back for the same period that Pie chart #1 has pulled.

  • Can you copy/paste the configuration(s) that you are having problems with? log_query( { “time”: “[7d - $__auto … 7d]” } )

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    parse error at line 1, col 95: syntax error: unexpected (

  • Did you follow any online instructions? If so, what is the URL? I have searched Grafana community forum and few other online forums but no luck.

Really appreciate if someone can help me here.

1 Like

Is it possible to use [$__range] instead of log_query( { “time”: “[7d - $__auto … 7d]” } )