12 使用Prometheus数据发现

概述

Prometheus提供的数据格式可以低级别发现使用

查看Prometheus检查的详细数据是如何在Zabbix中实现的。

配置

低级发现规则应该作为监控项依赖创建到Prometheus数据的HTTP监控项中。

Prometheus转JSON

在发现规则中,进入Preprocessing选项卡,并选择Prometheus to JSON Preprocessing选项。发现需要JSON格式的数据,而Prometheus to JSON预处理选项将会返回正确的数据,包含以下属性:

  • metric name

  • metric value

  • help (if present)

  • type (if present)

  • labels (if present)

  • raw line

例如,查询 wmi_logical_disk_free_bytes:

12 使用Prometheus数据发现 - 图1

从Prometheus获取数据:

  1. # HELP wmi_logical_disk_free_bytes Free space in bytes (LogicalDisk.PercentFreeSpace)
  2. # TYPE wmi_logical_disk_free_bytes gauge
  3. wmi_logical_disk_free_bytes{volume="C:"} 3.5180249088e+11
  4. wmi_logical_disk_free_bytes{volume="D:"} 2.627731456e+09
  5. wmi_logical_disk_free_bytes{volume="HarddiskVolume4"} 4.59276288e+08

返回:

  1. [
  2. {
  3. "name": "wmi_logical_disk_free_bytes",
  4. "help": "Free space in bytes (LogicalDisk.PercentFreeSpace)",
  5. "type": "gauge",
  6. "labels": {
  7. "volume": "C:"
  8. },
  9. "value": "3.5180249088e+11",
  10. "line_raw": "wmi_logical_disk_free_bytes{volume=\"C:\"} 3.5180249088e+11"
  11. },
  12. {
  13. "name": "wmi_logical_disk_free_bytes",
  14. "help": "Free space in bytes (LogicalDisk.PercentFreeSpace)",
  15. "type": "gauge",
  16. "labels": {
  17. "volume": "D:"
  18. },
  19. "value": "2.627731456e+09",
  20. "line_raw": "wmi_logical_disk_free_bytes{volume=\"D:\"} 2.627731456e+09"
  21. },
  22. {
  23. "name": "wmi_logical_disk_free_bytes",
  24. "help": "Free space in bytes (LogicalDisk.PercentFreeSpace)",
  25. "type": "gauge",
  26. "labels": {
  27. "volume": "HarddiskVolume4"
  28. },
  29. "value": "4.59276288e+08",
  30. "line_raw": "wmi_logical_disk_free_bytes{volume=\"HarddiskVolume4\"} 4.59276288e+08"
  31. }
  32. ]
映射LLD宏

接下来,你必须进入LLD宏标签,并创建以下映射:

  1. {#VOLUME}=$.labels['volume']
  2. {#METRIC}=$['name']
  3. {#HELP}=$['help']
监控项原型

你可能想要这样创建一个监控项原型:

12 使用Prometheus数据发现 - 图2

与预处理选项:

12 使用Prometheus数据发现 - 图3