Grafana Loki Integration Guide
Push alarm texts, machine events and quality records into Loki as log lines, and run LogQL queries whose lines and counts drive decisions.
- Push
- /loki/api/v1/push, JSON
- Query
- LogQL range and instant queries
- Operations
- Push Logs · Range Query · Instant Query
- Transport
- HTTP or HTTPS, port 3100 by default
Overview
Grafana Loki is the log store of the Grafana stack. It keeps log lines by stream, a set of labels such as {line="bc41", machine="op20"}, and answers LogQL queries over them. The Grafana Loki connector talks to Loki's HTTP API:
- Push Logs writes one line, or an array of lines, into one stream, with structured metadata per line.
- Range Query runs a LogQL query over a time window and returns its lines, or a metric query's series.
- Instant Query evaluates a LogQL metric query, such as
count_over_time, at one moment.
It works with a Loki reached directly, a multi-tenant Loki (one tenant per connection), Loki behind a gateway with Basic or Bearer authentication, and Grafana Cloud Logs.
When a resend is the same line. Loki stores a line with the same labels, time and text once; structured metadata is not part of that comparison. A resend is therefore the same line when it carries the same time. With Time empty, a pipeline write is stamped with the time it was produced, the same on the first attempt, on a Retry on Fail and on a store-and-forward replay, so a push resent after a lost answer is the same line and Loki keeps one. These are stamped anew on each attempt, so a resend may be a second line: a pipeline test run, the Test button, an API or MCP call without a write key, and a run redelivered after a crash. Set Time from the event (a timestamp the source sent) to be one line in every case.
Prerequisites
- Network access from MaestroHub to Loki's HTTP port (3100 by default) or to the gateway in front of it.
- The tenant ID when Loki runs multi-tenant (
auth_enabled: true). Such a Loki refuses any request without one. - For a gateway or Grafana Cloud: credentials allowed to push logs. On Grafana Cloud, the user is the stack's Loki user ID and the password an access-policy token with
logs:write(addlogs:readfor queries). - For Metadata: Loki 3, or Loki 2.9 with structured metadata allowed and the TSDB v13 schema.
Connection Configuration
Navigate to Connections → New Connection → Grafana Loki.


