Esben Eickhardt
Esben Eickhardt

Reputation: 3862

How to visualize Loki JSON logs in Grafana

So we are using Loki/Grafana to collect logs from our Kubernetes cluster, and the tool is great for that. But now that I have cleaned up the logs, I would also like to visualize them!

  1. My logs enter image description here

  2. Selecting only JSON lines

    # My query
    {namespace="default",pod=~"kkds-dockerscanner-test.+"} |= "SchemaVersion" | json
    
    My logs

    enter image description here

  3. I select only two columns that I want to display in a table

    {namespace="default",pod=~"kkds-dockerscanner-test.+"} |= "SchemaVersion" | json | line_format "{{.ArtifactName}} {{.Metadata_OS_Family}}"
    
  4. Now I want to show the results in a table, but Grafana doesn't quite show the table I want. I want to show the output of my query in a table, and not just my output as a string in a column. Do you have any suggestions how to make this work, or can you point to a tutorial?

    enter image description here

Upvotes: 10

Views: 22916

Answers (2)

Esben Eickhardt
Esben Eickhardt

Reputation: 3862

As suggested by @Witt, it is possible to transform the JSON by applying a transformation.

If I choose the Transform pane and extract fields, I now get the JSON keys as columns in the Table view.

enter image description here

Under your datasource, you can also add the columns using Derived Fields and Regex. This, however, is a bit more cumbersome.

enter image description here

Upvotes: 9

Witt
Witt

Reputation: 679

You'll need to apply a transform on the data before it's visualized.

I don't have an instance available to me to test so I can't send screenshots, but this is how you'd get the data out of the "line {}" column.

Upvotes: 3

Related Questions