Loki
Push log lines from rows to Grafana Loki and run LogQL queries as rows. Typical uses: send business logs to Loki, count errors for a report.
loki pingloki pushloki pushloki queryloki queryloki query_rangeloki query_rangeloki labelsloki labelsloki label_valuesloki label_valuesloki seriesloki seriesloki requestloki request

loki ping <config>


Description

    Test the connection. Returns {ok, version, ready}

Parameters

    config:   The configuration as JSON: url (http://127.0.0.1:3100, or the gateway of a Loki cluster), username with password (basic authentication, often a reverse proxy), or token (a bearer token), tenant (the X-Scope-OrgID header of a multi-tenant Loki), timeout_ms (30000: the longest silence of the server; a whole answer must arrive within 10 x timeout_ms), max_bytes (64 MB, 256 MB at most: the largest answer read), ca_file (a PEM file of a private CA, with https), allow_plain (false: credentials over http are refused unless the host is this machine) - String - required
admin
loki ping "{\"url\": \"http://127.0.0.1:3100\"}"
mentdb
{"ok": true, "version": "3.7.10", "ready": true}

loki push <config> <rows_json>


Description

    Push log lines from rows (the field line, or the other fields as JSON). Returns {pushed, streams}

Parameters

    config:   The configuration as JSON: url (http://127.0.0.1:3100, or the gateway of a Loki cluster), username with password (basic authentication, often a reverse proxy), or token (a bearer token), tenant (the X-Scope-OrgID header of a multi-tenant Loki), timeout_ms (30000: the longest silence of the server; a whole answer must arrive within 10 x timeout_ms), max_bytes (64 MB, 256 MB at most: the largest answer read), ca_file (a PEM file of a private CA, with https), allow_plain (false: credentials over http are refused unless the host is this machine) - String - required
    rows_json:   The rows: a JSON array of objects (or one object) - String - required
admin
loki push "{\"url\": \"http://127.0.0.1:3100\"}" "[{\"line\": \"import started\"}, {\"line\": \"import finished: 1200 rows\"}]"
mentdb
{"pushed": 2, "streams": 1}

loki push <config> <rows_json> <options_json>


Description

    Push log lines with options: labels (the fields that are labels), static_labels (labels of every line), line_field (line), time_field (time), metadata (the fields sent as structured metadata), line_format (json or logfmt: the line built from the other fields when there is no line field)

Parameters

    config:   The configuration as JSON: url (http://127.0.0.1:3100, or the gateway of a Loki cluster), username with password (basic authentication, often a reverse proxy), or token (a bearer token), tenant (the X-Scope-OrgID header of a multi-tenant Loki), timeout_ms (30000: the longest silence of the server; a whole answer must arrive within 10 x timeout_ms), max_bytes (64 MB, 256 MB at most: the largest answer read), ca_file (a PEM file of a private CA, with https), allow_plain (false: credentials over http are refused unless the host is this machine) - String - required
    rows_json:   The rows - String - required
    options_json:   The options - String - required
admin
loki push "{\"url\": \"http://127.0.0.1:3100\"}" "[{\"app\": \"billing\", \"level\": \"info\", \"line\": \"invoice 42 sent\", \"time\": \"2026-11-17T15:00:00.123456789Z\"}, {\"app\": \"billing\", \"level\": \"error\", \"line\": \"invoice 43 rejected\", \"time\": \"2026-11-17T15:00:01Z\"}, {\"app\": \"stock\", \"level\": \"info\", \"line\": \"stock updated\", \"time\": 1794927602}]" "{\"labels\": [\"app\", \"level\"], \"static_labels\": {\"source\": \"mentdb\"}}"
mentdb
{"pushed": 3, "streams": 3}
a line in logfmt from the other fields, with structured metadata (fixed result: real Loki 3.7.10)
admin
loki push "{\"url\": \"http://127.0.0.1:3100\"}" "[{\"app\": \"billing\", \"customer\": \"c001\", \"amount\": 120.5, \"trace_id\": \"4bf92f3577b34da6\", \"time\": \"2026-11-17T15:00:03Z\"}]" "{\"labels\": [\"app\"], \"metadata\": [\"trace_id\"], \"line_format\": \"logfmt\"}"
mentdb
{"pushed": 1, "streams": 1}
a line in JSON from the other fields (fixed result: real Loki 3.7.10)
admin
loki push "{\"url\": \"http://127.0.0.1:3100\"}" "[{\"app\": \"billing\", \"customer\": \"c002\", \"amount\": 99, \"time\": \"2026-11-17T15:00:04Z\"}]" "{\"labels\": [\"app\"]}"
mentdb
{"pushed": 1, "streams": 1}
An empty label
admin
loki push "{\"url\": \"http://127.0.0.1:3100\"}" "[{\"app\": \"\", \"line\": \"x\"}]" "{\"labels\": [\"app\"]}"
mentdb
ERROR: Sorry, an error appears (the row 0: the label 'app' is empty (Loki drops empty labels: leave it out)).

loki query <config> <logql>


Description

    An instant LogQL query, now (for metric queries). Returns rows

Parameters

    config:   The configuration as JSON: url (http://127.0.0.1:3100, or the gateway of a Loki cluster), username with password (basic authentication, often a reverse proxy), or token (a bearer token), tenant (the X-Scope-OrgID header of a multi-tenant Loki), timeout_ms (30000: the longest silence of the server; a whole answer must arrive within 10 x timeout_ms), max_bytes (64 MB, 256 MB at most: the largest answer read), ca_file (a PEM file of a private CA, with https), allow_plain (false: credentials over http are refused unless the host is this machine) - String - required
    logql:   The LogQL query: a log query ({app="billing"} |= "error") or a metric query (sum by (level) (count_over_time({app="billing"}[5m]))) - String - required
admin
loki query "{\"url\": \"http://127.0.0.1:3100\"}" "sum by (app) (count_over_time({app=~\".+\"}[10m]))"
mentdb
[]

loki query <config> <logql> <options_json>


Description

    An instant query with options: time, limit (1000), direction (backward or forward), time_format

Parameters

    config:   The configuration as JSON: url (http://127.0.0.1:3100, or the gateway of a Loki cluster), username with password (basic authentication, often a reverse proxy), or token (a bearer token), tenant (the X-Scope-OrgID header of a multi-tenant Loki), timeout_ms (30000: the longest silence of the server; a whole answer must arrive within 10 x timeout_ms), max_bytes (64 MB, 256 MB at most: the largest answer read), ca_file (a PEM file of a private CA, with https), allow_plain (false: credentials over http are refused unless the host is this machine) - String - required
    logql:   The LogQL query: a log query ({app="billing"} |= "error") or a metric query (sum by (level) (count_over_time({app="billing"}[5m]))) - String - required
    options_json:   The options - String - required
admin
loki query "{\"url\": \"http://127.0.0.1:3100\"}" "sum by (app) (count_over_time({app=~\".+\"}[10m]))" "{\"time\": \"2026-11-17T15:05:00Z\"}"
mentdb
[{"app": "billing", "value": 5, "time": "2026-11-17T15:05:00Z"}, {"app": "stock", "value": 1, "time": "2026-11-17T15:05:00Z"}]

loki query_range <config> <logql> <start> <end>


Description

    A LogQL query from start to end. Returns rows {labels..., time, line} (newest first), or {labels..., value, time} for a metric query

Parameters

    config:   The configuration as JSON: url (http://127.0.0.1:3100, or the gateway of a Loki cluster), username with password (basic authentication, often a reverse proxy), or token (a bearer token), tenant (the X-Scope-OrgID header of a multi-tenant Loki), timeout_ms (30000: the longest silence of the server; a whole answer must arrive within 10 x timeout_ms), max_bytes (64 MB, 256 MB at most: the largest answer read), ca_file (a PEM file of a private CA, with https), allow_plain (false: credentials over http are refused unless the host is this machine) - String - required
    logql:   The LogQL query: a log query ({app="billing"} |= "error") or a metric query (sum by (level) (count_over_time({app="billing"}[5m]))) - String - required
    start:   The start: now-1h, an ISO 8601 time or a unix time - String - required
    end:   The end - String - required
admin
loki query_range "{\"url\": \"http://127.0.0.1:3100\"}" "{app=\"billing\"}" "2026-11-17T14:59:00Z" "2026-11-17T15:01:00Z"
mentdb
[{"app": "billing", "detected_level": "unknown", "service_name": "billing", "time": "2026-11-17T15:00:04Z", "line": "{\"customer\": \"c002\", \"amount\": 99}"}, {"app": "billing", "detected_level": "unknown", "service_name": "billing", "trace_id": "4bf92f3577b34da6", "time": "2026-11-17T15:00:03Z", "line": "customer=c001 amount=120.5"}, {"app": "billing", "detected_level": "unknown", "service_name": "billing", "trace_id": "abc", "time": "2026-11-17T15:00:03Z", "line": "customer=c001 amount=120.5"}, {"app": "billing", "detected_level": "error", "level": "error", "service_name": "billing", "source": "mentdb", "time": "2026-11-17T15:00:01Z", "line": "invoice 43 rejected"}, {"app": "billing", "detected_level": "info", "level": "info", "service_name": "billing", "source": "mentdb", "time": "2026-11-17T15:00:00.123456789Z", "line": "invoice 42 sent"}]
a parser: the fields of the JSON lines become labels (fixed result: real Loki 3.7.10)
admin
loki query_range "{\"url\": \"http://127.0.0.1:3100\"}" "{app=\"billing\"} | json" "2026-11-17T15:00:04Z" "2026-11-17T15:00:05Z"
mentdb
[{"amount": "99", "app": "billing", "customer": "c002", "detected_level": "unknown", "service_name": "billing", "time": "2026-11-17T15:00:04Z", "line": "{\"customer\": \"c002\", \"amount\": 99}"}]
a syntax error (fixed result: real Loki 3.7.10)
admin
loki query_range "{\"url\": \"http://127.0.0.1:3100\"}" "{app=\"billing\"" "now-1h" "now"
mentdb
ERROR: Sorry, an error appears (Loki error HTTP 400: parse error at line 1, col 15: syntax error: unexpected $end, expecting } or ,).

loki query_range <config> <logql> <start> <end> <options_json>


Description

    A query with options: limit (1000 lines), direction (backward: the newest first, or forward), step (for metric queries), time_format

Parameters

    config:   The configuration as JSON: url (http://127.0.0.1:3100, or the gateway of a Loki cluster), username with password (basic authentication, often a reverse proxy), or token (a bearer token), tenant (the X-Scope-OrgID header of a multi-tenant Loki), timeout_ms (30000: the longest silence of the server; a whole answer must arrive within 10 x timeout_ms), max_bytes (64 MB, 256 MB at most: the largest answer read), ca_file (a PEM file of a private CA, with https), allow_plain (false: credentials over http are refused unless the host is this machine) - String - required
    logql:   The LogQL query: a log query ({app="billing"} |= "error") or a metric query (sum by (level) (count_over_time({app="billing"}[5m]))) - String - required
    start:   The start - String - required
    end:   The end - String - required
    options_json:   The options - String - required
admin
loki query_range "{\"url\": \"http://127.0.0.1:3100\"}" "{source=\"mentdb\"} |= \"invoice\"" "2026-11-17T14:59:00Z" "2026-11-17T15:10:00Z" "{\"direction\": \"forward\", \"limit\": 10, \"time_format\": \"unix_ns\"}"
mentdb
[{"app": "billing", "detected_level": "info", "level": "info", "service_name": "billing", "source": "mentdb", "time": "1794927600123456789", "line": "invoice 42 sent"}, {"app": "billing", "detected_level": "error", "level": "error", "service_name": "billing", "source": "mentdb", "time": "1794927601000000000", "line": "invoice 43 rejected"}]
a metric query by level, every minute (fixed result: real Loki 3.7.10)
admin
loki query_range "{\"url\": \"http://127.0.0.1:3100\"}" "sum by (level) (count_over_time({source=\"mentdb\"}[1m]))" "2026-11-17T14:59:00Z" "2026-11-17T15:01:00Z" "{\"step\": \"60s\"}"
mentdb
[{"level": "error", "value": 1, "time": "2026-11-17T15:01:00Z"}, {"level": "info", "value": 2, "time": "2026-11-17T15:01:00Z"}]

loki labels <config>


Description

    The label names (of the last hours, as Loki chooses). Returns a JSON array

Parameters

    config:   The configuration as JSON: url (http://127.0.0.1:3100, or the gateway of a Loki cluster), username with password (basic authentication, often a reverse proxy), or token (a bearer token), tenant (the X-Scope-OrgID header of a multi-tenant Loki), timeout_ms (30000: the longest silence of the server; a whole answer must arrive within 10 x timeout_ms), max_bytes (64 MB, 256 MB at most: the largest answer read), ca_file (a PEM file of a private CA, with https), allow_plain (false: credentials over http are refused unless the host is this machine) - String - required
admin
loki labels "{\"url\": \"http://127.0.0.1:3100\"}"
mentdb
["app", "job", "level", "service_name", "source"]

loki labels <config> <options_json>


Description

    The label names with options: start, end, query (a stream selector)

Parameters

    config:   The configuration as JSON: url (http://127.0.0.1:3100, or the gateway of a Loki cluster), username with password (basic authentication, often a reverse proxy), or token (a bearer token), tenant (the X-Scope-OrgID header of a multi-tenant Loki), timeout_ms (30000: the longest silence of the server; a whole answer must arrive within 10 x timeout_ms), max_bytes (64 MB, 256 MB at most: the largest answer read), ca_file (a PEM file of a private CA, with https), allow_plain (false: credentials over http are refused unless the host is this machine) - String - required
    options_json:   The options - String - required
admin
loki labels "{\"url\": \"http://127.0.0.1:3100\"}" "{\"start\": \"2026-11-17T14:00:00Z\", \"end\": \"2026-11-17T16:00:00Z\", \"query\": \"{app=\\"billing\\"}\"}"
mentdb
["app", "level", "service_name", "source"]

loki label_values <config> <label>


Description

    The values of a label. Returns a JSON array

Parameters

    config:   The configuration as JSON: url (http://127.0.0.1:3100, or the gateway of a Loki cluster), username with password (basic authentication, often a reverse proxy), or token (a bearer token), tenant (the X-Scope-OrgID header of a multi-tenant Loki), timeout_ms (30000: the longest silence of the server; a whole answer must arrive within 10 x timeout_ms), max_bytes (64 MB, 256 MB at most: the largest answer read), ca_file (a PEM file of a private CA, with https), allow_plain (false: credentials over http are refused unless the host is this machine) - String - required
    label:   The label name - String - required
admin
loki label_values "{\"url\": \"http://127.0.0.1:3100\"}" "app"
mentdb
["billing", "stock"]

loki label_values <config> <label> <options_json>


Description

    The values of a label with options: start, end, query

Parameters

    config:   The configuration as JSON: url (http://127.0.0.1:3100, or the gateway of a Loki cluster), username with password (basic authentication, often a reverse proxy), or token (a bearer token), tenant (the X-Scope-OrgID header of a multi-tenant Loki), timeout_ms (30000: the longest silence of the server; a whole answer must arrive within 10 x timeout_ms), max_bytes (64 MB, 256 MB at most: the largest answer read), ca_file (a PEM file of a private CA, with https), allow_plain (false: credentials over http are refused unless the host is this machine) - String - required
    label:   The label name - String - required
    options_json:   The options - String - required
admin
loki label_values "{\"url\": \"http://127.0.0.1:3100\"}" "level" "{\"start\": \"2026-11-17T14:00:00Z\", \"end\": \"2026-11-17T16:00:00Z\"}"
mentdb
["error", "info"]

loki series <config> <match>


Description

    The streams (label sets) matching a selector. Returns rows of labels

Parameters

    config:   The configuration as JSON: url (http://127.0.0.1:3100, or the gateway of a Loki cluster), username with password (basic authentication, often a reverse proxy), or token (a bearer token), tenant (the X-Scope-OrgID header of a multi-tenant Loki), timeout_ms (30000: the longest silence of the server; a whole answer must arrive within 10 x timeout_ms), max_bytes (64 MB, 256 MB at most: the largest answer read), ca_file (a PEM file of a private CA, with https), allow_plain (false: credentials over http are refused unless the host is this machine) - String - required
    match:   A stream selector, or a JSON array of selectors - String - required
admin
loki series "{\"url\": \"http://127.0.0.1:3100\"}" "{job=\"mentdb\"}"
mentdb
[{"job": "mentdb", "service_name": "mentdb"}]

loki series <config> <match> <options_json>


Description

    The streams with options: start, end, limit (10000)

Parameters

    config:   The configuration as JSON: url (http://127.0.0.1:3100, or the gateway of a Loki cluster), username with password (basic authentication, often a reverse proxy), or token (a bearer token), tenant (the X-Scope-OrgID header of a multi-tenant Loki), timeout_ms (30000: the longest silence of the server; a whole answer must arrive within 10 x timeout_ms), max_bytes (64 MB, 256 MB at most: the largest answer read), ca_file (a PEM file of a private CA, with https), allow_plain (false: credentials over http are refused unless the host is this machine) - String - required
    match:   A stream selector, or a JSON array of selectors - String - required
    options_json:   The options - String - required
admin
loki series "{\"url\": \"http://127.0.0.1:3100\"}" "{app=\"billing\"}" "{\"start\": \"2026-11-17T14:00:00Z\", \"end\": \"2026-11-17T16:00:00Z\"}"
mentdb
[{"app": "billing", "service_name": "billing"}, {"app": "billing", "level": "info", "service_name": "billing", "source": "mentdb"}, {"app": "billing", "level": "error", "service_name": "billing", "source": "mentdb"}]

loki request <config> <method> <path>


Description

    Any request to the API (path under the url). Returns the answer text

Parameters

    config:   The configuration as JSON: url (http://127.0.0.1:3100, or the gateway of a Loki cluster), username with password (basic authentication, often a reverse proxy), or token (a bearer token), tenant (the X-Scope-OrgID header of a multi-tenant Loki), timeout_ms (30000: the longest silence of the server; a whole answer must arrive within 10 x timeout_ms), max_bytes (64 MB, 256 MB at most: the largest answer read), ca_file (a PEM file of a private CA, with https), allow_plain (false: credentials over http are refused unless the host is this machine) - String - required
    method:   The HTTP method - String - required
    path:   The path - String - required
admin
loki request "{\"url\": \"http://127.0.0.1:3100\"}" "GET" "/loki/api/v1/status/buildinfo"
mentdb
{"version":"3.7.10","revision":"c792f585","branch":"release-3.7.x","buildUser":"root@d3ca4d55ebe5","buildDate":"2026-11-13T00:20:52Z","goVersion":""}

loki request <config> <method> <path> <body_json>


Description

    Any request with a JSON body

Parameters

    config:   The configuration as JSON: url (http://127.0.0.1:3100, or the gateway of a Loki cluster), username with password (basic authentication, often a reverse proxy), or token (a bearer token), tenant (the X-Scope-OrgID header of a multi-tenant Loki), timeout_ms (30000: the longest silence of the server; a whole answer must arrive within 10 x timeout_ms), max_bytes (64 MB, 256 MB at most: the largest answer read), ca_file (a PEM file of a private CA, with https), allow_plain (false: credentials over http are refused unless the host is this machine) - String - required
    method:   The HTTP method - String - required
    path:   The path - String - required
    body_json:   The JSON body - String - required
admin
loki request "{\"url\": \"http://127.0.0.1:3100\", \"tenant\": \"shop1\"}" "POST" "/loki/api/v1/push" "{\"streams\": [{\"stream\": {\"job\": \"mentdb\"}, \"values\": [[\"1794927607000000000\", \"tenant line\"]]}]}"
mentdb
ERROR: Sorry, an error appears (Loki error HTTP 400: entry with timestamp 2026-11-17 15:00:07 +0000 UTC ignored, reason: 'entry too far behind, entry timestamp is: 2026-11-17T15:00:07Z, oldest acceptable timestamp is: 2026-11-17T15:07:39Z', user 'fake', total ignored: 1 out of 1 for stream: {job="mentdb", service_name="mentdb"}).