Laravel Lumen Grafana Loki
Tutorial

Monitoring API Endpoints Speed on Laravel/Lumen using Loki and Grafana [3/3]

Finally, we generate data, scrap them, now time to display the data in Grafana.

#1 – Add Loki as a Datasource

Connect to your Grafana, then go to Menu > Connections > Your connections > Data sources.

Then click on the “+ Add new data source” on the top right of the screen.

Search for Loki

Set your source name, and in the HTTP section, set the URL of your Loki instance
Local: http://127.0.0.1:3100
Remote: http://REMOTE_IP:3100

Then click on Save & test, if everything is well set, you should have this:

#2 – Import Dashboard

To create our dashboard, we will import the dashboard I’ve developed and that is available on Grafana Labs.

Go to Dashboards and click New > Import

My dashboard is available here: Grafana Labs

In the “Import via grafana.com” field, you can input
the URL: https://grafana.com/grafana/dashboards/19897-laravel-lumen-execution-time-monitoring/
– or the ID: 19897

You can rename your Dashboard, and make sure to select the Loki data source that we’ve created earlier.

#3 – Set the variable

Finally, we need to set the job variable. This will allow you to set multiple jobs in the Promtail configuration if you want to have multiple source, and therefore being able to filter the data you want to display.

In your Datashboard, go to Settings > Variables, and click “+ New variable“:
Name: job
Label: Job
Data source: Loki
Query type: Label values
Label: job
Select Multi-value
Select Include All option

Then finally you should see the different jobs from your Promtail configuration appearing in “Preview of values“. If the values don’t appear, click “Run query“.

Don’t forget to click “Apply” and voilà, here is how should look your dashboard:

Nota Bene

This dashboard still need some improvements:
– Being able to order the endpoints list based on the values
– Improving the query to be able to handle when querying a huge amount of data and stay bellow the Loki max amount of data. Need to find the right query to change the sample amount based on the time scale.

Last word

Thank you for following the tutorial until this point and don’t forget to share your feedbacks in the comments, and I hope this would be helpful. And I’m open for any suggestions on improving this dashboard.

Leave a Reply

Your email address will not be published. Required fields are marked *