Loki提供了HTTP接口,我们这里就不详解了,大家可以看:
https://github.com/grafana/loki/blob/master/docs/api.md
我们这里说下查询的接口如何使用:
第一步,获取当前Loki的元数据类型:
curl http://192.168.25.30:30972/api/prom/label
{
"values": ["alertmanager", "app", "component", "container_name", "controller_revision_hash", "deployment", "deploymentconfig", "docker_registry", "draft", "filename", "instance", "job", "logging_infra", "metrics_infra", "name", "namespace", "openshift_io_component", "pod_template_generation", "pod_template_hash", "project", "projectname", "prometheus", "provider", "release", "router", "servicename", "statefulset_kubernetes_io_pod_name", "stream", "tekton_dev_pipeline", "tekton_dev_pipelineRun", "tekton_dev_pipelineTask", "tekton_dev_task", "tekton_dev_taskRun", "type", "webconsole"]
}
第二步,获取某个元数据类型的值:
curl http://192.168.25.30:30972/api/prom/label/namespace/values
{"values":["cicd","default","gitlab","grafanaserver","jenkins","jx-staging","kube-system","loki","mysql-exporter","new2","openshift-console","openshift-infra","openshift-logging","openshift-monitoring","openshift-node","openshift-sdn","openshift-web-console","tekton-pipelines","test111"]}
第三步,根据label进行查询,例如:
http://192.168.25.30:30972/api/prom/query?direction=BACKWARD&limit=1000®exp=&query={namespace="cicd"}&start=1567644457221000000&end=1567730857221000000&refId=A
参数解析:
对于查询表达式的标签部分,将放在{}中,多个标签表达式用逗号分隔:
{app="mysql",name="mysql-backup"}
支持的符号有:
编写日志流选择器后,您可以通过编写搜索表达式进一步过滤结果。搜索表达式可以文本或正则表达式。
如:
支持多个过滤
目前支持的操作符:
表达式遵循https://github.com/google/re2/wiki/Syntax语法