首页  

prometheus 查询例子     所属分类 prometheus 浏览量 119
https://prometheus.io/docs/prometheus/latest/querying/examples/

PromQL (Prometheus Query Language) 

Return all time series with the metric http_requests_total:
http_requests_total

根据标签过滤
http_requests_total{job="apiserver", handler="/api/comments"}


Return a whole range of time (in this case 5 minutes) for the same vector, making it a range vector
http_requests_total{job="apiserver", handler="/api/comments"}[5m]

Note that an expression resulting in a range vector cannot be graphed directly, but viewed in the tabular ("Console") view of the expression browser.

不能直接绘图 ,但是可以在 console里查看数据

使用正则表达式 过滤
http_requests_total{job=~".*server"}
all jobs that end with server
. 任意字符
.* 匹配 0到多个任意字符


select all HTTP status codes except 4xx ones
http_requests_total{status!~"4.."}

RE2 syntax
https://github.com/google/re2/wiki/Syntax

Subquery  子查询
Return the 5-minute rate of the http_requests_total metric for the past 30 minutes, with a resolution of 1 minute.
rate(http_requests_total[5m])[30m:1m]

rate(total_pv[5m])[30m:1m]
执行报错
Error executing query: parse error at char 19: range specification must be preceded by a metric selector, but follows a *promql.Call instead


使用函数

Return the per-second rate for all time series with the http_requests_total metric name, as measured over the last 5 minutes:
rate(http_requests_total[5m])
rate(total_pv[5m])
increase(total_pv[5m])

根据时间窗口聚合计算

node_filesystem_avail_bytes

node_filesystem_avail_bytes{device="tmpfs",fstype="tmpfs",instance="localhost:9100",job="node_exporter",mountpoint="/run/user/0"}
node_filesystem_avail_bytes{device="tmpfs",fstype="tmpfs",instance="localhost:9100",job="node_exporter",mountpoint="/run"}
node_filesystem_avail_bytes{device="rootfs",fstype="rootfs",instance="localhost:9100",job="node_exporter",mountpoint="/"}
node_filesystem_avail_bytes{device="/dev/vda1",fstype="ext3",instance="localhost:9100",job="node_exporter",mountpoint="/"}

sum(node_filesystem_avail_bytes)

sum by (device) (node_filesystem_avail_bytes)
{device="tmpfs"}
{device="rootfs"}
{device="/dev/vda1"}

sum by (device)  保留 device 标签

类似 sql  中的 group by 

count  (node_filesystem_avail_bytes)
4

topk(1, count by (device) (node_filesystem_avail_bytes) )


topk(2, sum by (device) (node_filesystem_avail_bytes))

topk(1, sum by (device) (node_filesystem_avail_bytes))

上一篇     下一篇
prometheus中的时间序列数据

grafana数据接口

grafana 日PV 柱状图

springboot ApplicationContextInitializer 使用

日志框架冲突及解决方法

linux熵池太小导致随机函数阻塞