prometheus 语法

本贴最后更新于 1256 天前,其中的信息可能已经时移世改

prometheus语法

如果prometheus正常启动,在防火墙开放了9090端口时,可以通过浏览器访问 http://机器ip:9090 直接访问

prometheus101401.png

在页面中“insert metric at cursor” 中选择查看的监控对象,如 node_cpu_seconds_total 然后点击 Execute 按钮

prometheus101402.png

再切换到 graph

prometheus101403.png

此时,我们已经看到了服务器cpu资源监控图

如果没有出现图,可能是因为时间跨度区间太长,可以点击 graph标签下面的 "- +"来调整图表时间区间,缩小区间,就能看到时间了。

设置标签匹配器

eg:

# 条件匹配
node_cpu_seconds_total{cpu="0", mode="system"}

# 点击 execute

点击 execute 按钮之后,graph中就只有1个图形线了。

逻辑符号除了上面用的 ‘=’ 还可以用

eg:

# 模糊匹配
node_cpu_seconds_total{cpu="0", mode=~"user|system|irq"}

# 点击 execute

点击 execute 按钮之后,graph中就会看到 3 条图形线。

eg:

# 精确匹配标签
{name="node_cpu_seconds_total"}

# 模糊匹配标签
{name=~"node_cpu.*"}

prometheus101404.png

但是,指标名称不能是关键词: bool、on、ignoring、group_left、group_right

# 标签名,不能是关键字

on{name=~"node_cpu.*"}  # 这个会报错

设置范围取值器

eg:

# 15分钟

irate(node_cpu_seconds_total{mode="user"}[15m])

时间偏移

# 偏移20分钟
node_cpu_seconds_total offset 20

msum(node_cpu_seconds_total{mode="user"} offset 5m)

重点函数

回帖
请输入回帖内容 ...