2022-11-01 10:22:06 -05:00
---
aliases:
2022-12-09 10:36:04 -06:00
- ../data-sources/loki/
- ../features/datasources/loki/
2022-11-01 10:22:06 -05:00
description: Guide for using Loki in Grafana
keywords:
- grafana
- loki
- logging
- guide
Explicitly set all front matter labels in the source files (#71548)
* Set every page to have defaults of 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration pages to have of 'Cloud', 'Enterprise', and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/enterprise-licensing pages to have 'Enterprise' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/organization-management pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/provisioning pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/recorded-queries pages to have labels cloud,enterprise
* Set administration/roles-and-permissions/access-control pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/stats-and-license pages to have labels cloud,enterprise
* Set alerting pages to have labels cloud,enterprise,oss
* Set breaking-changes pages to have labels cloud,enterprise,oss
* Set dashboards pages to have labels cloud,enterprise,oss
* Set datasources pages to have labels cloud,enterprise,oss
* Set explore pages to have labels cloud,enterprise,oss
* Set fundamentals pages to have labels cloud,enterprise,oss
* Set introduction/grafana-cloud pages to have labels cloud
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Fix introduction pages products
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set panels-visualizations pages to have labels cloud,enterprise,oss
* Set release-notes pages to have labels cloud,enterprise,oss
* Set search pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/audit-grafana pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-authentication pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/configure-authentication/enhanced-ldap pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-authentication/saml pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-database-encryption/encrypt-secrets-using-hashicorp-key-vault pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-request-security pages to have labels cloud,enterprise,oss
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-team-sync pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/export-logs pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set troubleshooting pages to have labels cloud,enterprise,oss
* Set whatsnew pages to have labels cloud,enterprise,oss
* Apply updated labels from review
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
---------
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
2023-07-18 03:10:12 -05:00
labels:
products:
- cloud
- enterprise
- oss
2022-11-01 10:22:06 -05:00
menuTitle: Loki
2023-07-25 11:10:28 -05:00
title: Configure the Loki data source
2022-11-01 10:22:06 -05:00
weight: 800
---
# Loki data source
2023-07-25 11:10:28 -05:00
Grafana Loki is a set of components that can be combined into a fully featured logging stack.
Unlike other logging systems, Loki is built around the idea of only indexing metadata about your logs: labels (just like Prometheus labels). Log data itself is then compressed and stored in chunks in object stores such as S3 or GCS, or even locally on a filesystem.
The following guides will help you get started with Loki:
- [Getting started with Loki ](/docs/loki/latest/getting-started/ )
- [Install Loki ](/docs/loki/latest/installation/ )
- [Loki best practices ](/docs/loki/latest/best-practices/#best-practices )
- [Configure the Loki data source ](/docs/grafana/latest/datasources/loki/configure-loki-data-source/ )
- [LogQL ](/docs/loki/latest/logql/ )
- [Loki query editor ]({{< relref "./query-editor" >}} )
## Adding a data source
2022-11-01 10:22:06 -05:00
2023-07-31 10:34:03 -05:00
For instructions on how to add a data source to Grafana, refer to the [administration documentation][data-source-management]
2022-11-01 10:22:06 -05:00
Only users with the organization administrator role can add data sources.
2023-07-31 10:34:03 -05:00
Administrators can also [configure the data source via YAML ](#provision-the-data-source ) with Grafana's provisioning system.
2022-11-01 10:22:06 -05:00
2023-07-31 10:34:03 -05:00
Once you've added the Loki data source, you can [configure it ](#configure-the-data-source ) so that your Grafana instance's users can create queries in its [query editor ]({{< relref "./query-editor" >}} ) when they [build dashboards][build-dashboards], use [Explore][explore], and [annotate visualizations ]({{< relref "./query-editor#apply-annotations" >}} ).
2022-11-01 10:22:06 -05:00
2023-05-22 15:45:28 -05:00
{{% admonition type="note" %}}
To troubleshoot configuration and other issues, check the log file located at `/var/log/grafana/grafana.log` on Unix systems, or in `<grafana_install_dir>/data/log` on other platforms and manual installations.
{{% /admonition %}}
2022-11-01 10:22:06 -05:00
2023-07-25 11:10:28 -05:00
## Provision the Loki data source
2022-11-01 10:22:06 -05:00
You can define and configure the data source in YAML files as part of Grafana's provisioning system.
2023-07-31 10:34:03 -05:00
For more information about provisioning, and for available configuration options, refer to [Provisioning Grafana][provisioning-data-sources].
2022-11-01 10:22:06 -05:00
2023-07-25 11:10:28 -05:00
### Provisioning examples
2022-11-01 10:22:06 -05:00
```yaml
apiVersion: 1
datasources:
- name: Loki
type: loki
access: proxy
url: http://localhost:3100
jsonData:
maxLines: 1000
```
**Using basic authorization and a derived field:**
You must escape the dollar (`$`) character in YAML values because it can be used to interpolate environment variables:
```yaml
apiVersion: 1
datasources:
- name: Loki
type: loki
access: proxy
url: http://localhost:3100
basicAuth: true
basicAuthUser: my_user
jsonData:
maxLines: 1000
derivedFields:
# Field with internal link pointing to data source in Grafana.
# datasourceUid value can be anything, but it should be unique across all defined data source uids.
- datasourceUid: my_jaeger_uid
matcherRegex: "traceID=(\\w+)"
name: TraceID
# url will be interpreted as query for the datasource
url: '$${__value.raw}'
2023-07-05 07:08:45 -05:00
# optional for URL Label to set a custom display label for the link.
urlDisplayLabel: 'View Trace'
2022-11-01 10:22:06 -05:00
# Field with external link.
- matcherRegex: "traceID=(\\w+)"
name: TraceID
url: 'http://localhost:16686/trace/$${__value.raw}'
secureJsonData:
basicAuthPassword: test_password
```
**Using a Jaeger data source:**
In this example, the Jaeger data source's `uid` value should match the Loki data source's `datasourceUid` value.
```
datasources:
- name: Jaeger
type: jaeger
url: http://jaeger-tracing-query:16686/
access: proxy
# UID should match the datasourceUid in derivedFields.
uid: my_jaeger_uid
```
## Query the data source
The Loki data source's query editor helps you create log and metric queries that use Loki's query language, [LogQL ](/docs/loki/latest/logql/ ).
2023-07-31 10:34:03 -05:00
For details, refer to the [query editor documentation ]({{< relref "./query-editor" >}} ).
2022-11-01 10:22:06 -05:00
## Use template variables
Instead of hard-coding details such as server, application, and sensor names in metric queries, you can use variables.
Grafana lists these variables in dropdown select boxes at the top of the dashboard to help you change the data displayed in your dashboard.
Grafana refers to such variables as template variables.
2023-07-31 10:34:03 -05:00
For details, see the [template variables documentation ]({{< relref "./template-variables" >}} ).
{{% docs/reference %}}
[build-dashboards]: "/docs/grafana/ -> /docs/grafana/< GRAFANA VERSION > /dashboards/build-dashboards"
[build-dashboards]: "/docs/grafana-cloud/ -> /docs/grafana/< GRAFANA VERSION > /dashboards/build-dashboards"
[data-source-management]: "/docs/grafana/ -> /docs/grafana/< GRAFANA VERSION > /administration/data-source-management"
[data-source-management]: "/docs/grafana-cloud/ -> /docs/grafana/< GRAFANA VERSION > /administration/data-source-management"
[explore]: "/docs/grafana/ -> /docs/grafana/< GRAFANA VERSION > /explore"
[explore]: "/docs/grafana-cloud/ -> /docs/grafana/< GRAFANA VERSION > /explore"
[logs-integration-labels-and-detected-fields]: "/docs/grafana/ -> /docs/grafana/< GRAFANA VERSION > /explore/logs-integration#labels-and-detected-fields"
[logs-integration-labels-and-detected-fields]: "/docs/grafana-cloud/ -> /docs/grafana/< GRAFANA VERSION > /explore/logs-integration#labels-and-detected-fields"
[provisioning-data-sources]: "/docs/grafana/ -> /docs/grafana/< GRAFANA VERSION > /administration/provisioning#data-sources"
[provisioning-data-sources]: "/docs/grafana-cloud/ -> /docs/grafana/< GRAFANA VERSION > /administration/provisioning#data-sources"
{{% /docs/reference %}}