Search code examples
kubernetesvisualizationgrafanagrafana-loki

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


Solution

  • 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