13 利用Prometheus数据执行自动发现
概述
Prometheus中的数据格式适用于低级别自动发现。
关于Zabbix如何执行Prometheus数据的查询,请参考 Prometheus检查。
配置
利用低级别自动发现规则创建一个 依赖型监控项 ,附属于采集Prometheus数据的HTTP主监控项。
Prometheus to JSON
在自动发现规则中, 找到预处理选项, 然后选择 Prometheus to JSON 这个预处理选项. 自动发现需要使用JSON格式的数据, Prometheus to JSON 这个选项会返回所需的JSON格式, 并附带下列属性:
- 指标名称
- 指标值
- 帮助 (如果有)
- 类型(如果有)
- 标签(如果有)
- 原始行
例如, 需要查询 wmi_logical_disk_free_bytes
:
从这些Prometheus的行中执行上述查询:
# HELP wmi_logical_disk_free_bytes Free space in bytes (LogicalDisk.PercentFreeSpace)
# TYPE wmi_logical_disk_free_bytes gauge
wmi_logical_disk_free_bytes{volume="C:"} 3.5180249088e+11
wmi_logical_disk_free_bytes{volume="D:"} 2.627731456e+09
wmi_logical_disk_free_bytes{volume="HarddiskVolume4"} 4.59276288e+08
会返回:
[
{
"name": "wmi_logical_disk_free_bytes",
"help": "Free space in bytes (LogicalDisk.PercentFreeSpace)",
"type": "gauge",
"labels": {
"volume": "C:"
},
"value": "3.5180249088e+11",
"line_raw": "wmi_logical_disk_free_bytes{volume=\"C:\"} 3.5180249088e+11"
},
{
"name": "wmi_logical_disk_free_bytes",
"help": "Free space in bytes (LogicalDisk.PercentFreeSpace)",
"type": "gauge",
"labels": {
"volume": "D:"
},
"value": "2.627731456e+09",
"line_raw": "wmi_logical_disk_free_bytes{volume=\"D:\"} 2.627731456e+09"
},
{
"name": "wmi_logical_disk_free_bytes",
"help": "Free space in bytes (LogicalDisk.PercentFreeSpace)",
"type": "gauge",
"labels": {
"volume": "HarddiskVolume4"
},
"value": "4.59276288e+08",
"line_raw": "wmi_logical_disk_free_bytes{volume=\"HarddiskVolume4\"} 4.59276288e+08"
}
]
映射LLD宏
接下来需要找到LLD宏的选项并做下面的映射:
{#VOLUME}=$.labels['volume']
{#METRIC}=$['name']
{#HELP}=$['help']
监控项原型
可以创建这样的监控项原型:
并配置预处理选项: