---
title: "Loki data source | Grafana Cloud documentation"
description: "Guide for using Loki in Grafana"
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Loki data source

Grafana Loki is a horizontally scalable, highly available, multi-tenant log aggregation system by Grafana Labs. Unlike other logging systems, Loki indexes only metadata about your logs in the form of labels, the same label model used by Prometheus. Loki compresses and stores the log content itself in chunks in object stores such as Amazon S3 or Google Cloud Storage, or on a local filesystem. The Loki data source in Grafana lets you query and visualize those logs, and correlate them with metrics, traces, and other data in unified dashboards.

Grafana includes built-in support for Loki, so you don’t need to install a plugin.

## Supported features

Expand table

| Feature     | Supported                                                  |
|-------------|------------------------------------------------------------|
| Logs        | Yes                                                        |
| Metrics     | Yes. Use LogQL metric queries to derive metrics from logs. |
| Traces      | No                                                         |
| Alerting    | Yes                                                        |
| Annotations | Yes                                                        |

## Get started

The following documents help you get started with the Loki data source:

- [Configure the Loki data source](/docs/grafana-cloud/observe-and-act/connect-externally-hosted/data-sources/loki/configure/)
- [Loki query editor](/docs/grafana-cloud/observe-and-act/connect-externally-hosted/data-sources/loki/query-editor/)
- [Template variables](/docs/grafana-cloud/observe-and-act/connect-externally-hosted/data-sources/loki/template-variables/)
- [Loki annotations](/docs/grafana-cloud/observe-and-act/connect-externally-hosted/data-sources/loki/annotations/)
- [Loki alerting](/docs/grafana-cloud/observe-and-act/connect-externally-hosted/data-sources/loki/alerting/)
- [Troubleshoot Loki issues](/docs/grafana-cloud/observe-and-act/connect-externally-hosted/data-sources/loki/troubleshooting/)

To learn more about Loki itself, refer to the following Loki documentation:

- [Get started with Loki](/docs/loki/latest/get-started/)
- [Install Loki](/docs/loki/latest/setup/install/)
- [Loki best practices](/docs/loki/latest/best-practices/)
- [LogQL query language](/docs/grafana-cloud/observe-and-act/connect-externally-hosted/data-sources/loki//)

## Additional features

After configuring the Loki data source, you can:

- Use [Explore](/docs/grafana/next/explore/) to query and live tail logs without building a dashboard.
- Use [Grafana Logs Drilldown](/docs/grafana/next/explore/simplified-exploration/logs/) to explore your Loki logs without writing LogQL queries.
- Create a wide variety of [visualizations](/docs/grafana/next/panels-visualizations/visualizations/).
- Add [transformations](/docs/grafana/next/panels-visualizations/query-transform-data/transform-data/) to manipulate query results.
- Set up [alerting](/docs/grafana-cloud/observe-and-act/alert-and-measure-reliability/alerting/) on your logs.
- Add [annotations](/docs/grafana/next/dashboards/build-dashboards/annotate-visualizations/) to overlay log events on your graphs.
- Optimize performance with [query caching](/docs/grafana/next/administration/data-source-management/#query-and-resource-caching).

## Query with the Grafana CLI

You can query this data source from the command line and from AI coding agents using the Grafana CLI, `gcx`. `gcx` gives you and your agent structured, terminal-based access to your Grafana data sources, which is useful for automation and agent-driven investigations.

`gcx` supports Grafana Cloud and Grafana OSS or Enterprise v12 and later. Before you query, install and authenticate `gcx`. Refer to the [`gcx` CLI documentation](/docs/grafana/next/as-code/observability-as-code/grafana-cli/gcx/) for installation, configuration, and the full command reference.

For example, to query your Loki data source, use the `gcx datasources loki` commands:

sh ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```sh
# Run a LogQL query that returns log lines
gcx datasources loki query -d <DATASOURCE_UID> '{job="varlogs"} |= "error"' --since 1h

# Run a metric LogQL query that returns time series
gcx datasources loki metrics -d <DATASOURCE_UID> 'rate({job="varlogs"}[5m])' --since 1h

# List all labels, or the values for a single label
gcx datasources loki labels -d <DATASOURCE_UID>
gcx datasources loki labels -d <DATASOURCE_UID> --label job

# List log streams matching a selector
gcx datasources loki series -d <DATASOURCE_UID> --match '{job="varlogs"}'
```

Replace *`<DATASOURCE_UID>`* with the UID of your Loki data source. You can omit the `-d` flag when `datasources.loki` is configured in your `gcx` context. The `query` command returns log lines, `metrics` returns time series from a metric LogQL query, and `series` requires at least one `--match` stream selector.

## Related resources

- [Loki documentation](/docs/loki/latest/)
- [LogQL query language](/docs/grafana-cloud/observe-and-act/connect-externally-hosted/data-sources/loki//)
- [Grafana community forum](https://community.grafana.com/)
