prometheus 向量匹配

1、一对一

process_open_fds{job="canal-exporter"}
process_open_fds{agent_id="agent-bfey9gbj", instance="10.8.42.145:11112", job="canal-exporter"}
process_open_fds{agent_id="agent-bfey9gbj", instance="10.8.42.64:11112", job="canal-exporter"}
process_open_fds{agent_id="agent-bfey9gbj", instance="10.8.42.78:11112", job="canal-exporter"}

process_max_fds{job="canal-exporter"}
process_max_fds{agent_id="agent-bfey9gbj", instance="10.8.42.145:11112", job="canal-exporter"}
process_max_fds{agent_id="agent-bfey9gbj", instance="10.8.42.64:11112", job="canal-exporter"}
process_max_fds{agent_id="agent-bfey9gbj", instance="10.8.42.78:11112", job="canal-exporter"}


process_open_fds{job="canal-exporter"} / process_max_fds{job="canal-exporter"}

===========
sum without(cpu)(rate(node_cpu_seconds_total{instance="api-1:9100",mode="idle"}[5m]))
{agent_id="agent-bfey9gbj", instance="api-1:9100", job="node_exporter_full", mode="idle"}


sum without(mode,cpu)(rate(node_cpu_seconds_total{instance="api-1:9100"}[5m]))
{agent_id="agent-bfey9gbj", instance="api-1:9100", job="node_exporter_full"}


sum without(cpu)(rate(node_cpu_seconds_total{instance="api-1:9100",mode="idle"}[5m])) / ignoring(mode) sum without(mode,cpu)(rate(node_cpu_seconds_total{instance="api-1:9100"}[5m]))
sum without(cpu)(rate(node_cpu_seconds_total{instance="api-1:9100",mode="idle"}[5m])) / on(agent_id,instance,job) sum without(mode,cpu)(rate(node_cpu_seconds_total{instance="api-1:9100"}[5m]))

 

2、多对一

sum without(cpu)(rate(node_cpu_seconds_total{instance="api-1:9100"}[5m]))
{agent_id="agent-bfey9gbj", instance="api-1:9100", job="node_exporter_full", mode="idle"}
{agent_id="agent-bfey9gbj", instance="api-1:9100", job="node_exporter_full", mode="iowait"}
{agent_id="agent-bfey9gbj", instance="api-1:9100", job="node_exporter_full", mode="irq"}
{agent_id="agent-bfey9gbj", instance="api-1:9100", job="node_exporter_full", mode="nice"}
{agent_id="agent-bfey9gbj", instance="api-1:9100", job="node_exporter_full", mode="softirq"}
{agent_id="agent-bfey9gbj", instance="api-1:9100", job="node_exporter_full", mode="steal"}
{agent_id="agent-bfey9gbj", instance="api-1:9100", job="node_exporter_full", mode="system"}
{agent_id="agent-bfey9gbj", instance="api-1:9100", job="node_exporter_full", mode="user"}

sum without(mode,cpu)(rate(node_cpu_seconds_total{instance="api-1:9100"}[5m]))
{agent_id="agent-bfey9gbj", instance="api-1:9100", job="node_exporter_full"}


sum without(cpu)(rate(node_cpu_seconds_total{instance="api-1:9100"}[5m]))/ ignoring(mode) group_left sum without(mode,cpu)(rate(node_cpu_seconds_total{instance="api-1:9100"}[5m]))


