Skip to content

HTTP API

Lorenzo Mangani edited this page Jan 2, 2022 · 25 revisions

CLOKI HTTP API

cLoki API Functions are loosely implemented as documented by the Loki API reference.

LogQL

  • /loki/api/v1/push
  • /loki/api/v1/query
  • /loki/api/v1/query_range
  • /loki/api/v1/label
  • /loki/api/v1/label/name/values
  • /loki/api/v1/tail
  • /hello
  • /ready

Alertmanager

  • /api/prom/rules
  • /api/prom/rules/{namespace}
  • /api/prom/rules/{namespace}/{groupName}
  • /api/prom/rules/{namespace}
  • /api/prom/rules/{namespace}/{groupName}
  • /api/prom/rules/{namespace}

Tempo (experimental)

  • /tempo/api/push
  • /api/v2/spans
  • /api/traces/{traceId}
  • /api/search/tags
  • /api/search/tag/{tags}/values

API Examples

INSERT Labels & Logs
curl -i -XPOST -H "Content-Type: application/json" http://localhost:3100/loki/api/v1/push \
     --data '{"streams":[{"labels":"{\"__name__\":\"up\"}","entries":[{"timestamp":"2021-12-26T16:00:06.944Z", "line":"zzz"}]}]}'
QUERY Logs
curl -G -s localhost:3100/loki/api/v1/query_range --data-urlencode 'query={__name__="up"}'
{
    "streams": [
        {
            "labels": "{\"__name__\":\"up\"}",
            "entries": [
                {
                    "timestamp":"1545840006944",
                    "line":"zzz"
                },
                {
                    "timestamp":"1545840006944",
                    "line":"zzz"
                },
                {
                    "timestamp":"1545840006944",
                    "line":"zzz"
                }
            ]
        }
    ]
}
QUERY Labels
# curl localhost:3100/loki/api/v1/label
{"status": "success", "data":["__name__"]}
QUERY Label Values
# curl 'localhost:3100/loki/api/v1/label/__name__/values'
{"status": "success", "data":["up"]}

API Experimental

INSERT Labels & Metrics (experimental)

Both below variations are accepted to insert labeled metrics, or a hybrid of metrics and logs.

curl -i -XPOST -H "Content-Type: application/json" http://localhost:3100/loki/api/v1/push \
     --data '{"streams":[{"labels":"{\"__name__\":\"metric\"}","entries":[{"timestamp":"2021-12-26T16:00:06.944Z", "value":100}]}]}'
curl -i -XPOST -H "Content-Type: application/json" http://localhost:3100/loki/api/v1/push \
     --data '{"streams":[{"labels":"{\"__name__\":\"hybrid\"}","entries":[{"timestamp":"2021-12-26T16:00:06.944Z", "line":"zzz", "value":100}]}]}'
{
    "streams": [
        {
            "labels": "{\"__name__\":\"up\"}",
            "entries": [
                {
                    "timestamp":"1545840006944",
                    "line":"zzz"
                },
                {
                    "timestamp":"1545840006945",
                    "value": 100
                },
                {
                    "timestamp": "1545840006946",
                    "line":"zzz",
                    "value": 100
                }
            ]
        }
    ]
}
Clone this wiki locally