Add the data source in Grafana
- Create an API token with the
readability in the dashboard (Settings, API tokens). - In Grafana, open Connections, Data sources, Add data source, Loki.
- Set URL to your control plane address plus
/api/v1/loki, for examplehttps://levelrail.example.com/api/v1/loki. - Turn on Basic auth. Use any user name and paste the token as the password. Alternatively add a custom header
Authorizationwith the valueBearer <token>. - Click Save & test, then open Explore and run
{app="web"}.
Endpoints
Base path:/api/v1/loki. The paths Grafana builds (/api/v1/loki/loki/api/v1/...) are served too, so the data source URL above works unchanged.
All of them require the
read ability. Times are unix seconds, unix nanoseconds or RFC3339. limit defaults to 100 and is capped at 5000. direction is backward (newest first, the default) or forward. A range may not exceed 30 days (APP_LOKI_MAX_RANGE), and at most APP_LOG_SIGNATURE_MAX_ROWS lines are scanned per app per query.
Supported LogQL
- Stream selector with
=,!=,=~and!~onapp,streamandlevel. At least oneappmatcher with=or=~is required. Regexes are fully anchored, as in Loki. - Line filters
|=,!=,|~and!~, chained in any order. levelis present when a level could be read from the line or its JSON fields.
{"status":"error","errorType":"bad_data","error":"..."}) instead of a guessed answer: metric queries (rate, count_over_time, sum), parsers and stages (| json, | logfmt, | line_format, unwrap), and other labels.
For counts and trends use the log explorer and the metrics API instead.