current position:Home>Loki HTTP API usage

Loki HTTP API usage

2022-04-29 15:31:36Forest lost ~ deer

Loki Http API Use

One 、 Query log stream

1. Query the log at a certain point in time

GET /loki/api/v1/query

Example :

http://192.168.15.139:30100/loki/api/v1/query?direction=BACKWARD&limit=1000&query=sum(rate({job="anychatlog"}[2d]))

Parameter description :

query: Executes LogQL Inquire about

limit: Maximum number of entries to return

time: The evaluation time of the query is taken as a nanosecond Unix An era . The default is now .

direction: Determine the sort order of logs . The value of support is forward or backward. The default is backward

2. Query the log of a certain time period

GET /loki/api/v1/query_range

Example :

http://192.168.15.139:30100/loki/api/v1/query_range?direction=BACKWARD&limit=1000&query={job="anychatlog"} &start=1641280408415000000&end=1641453208415000000&step=120

Parameter description :

query: Executes LogQL Inquire about

limit: Maximum number of entries to return

start: Start time of query , In nanoseconds Unix Era representation . The default is one hour ago .

end: End time of query , In nanoseconds Unix Era representation . The default is now .

step: With duration Format or floating-point seconds query resolution step .duration Means in the form of Of Prometheus Duration string [0-9]+[smhdwy]. for example ,5m Indicates that the duration is 5 minute . Default is based on start Dynamic values of and end. Only applicable to query types that generate matrix responses .

interval: This parameter is experimental ; Refer to the instructions under steps and intervals . Only return ( Or greater than ) Specify the entries for the interval , It can be duration Format or floating point number . Only applicable to queries that generate stream responses .

direction: Determine the sort order of logs . The value of support is forward or backward. The default is backward.

Two 、 Search tags

1. Query tag list

GET /loki/api/v1/labels

Parameters :

start: Start time of query , In nanoseconds Unix Era representation . The default is 6 Hours before .

end: End time of query , In nanoseconds Unix Era representation . The default is now .

Example :

 http://192.168.15.139:30100/loki/api/v1/labels

2. Query tag value

Query the list of known values of a given tag within a given time span

GET /api/prom/label/<name>/values

Parameters :

name: GET /loki/api/v1/label The label in

start: Start time of query , In nanoseconds Unix Era representation . The default is 6 Hours before .

end: End time of query , In nanoseconds Unix Era representation . The default is now .

Example :

http://192.168.15.139:30100/loki/api/v1/label/job/values

3、 ... and 、 Matches a list of specific tag sets

Returns a list of time series matching a specific tag set

GET /loki/api/v1/series

POST /loki/api/v1/series

Parameters :

match[]=<series_selector>: Select the label of the log stream to return .match[] At least one parameter must be provided .

start=: Start timestamp .

end=: End timestamp .

Example :

http://192.168.15.139:30100/loki/api/v1/series?start=1640922291907000000&end=1641527091908000000&match[]={host="192.168.11.123"}

Four 、 Delete log stream

explain : need 2.3.0 Previous versions of Loki, And configure it according to the official documents

1. Delete log stream

POST loki_addr/loki/api/admin/delete?match[]

Parameters :

match[]: Tag matcher , Used to identify the stream to be deleted from , At least one parameter must be provided

<series_selector>: Query parameters

start: Start time stamp

end: End timestamp

204 The response indicates success .

cURL Example forms of commands :

Example :

http://192.168.15.139:30100/loki/api/admin/delete?match[]={job="anychatlog"}

2. List delete requests

Use the following API List existing delete requests :

GET /loki/api/admin/delete

Example :

http://192.168.15.139:30100/loki/api/admin/delete

3. Cancel delete request

POST /loki/api/admin/cancel_delete_request

Example :

http://192.168.15.139:30100/loki/api/admin/cancel_delete_request?request_id=dad569a8

Four 、 Other commonly used API

GET /ready

When Loki When the ingestor is ready to receive flow , return HTTP 200. If in Kubernetes Up operation Loki/ready It can be used as a ready probe .

POST /flush

Flush all memory blocks held by the ingestor to the backup storage . Mainly used for local testing .

POST /ingester/flush_shutdown

Closing of the ingestor , Especially will Throughout Refresh any memory block it holds . This helps to narrow down and enable WAL Your ingestor , We want to make sure the old WAL Directories are not isolated , Instead, refresh to the back end of our block .

GET /metrics

Open Prometheus indicators . of Exported indicator list , see also loki

GET /config

/config Expose the current configuration . Optional mode Query parameters can be used to modify the output . If it has this value , be diff Only the difference between the default configuration and the current configuration is returned . value defaults Return to the default configuration

GET /loki/api/v1/status/buildinfo

stay JSON The object... Exposes information in the build . Fields including version,revision,branch,buildDate,buildUser, and goVersion.

5、 ... and 、Loki http Api Official statement

https://grafana.com/docs/loki/latest/api/

copyright notice
author[Forest lost ~ deer],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204291416313849.html

Random recommended