H S Raju
H S Raju

Reputation: 410

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.

Background: I am using promtail to ship logs where I create labels for SequenceID and 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.

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:

Upvotes: 1

Views: 10596

Answers (3)

Willie Cheng
Willie Cheng

Reputation: 8263

Sort Example

Step 1: Choose a new dashboard
enter image description here
Step 2: Add a new panel
enter image description here
Step 3: query command (example: {job="localhost_logs"} |= "GGGG") and choose the switch to table
enter image description here
Step 4: Transform (Extract fields)
enter image description here
enter image description here
Step 5: Add transformation(Organize fields)
enter image description here

Upvotes: 1

H S Raju
H S Raju

Reputation: 410

Solution: Selected "Table" visualization. The transformation steps are as below:

  • Reduce

    Mode: Series to rows

    Calculations: "Step"

    Enable - Label to fields

Further, I used Filter data values and Filter by name transformation stages to filter the empty rows and remove a few columns.

Transformation for ordering of logs based on label

Upvotes: 0

Do the following steps:

  • Select "Table" visualization

  • Select "Label to fields" transformation

  • Click in the "sequenceID" column name to change the order.

Upvotes: 1

Related Questions