The Connection tab: Loki's address and the tenant
Connection
| Field | Required | Description |
|---|---|---|
| Server URL | Yes | Loki's base URL, e.g. http://loki.plant.local:3100, or the gateway's (Grafana Cloud: https://logs-prod-<region>.grafana.net). Include a sub-path when Loki is served under one. A URL pasted with an API path (/loki/api/v1/push) is cut back to the base. |
| Tenant | For multi-tenant Loki | Sent as X-Scope-OrgID on every request. Lines are pushed to and read from this tenant only. Letters, digits and !-_.*'(), at most 150 characters. Leave empty for a single-tenant Loki or Grafana Cloud. |
| Connect Timeout | No | How long the connection check may take, 10s by default. |
Authentication
Loki has no login of its own; a gateway in front of it does.
| Field | Used with | Description |
|---|---|---|
| Authentication | none for a Loki reached directly, basic for a user and password, bearer for a token. | |
| Username, Password | basic | Grafana Cloud: the stack's Loki user ID and an access-policy token. The password is stored encrypted. |
| Bearer Token | bearer | Sent as Authorization: Bearer. Stored encrypted. |
Only the chosen mode's fields are sent; values left in another mode's fields are kept but never used.
TLS
| Field | Description |
|---|---|
| CA Certificate (PEM) | The CA that signed Loki's or the gateway's certificate, when it is not publicly trusted. |
| Client Certificate (PEM), Client Private Key (PEM) | For mutual TLS, when the gateway asks for a client certificate. The key is stored encrypted. |
| Server Name | The name to check the certificate against, when it differs from the host in the Server URL. |
| Skip Certificate Verification | Accept any certificate. For testing only. |
How the connection is checked
Test Connection, and the health check while the connection runs, send Loki an empty push. Loki checks the credential and the tenant first and then stores nothing: Loki 3.5 and later answer 422 (no stream), older versions answer 204 (measured on 2.9 and 3.0), and both pass. Any other success answer is not Loki and fails the check. So a wrong password, a missing tenant or a URL that is not Loki shows as a failed connection at once. The check needs push rights: a read-only token fails it.
Function Builder
After saving the connection, open its Functions tab → New Function and choose Push Logs, Range Query or Instant Query.


Push Logs writes; Range Query and Instant Query read with LogQL
Push Logs
| Parameter | Required | Description |
|---|---|---|
| Lines | Yes | Text is one line; a JSON object is one line written as JSON (LogQL's | json reads it back); a JSON array pushes one line per element in one request, at most 10,000. ((reading)) passes a pipeline value through as it is. |
| Labels | Yes | The stream's labels as a JSON object, at least one, e.g. {"line": "bc41", "machine": "op20"}. Names are letters, digits and _, not starting with a digit or __. |
| Metadata | No | Structured metadata stored with every line of the call, e.g. {"order": "PO-1182"}. Same name rules as labels. Loki tells lines apart by stream, time and text, not metadata: two lines that differ only in Metadata are stored as one. |
| Time | No | When the lines happened: an RFC 3339 timestamp (2026-11-17T09:00:00.250Z) or Unix epoch seconds (1794906000.25), from 1678 to 2262 (Loki counts nanoseconds). A number too large to be seconds is refused rather than read as milliseconds. Empty: the moment the pipeline produced the write. Set it from the event so a resend is the same line; two events with the same Time, labels and text are one line in Loki, whatever their Metadata. |
| Timeout | No | Bound on this call, 30s by default. |
Labels make streams. Loki creates one stream per distinct label set and indexes only labels. A templated label value must come from a small set (a line, a machine, a severity); an order number, a serial number, a trace ID or a time in a label creates a stream per value, which slows Loki down and runs into its stream limit. Put such values in Metadata: Loki stores them with each line, you filter on them in LogQL ({machine="op20"} | order="PO-1182"), and they make no stream.
A ((parameter)) in any field becomes a function parameter, filled from the pipeline at run time:


A Push Logs function whose line and labels carry pipeline values
The result is {"linesPushed": <n>, "timestamp": "<first line's time>"}.
What happens when Loki refuses. A line older than Loki accepts, a line more than an hour behind the newest line of its stream, a time in the future, too many labels or a line that is too long fail the node, and trying again does not help: the message names Loki's setting to change. When Loki refuses part of an array it may keep the other lines; replaying the push from Failed messages carries the write's produce time, so they are stored once (except for the writes stamped anew, listed under When a resend is the same line). Loki's rate limits (HTTP 429) and its outages (HTTP 5xx, no answer) fail the node as retryable: with store-and-forward the push is buffered and delivered when Loki takes it.
Range Query
| Parameter | Required | Description |
|---|---|---|
| LogQL Query | Yes | A log query ({machine="op20"} |= "alarm") or a metric query (sum by (machine) (count_over_time({line="bc41"}[5m]))). A ((placeholder)) is put into the query as LogQL, not as a quoted value: a value from a message can change what the query selects, so fill placeholders only from values you trust. |
| Start, End | Yes | The window: now, an offset before now (-1h, -15m), an RFC 3339 timestamp or Unix epoch seconds. Defaults -1h and now. |
| Max Lines | No | The most log lines to return across all streams, 1 to 5000 (Loki's own default cap), 100 by default. |
| Direction | No | backward (newest first, the default) or forward (oldest first). The limit keeps the lines at that end of the window. |
| Step | No | For a metric query, the distance between points, e.g. 1m. Empty: Loki's default for the window. |
| Timeout | No | Bound on this call, 1m by default. |
The window, the limit and the step go to Loki with the query: MaestroHub never fetches more than it returns. The result holds lines for a log query and series for a metric query; limitReached is true when Loki returned exactly Max Lines. An answer is read within these limits, and refused the moment it crosses one: at most 64 MiB of answer, in UTF-8; at most Max Lines lines, 5,000 series in a metric answer and 100,000 points (series times steps); and a result of at most 64 MiB as it is passed on. The result counts each line's text, its labels (structured metadata and extracted labels included; a stream's labels once for each of its lines, as each line carries them) and each point, at the size they take in JSON (<, > and & take six bytes each). Measured at those limits, one call peaks at about 350 MiB of memory; a usual answer takes a few MiB. A log answer too large fails the node: lower Max Lines, narrow Start and End, or drop extracted labels with | keep or | drop. A metric answer too large: raise Step, narrow Start and End, or aggregate the query (sum by (...)). For example count_over_time({line="bc41"}[5m]) over a week at a 1m step is 10,080 points per series, so 10 such series are already past the limit.
Instant Query
| Parameter | Required | Description |
|---|---|---|
| LogQL Query | Yes | A metric query such as count_over_time({machine="op20"} |= "alarm" [10m]). Loki refuses a log query here. |
| Time | No | When to evaluate: now (the default), an offset, an RFC 3339 timestamp or Unix epoch seconds. |
| Timeout | No | Bound on this call, 1m by default. |
Pipeline Integration


The Grafana Loki Push Logs node with its connection and function
The three functions become pipeline nodes, Grafana Loki Push Logs, Grafana Loki Range Query and Grafana Loki Instant Query, under the database group of the node library. Their outputs are described on the Grafana Loki nodes page.
Common Use Cases
Keep every machine alarm in Loki
A pipeline triggered by an alarm tag pushes {"alarm": "((code))", "text": "((text))", "state": "((state))"} with labels {"line": "bc41", "machine": "((machine))"} and the work order in Metadata. Grafana then shows the alarm history next to the line's metrics, and with store-and-forward on, alarms raised while the link to Loki is down arrive when it returns, at the time they happened.
Ask Loki before acting
Before a pipeline opens a maintenance order, Instant Query counts the machine's alarm lines in the last hour (sum(count_over_time({machine="((machine))"} |= "alarm" [1h]))). A Condition node compares $node["Grafana Loki Instant Query"].result.series[0].points[0].value with a threshold; an empty series means there were none.
Attach recent log lines to a record
Range Query with {machine="((machine))"}, Start -15m and Max Lines 20 returns the latest lines, newest first, to store with a quality record or send with a notification.
Troubleshooting
| Message | Cause | What to do |
|---|---|---|
no org id | Loki is multi-tenant and the connection has no Tenant. | Set Tenant. |
401, invalid credentials | The gateway refused the credential. | Check Authentication; on Grafana Cloud, the user ID and an access-policy token. |
403 | The credential may not do this. | Give the access policy logs:write to push and logs:read to query. |
404 page not found | The Server URL is not Loki's base address. | Use the address under which /loki/api/v1 answers. |
timestamp too old | The line is older than Loki accepts (reject_old_samples_max_age, a week by default). If the push was a resend, its lines may already be stored. | Raise reject_old_samples_max_age on Loki, then replay from Failed messages. |
entry too far behind | The line is more than Loki's out-of-order window (half of max_chunk_age, an hour by default) older than the newest line of its stream. If the push was a resend, its lines may already be stored. | Push lines close to when they happen, or raise max_chunk_age on Loki, then replay from Failed messages. |
more than 100000 points, more than 5000 series, makes a result of more than 64 MiB | The answer is larger than one call reads or returns. | A log query: lower Max Lines, narrow Start and End, or drop extracted labels with | keep or | drop. A metric query: raise Step, narrow Start and End, or aggregate (sum by (...)). |
timestamp too new | The line's time is in the future for Loki. | Check the clock of the source that set Time. |
label names; limit 15 | Too many labels on the stream: Loki counts the labels sent, before it adds service_name. | Move values to Metadata. |
Ingestion rate limit exceeded | Loki is pacing this tenant. | Retried automatically; raise ingestion_rate_mb on Loki for a steady higher rate. |
structured metadata, disallowed | This Loki does not take structured metadata. | Leave Metadata empty, or enable it on Loki (allow_structured_metadata, TSDB v13 schema). |
structured metadata too large | A line's Metadata is larger than max_structured_metadata_size (64KB by default). | Send less, or raise it on Loki. |
too many structured metadata | A line carries more Metadata entries than max_structured_metadata_entries_count (128 by default). | Send fewer, or raise it on Loki. |
maximum of series (500) reached for a single query | The query matches more series than Loki answers at once (max_query_series). | Narrow the selector, aggregate (sum by (...)), raise Step, or raise max_query_series on Loki. |
Loki's answer is larger than 64 MiB | The answer itself is larger than this connector reads. | Narrow the query: a shorter window, a larger Step, fewer lines. |
answered 200 with …, which Loki does not | The Server URL answers like a web page, not like Loki: a catch-all proxy, a gateway's page or a login page. Loki answers a push 204, and the connection check 422 (204 on older versions). | Set the Server URL to Loki's own address; lines pushed to the other server are not in Loki. |
not valid UTF-8 | A line holds bytes in another encoding, which JSON may not carry. | Leave such lines out of the query, with a line filter or a label that marks them. |
values before its labels, text follows Loki's answer | The answer is not in the shape Loki writes: often a proxy in front of Loki that rewrites it. | Point the Server URL at Loki itself, or at a gateway that passes Loki's answers unchanged. |
maximum resolution of 11,000 points | A metric query asks for more points per series than Loki computes. | Raise Step, or narrow Start and End. |
max entries limit per query exceeded | Max Lines is above Loki's max_entries_limit_per_query. | Lower Max Lines. |
log queries are not supported as an instant query type | Instant Query got a log query. | Use Range Query, or wrap the query in count_over_time(...). |
parse error | The LogQL is wrong. | Try the query in Grafana Explore to see the error in context. |
x509: certificate signed by unknown authority | The server's certificate is not trusted. | Paste its CA under CA Certificate. |