7

My setup: Loki: 2.1.0, Grafana: 6.7.3

My software runs on Kubernetes, Loki collects its logs. It looks something like this:

[2021-03-29 10:13:05] [INFO] Q_len=256 sol_q=0.049 info_q=0.240
[2021-03-29 10:13:05] [INFO] Q_len=196 sol_q=0.047 info_q=0.144 

I used logfmt in the logs, so loki can detect my fields: ![image|496x169](upload://vlvULKFu8DhvVZJb9qxURLMlSso.png)

Now I want info_q 's avg value plotted over time on Grafana. Here are the things I tried:

avg by (info) (avg_over_time({job="ism/ism-core-es"} | regexp `.*info_q=(?P<info_q>.*)` | unwrap info_q [1m]))

returns enter image description here

As the error message suggested, l did

avg by (info) (avg_over_time({job="ism/ism-core-es"} | regexp `.*info_q=(?P<info_q>.*)` | unwrap info_q | __error__="" [1m] ))

which returns empty chart. And this

avg_over_time(
{job="ism/ism-core-es"}
| regexp ".*info_q=(?P<info_q>.*?)"
| unwrap info_q [5m])

returns nothing either.

What am I doing wrong? Do I have to type cast? Any help is appreciated!

Jens Baitinger
  • 2,230
  • 14
  • 34
Xuekai Du
  • 617
  • 1
  • 6
  • 27

1 Answers1

3

As it turned out:

avg by (info) (avg_over_time( ({job="ism/ism-core-es"} |logfmt |unwrap info|__error__="")[1m]))

did the trick

Xuekai Du
  • 617
  • 1
  • 6
  • 27