It looks like there's a syntax error in your Loki query. The table stage is not valid in the context of a LogQL query used for metric visualizations in Grafana. Instead, table is used when viewing raw logs in Loki's Explore section.
Since you're building a dashboard, you should use the sum() and count_over_time() functions to aggregate your log data into metrics. If you want to display a table of the raw log data in Grafana, you should create a separate panel specifically for viewing logs.
Let's correct the query and provide you with the correct setup for both a time series panel and a log table panel.
Time Series Panel (Mode Switches by Mode and Sender)
In the panel editor, select the "Logs" visualization.
Under the "Log format" section, you can use the extracted labels to format the log lines. For example:
code
{{.time}} - Mode: {{.mode}}, Sender: {{.sender}}
This will display the timestamp, mode, and sender in the log table.
Steps to Create the Dashboard
Create a New Dashboard:
In Grafana, click the "+" icon and select "Dashboard".
Give your dashboard a descriptive name and save it.
Add Panels:
Click "Add new panel".
Choose the appropriate visualization type (Time series for the first two panels, Logs for the third panel).
Choose Loki Data Source:
Select your Loki data source.
Enter LogQL Query:
Paste the appropriate LogQL query for each panel.
Configure Visualization:
For the time series panels, set the legend format to {{mode}} and {{sender}}, respectively.
For the log table panel, configure the log format as shown above.
Save Dashboard:
Save your dashboard to apply the changes.
By following these steps, you'll have a comprehensive dashboard that visualizes mode switch events by mode and sender, as well as a table displaying the raw log data for recent mode switches.