简体   繁体   English

在 Grafana 上排序日志(来自 Loki)

[英]Sorting logs (from Loki) on Grafana

Scenario: The logs are in following format:场景:日志格式如下:

<SequenceID> <Level> <Message>

I have a requirement to sort the logs based on the SequenceID at Grafana.我需要根据 Grafana 的 SequenceID 对日志进行排序。

Background: I am using promtail to ship logs where I create labels for SequenceID and Level.背景:我正在使用 promtail 发送日志,在其中为 SequenceID 和 Level 创建标签。 However, I am unable to find any valid visualization/transformation option (panel/widget) at Grafana Dashboard that would help me in creating a table where I can sort the log entries based on the sequenceID.但是,我无法在 Grafana Dashboard 上找到任何有效的可视化/转换选项(面板/小部件),这将帮助我创建一个表,在该表中我可以根据 sequenceID 对日志条目进行排序。

Also note: The logs are generated at microsecond level, hence can't rely on timestamp.另请注意:日志是在微秒级生成的,因此不能依赖时间戳。

PS: When adding transformation "Labels to fields" for the label "SequenceID", I get below error: Pls note: PS:为 label “SequenceID”添加转换“标签到字段”时,出现以下错误:请注意:

  • There are multiple values in the dropdown below.下面的下拉列表中有多个值。
  • There's only one value in the table where it doesn't make sense to sort.表中只有一个值对排序没有意义。 Grafana中基于标签的排序

Do the following steps:执行以下步骤:

  • Select "Table" visualization Select “表”可视化

  • Select "Label to fields" transformation Select“标签到字段”转换

  • Click in the "sequenceID" column name to change the order.单击“sequenceID”列名称以更改顺序。

Solution: Selected "Table" visualization.解决方案:选择“表格”可视化。 The transformation steps are as below:改造步骤如下:

  • Reduce减少

    Mode: Series to rows模式:系列到行

    Calculations: "Step"计算:“步”

    Enable - Label to fields启用 - Label 到字段

Further, I used Filter data values and Filter by name transformation stages to filter the empty rows and remove a few columns.此外,我使用过滤数据值按名称过滤转换阶段来过滤空行并删除一些列。

基于标签的日志排序转换

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

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