7.03 Exploring Logs - MartinWong06/grafana GitHub Wiki

Add Loki Datasource in Grafana

Go to Configuration -> Select Data sources then click "Add new data source" button

Configure data source name and URL

Scroll down to the end of the page, click on "Save & Test" button. Grafana will test the data sources connection base on your configuration.

Exploring logs

Click on "Explore" button

Grafana will redirect to another page. In this page, user can using Label browser or Label filters do query the log from the loki data sources

Label Browser User Interface

Query Loki Log with the following query

{job="my-job"}

Add this result into Dashboard, by clicking "Add to Dashboard" Button

Exploring logs with annotations

Click the Dashboard Setting button to add the Annotation query

Select Annotation and click + New Query

Configure the data sources base on your reqirement

Annotation query match a value

{job="my-job"} |= "error"

Exclude a value

{job="my-job"} != "debug"

For example, if you want to match log entries that contain either "error" or "warning" in the message field, you could use a query like this:

{job="my-job"} |= "error" OR {job="my-job"} |= "warning"
{job="my-job"} |= ("error"|"warning")

Create a new Time Series panel

Calculating the rate of the query for this panel

rate({job="my-job"} |= "error"[$__interval])

Example View with enabled annotation query

Nginx Log generator

Reference: https://github.com/kscarlett/nginx-log-generator

docker run -e "RATE=10" kscarlett/nginx-log-generator >> FILE_PATH/FILE_NAME 

FILE_PATH/FILE_NAME - This path use to bind promtail docker container, to allow promtail scrape the log.

⚠️ **GitHub.com Fallback** ⚠️