group_left还有另一种用途,将信息指标中的标签添加到一个目标的其他指标中
up
up{agent_id="agent-bfey9gbj", group="tcp", instance="10.8.42.19:8000", job="prometheus_port_status"}
up{agent_id="agent-bfey9gbj", instance="10.8.42.145:11112", job="canal-exporter"}
up{agent_id="agent-bfey9gbj", instance="10.8.42.64:11112", job="canal-exporter"}
up{agent_id="agent-bfey9gbj", instance="10.8.42.78:11112", job="canal-exporter"}
up{agent_id="agent-bfey9gbj", instance="127.0.0.1:9090", job="prometheus-agent"}
up{agent_id="agent-bfey9gbj", instance="api-1:8081", job="php-fpm2"}
up{agent_id="agent-bfey9gbj", instance="api-1:9100", job="node_exporter_full"}
up{agent_id="agent-bfey9gbj", instance="api-1:9113", job="nginx-exporter"}
up{agent_id="agent-bfey9gbj", instance="api-2:8081", job="php-fpm2"}
up{agent_id="agent-bfey9gbj", instance="api-2:9100", job="node_exporter_full"}
up{agent_id="agent-bfey9gbj", instance="api-2:9113", job="nginx-exporter"}
up{agent_id="agent-bfey9gbj", instance="api-3:8081", job="php-fpm2"}
up{agent_id="agent-bfey9gbj", instance="api-3:9100", job="node_exporter_full"}
up{agent_id="agent-bfey9gbj", instance="api-3:9113", job="nginx-exporter"}
up{agent_id="agent-bfey9gbj", instance="api-4:8081", job="php-fpm2"}
up{agent_id="agent-bfey9gbj", instance="api-4:9100", job="node_exporter_full"}
up{agent_id="agent-bfey9gbj", instance="api-4:9113", job="nginx-exporter"}
up{agent_id="agent-bfey9gbj", instance="api-5:8081", job="php-fpm2"}
up{agent_id="agent-bfey9gbj", instance="api-5:9100", job="node_exporter_full"}
up{agent_id="agent-bfey9gbj", instance="api-5:9113", job="nginx-exporter"}
。。。


prometheus_build_info
prometheus_build_info{agent_id="agent-bfey9gbj", branch="prometheus-agent", goversion="go1.14.13", instance="127.0.0.1:9090", job="prometheus-agent", revision="2edef6b7a31978643ae41e54f21eeabf667f1eaf", version="2.19.0"}
prometheus_build_info{branch="prometheus-agent", cluster_id="cls-iqsypsqd", cluster_version="v1.18.4-tke.3", endpoint="web", goversion="go1.14.13", instance="172.16.2.178:9090", job="prometheus-agent", namespace="cm-prometheus", pod="prometheus-rig-prometheus-agent-0", prometheus_replica="prometheus-rig-prometheus-agent-0", revision="2edef6b7a31978643ae41e54f21eeabf667f1eaf", service="rig-prometheus-agent", version="2.19.0"}

up * on(instance) group_left(version) prometheus_build_info
{agent_id="agent-bfey9gbj", instance="127.0.0.1:9090", job="prometheus-agent", version="2.19.0"}
{cluster_id="cls-iqsypsqd", cluster_version="v1.18.4-tke.3", endpoint="web", instance="172.16.2.178:9090", job="prometheus-agent", namespace="cm-prometheus", pod="prometheus-rig-prometheus-agent-0", prometheus_replica="prometheus-rig-prometheus-agent-0", service="rig-prometheus-agent", version="2.19.0"}


当group_left(version)被请求的时候,version标签从右侧操作数复制到了左侧操作数,此外还返回了左侧操作数中的所有标签。

ignoring 所忽略的标签不在乎是左侧还是右侧,而on是匹配的左侧和右侧都有的标签


group_right 和 group_left工作原理是一样的

 

 

3、多对多
所有的逻辑运算符都以多对多的方式工作,他们是唯一可以多对多运算的运算符。
or操作符,每组左侧的组都有样本,然后返回他们,否则返回右侧组中的样本。

and操作符,与unless相反,仅当匹配的右侧组有样本时,他才从左侧的操作数返回一个组;否则,他不返回该匹配组的样本。

unless操作符,根据右和左操作数中的组是否为空进行判断。除非右侧组有成员,否则unless运算符返回左侧组。
例如:你想知道除了使用少于100MB驻留内存进程以外的其他进程平均cpu使用率:
rate(process_cpu_seconds_total[5m])
unless
process_resident_memory_bytes < 100 * 1024 * 1024
计算平均cpu使用率的都是驻留内存大于100mb的

posted @ 2022-08-30 23:30  JvvYou  阅读(110)  评论(0编辑  收藏  举报