On this page
18 Prometheus 数据处理
概述
Zabbix可以查询Prometheus行格式标准的度量数据。
收集 Prometheus 数据需要如下两步:
- 一个主 HTTP 监控项数据端点
, 例如:
https://<prometheus host>/metrics - 一个预处理配置,
预定步骤为 Prometheus 选项的依赖监控项,用于从主HTTP监控项收集的度量中查询所需数据。
有两个 Prometheus 预处理的预定步骤配置选项:
- Prometheus 正则 - 用于普通监控项中查询Prometheus 数据
- Prometheus 转 JSON - 用于普通监控项及低级发现中. 在这种情况下,将返回 JSON 格式的 Prometheus 数据.
配置
如果您配置了HTTP主监控项, 你需要创建一个使用 Prometheus
预定步骤配置的依赖监控项,配置步骤如下:
- 点击监控项配置表单的类型(Type),选择相关项目(Dependent item)并配置主监控项
- 切换到预处理(Preprocessing)选项页
- 选择一个 Prometheus 预定步骤(Preprocessing steps),选择 Prometheus 正则 或 Prometheus 转 JSON

| 参数 描 | 样例 | |
|---|---|---|
| Pattern | 要定义所需的数据的正则规则,可以使用类似于Prometheus查询语言的语法规则 (参见对照表), 例如.:\ wmi_os_physical_memory_free_by<metric name> - 被选定的 metric 名称\ cpu {__name__="<metric name>"} - 被选定的 metric 名称\ cpu {__name__=\~"<regex>"} - 匹配被选定 metric 名称的正则表达式\ cpu_usage {<label name>="<label value>",...} - 被选定的 label 名称\ wmi {<label name>=\~"<regex>",...} - 匹配被选定 label 名称的正则表达式\ wmi_os_ti{__name__=\~".*"}==<value> - 被选定的 metric 值 或以上两者的结合: <metric name>{<label1 name>="<label1 value>",<label2 name>=\~"<regex>",...}==<value> Label 值可以是UTF-8字符的任意序列,但反斜杠、双引号和换行符必须转义为 \\, \" 和 \n ; 其他字符不必转义 。 |
es usage_system{cpu="cpu-total"} usage_system{cpu=\~".*"} system{cpu="cpu-total",host=\~".*"} service_state{name="dhcp"}==1 ezone{timezone=\~".*"}==1 |
| Output | 定义 Label 名称(可选)。在这种情况下,将返回与 Label名称对应的值。 此字段仅适用于 Prometheus 正则 选项。 |
|
Prometheus 转 JSON
可以使用低级(low-level)发现处理Prometheus数据,此时需要配置预处理步骤 选项为 Prometheus 转 JSON 将Prometheus数据转换为JSON格式数据。
详细参见 使用 Prometheus 数据发现.
查询语法对照表
下表列出了PromQL和Zabbix Prometheus预处理查询语法之间的差异。
| PromQL 语法 Z | bbix Prometheus 预处理语法 | |
|---|---|---|
| 差异 | ||
| 查询目标 Pro | etheus 服务器 Promet | eus 格式的纯文本 |
| 返回 瞬 | 向量(Instant vector) Metri | 或 label 值 (Prometheus 正则) 每条度量数据的 JSON 列表(Prometheus 转 JSON) |
| Label 匹配运算符 *= | , !=, =\~, !\~ *= | , =\~ |
| Label 或 Metric 名称匹配的Regular 表达式 RE2 | PCRE | |
| 比较运算符 参见 [ | 表](https://prometheus.io/docs/prometheus/latest/querying/operators/#comparison-binary-operators) 只有 *== | (等于) 支持值过滤 |
| 相似 | ||
| 按 metric 名称等于字符串进行选定 <metric | ame> or {__name__="<metric name>"} <metric | ame> or {__name__="<metric name>"} |
| 按 metric 名称匹配正则表达式进行选定 {__name__ | \~"<regex>"} {__name__ | \~"<regex>"} |
| 按<label name>的值等于字符串进行选定 {<label | ame>="<label value>",...} {<label | ame>="<label value>",...} |
| 按<label name>的值匹配正则表达式进行选定 {<label na | e>=\~"<regex>",...} {<label na | e>=\~"<regex>",...} |
| 按值等于字符串进行选定 {__name |
_=\~".*"} == <value> {__name |
_=\~".*"} == <value> |