简体   繁体   English

如何在 Grafana 中可视化 Loki JSON 日志

[英]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.所以我们使用 Loki/Grafana 从我们的 Kubernetes 集群收集日志,这个工具非常适合。 But now that I have cleaned up the logs, I would also like to visualize them!但是现在我已经清理了日志,我还想将它们可视化!

  1. My logs我的日志在此处输入图像描述

  2. Selecting only JSON lines仅选择 JSON 行

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

    在此处输入图像描述

  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.现在我想在表格中显示结果,但 Grafana 并没有完全显示我想要的表格。 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?您对如何使这项工作有任何建议,或者您能指出一个教程吗?

    在此处输入图像描述

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.我没有可供我测试的实例,因此我无法发送屏幕截图,但这是您从“line {}”列中获取数据的方式。

As suggested by @Witt, it is possible to transform the JSON by applying a transformation.正如@Witt 所建议的,可以通过应用转换来转换 JSON。

If I choose the Transform pane and extract fields, I now get the JSON keys as columns in the Table view.如果我选择转换窗格并提取字段,我现在将 JSON 键作为表视图中的列。

在此处输入图像描述

Under your datasource, you can also add the columns using Derived Fields and Regex .在您的数据源下,您还可以使用Derived FieldsRegex添加列。 This, however, is a bit more cumbersome.但是,这有点麻烦。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM