Loki quick tip: How to use a Loki datasource in your Grafana dashboard

Published: 15 Apr 2020 RSS

In Grafana, Loki isn’t just for log visualization anymore. Now there’s a simple way to use a Loki datasource as a metric datasource in your graphs.

This used to require a hack to make it work – adding Loki as a Prometheus datasource – and the process was very tedious. But Grafana v6.6 integrates Loki even better than before. As a result, right out of the box you can create very nice dashboards about your logs, and mix them with your dashboards about metrics.

Why use Loki as a metric datasource at all? For one thing, it’s great for when your application is not instrumented with metrics. Usually metric instrumentation requires you to change the code and you may not always have access to that, so you can just use your logs to start building dashboards.

Before you begin, you need to get your data into Loki. This video explains how:

How to use a Loki datasource as a metric datasource

Step 1: Choose a visualization. Graph, Gauge, Bar Gauge, and Stat all work for this (Single Stat does not).

Step 2: Choose a query. Before, the only possibility was a Prometheus datasource using Loki, but now you can simply select a Loki datasource.

Step 3: Write your metric query. Find a guide to LogQL metric queries here. For the interval, you can choose one that is fixed or the $__interval Grafana variable. (This has the advantage of using the same range and step.)

Loki metric query

And what you’re able to create is something like this:

Loki metric query dashboards

The top two graphs were created using Loki as a metric datasource, and the bottom is a typical Loki Log Panel.

And that’s it! You have an application dashboard made only with logs.

Want to learn more about Loki?

Sign up for our Intro to Loki webinar scheduled for April 22 at 9:30am PT/16:30 UTC. The agenda includes an overview of how Loki works, basic configs and setup to run Loki and test it out, how to use Loki from Grafana, an introduction to querying, and a Q&A with me and my fellow Loki team member Ed Welch.

Related Posts

A customer asked for a dashboard with a simple search for labels already pre-set to help teams quickly find what they are looking for while troubleshooting. Here’s our solution.
At FOSDEM 2020, Grafana Labs full stack developer Andrej Ocenas talked about one of the company's big goals: to make Grafana into a full observability platform where users can see their metrics, logs, and traces, correlate data between them, and quickly solve their issues.
Here’s some important information about our annual conference, scheduled for Amsterdam May 13-14.