用Prometheus进行网络质量ping监控Grafana进行监控数据展示

简介

Prometheus

Prometheus 是一个开源的服务监控系统和时间序列数据库。作为容器领域的监控比较热门。
Prometheus 采用 PULL 拉的方式进行监控,如果不在一个网络中可以采用 Push gateway 作为中间件来被 PULL 拉。
架构图为

Prometheus 官方提供常用的 exporters 。
blackbox_exporter 是 Prometheus 官方提供的 exporter之一,可以提供 http、dns、tcp、icmp(ping)的监控数据采集。

Grafana

Grafana 是开源的,功能齐全的度量仪表盘和图形编辑器,支持 Graphite,OpenTSDB,Elasticsearch,Cloudwatch,Prometheus,InfluxDB,小米监控
等。

安装

分别安装grafana、prometheus、blackbox_exporter,安装文档参考官网。

配置

prometheus 配置和运行

在prometheus的配置文件 prometheus.yml 中增加一个新的job

  - job_name: 'ping_all'
    scrape_interval: 5s
    metrics_path: /probe
    params:
      module: [icmp]  #ping
    static_configs:
      - targets: ['219.150.32.132', '219.148.204.66', '183.59.4.178', '202.96.209.5', '202.100.4.15', '219.146.0.253', '222.173.113.3', '61.139.2.69', '61.128.114.133', '202.98.234.35', '202.100.64.68', '202.100.100.1', '221.232.129.35', '222.88.19.1', '222.190.127.1', '202.96.96.68', '202.101.103.54', '61.140.99.11', '202.96.161.1', '202.103.224.74']
        labels:
          group: '一线城市-电信网络监控'
      - targets: ['218.8.251.163', '218.107.51.1', '221.7.34.1', '112.65.244.1', '218.25.9.38', '124.89.76.214', '202.102.152.3', '202.102.128.68', '124.161.132.1', '221.7.1.20', '27.98.234.1', '218.104.111.122', '218.28.199.1', '221.6.4.66', '221.12.31.58', '218.104.136.149', '210.21.4.130', '210.21.196.6', '221.7.128.68', '221.199.15.5']
        labels:
          group: '一线城市-联通网络监控'
      - targets: ['211.137.241.34', '211.136.192.1', '218.203.160.194', '117.131.0.22', '211.137.32.178', '117.136.25.1', '211.137.191.26', '211.137.180.1', '211.137.106.1', '218.202.152.130', '211.139.73.34', '223.77.0.1', '211.138.16.1', '221.131.143.1', '211.140.10.2', '211.143.195.255', '183.238.55.1', '218.204.216.65', '211.138.245.180', '211.138.56.1']
        labels:
          group: '一线城市-移动网络监控'
      - targets: ['61.233.168.1', '61.234.113.1', '211.98.224.87', '222.44.44.1', '222.33.8.1', '61.232.201.76', '211.98.19.1', '61.232.49.1', '211.98.208.1', '61.233.199.129', '222.34.16.1', '61.232.206.1', '61.233.79.1', '211.98.43.1', '61.232.78.1', '61.232.93.193', '211.98.161.1', '61.235.99.1', '222.52.72.66', '211.138.56.1']
        labels:
          group: '一线城市-铁通网络监控'
      - targets: ['219.150.32.132', '219.153.32.1', '219.149.6.99', '220.189.218.45', '123.172.77.1', '202.103.124.34', '222.172.200.68', '202.100.64.68', '222.93.201.1', '222.191.255.1', '202.101.224.68', '222.85.179.1', '220.178.79.2', '59.49.12.97', '222.223.255.1', '219.148.172.97', '219.132.199.49', '14.120.0.1', '222.223.29.5', '222.173.222.1', '202.101.107.55', '222.74.58.29']
        labels:
          group: '二线城市-电信网络监控'
      - targets: ['60.24.4.1', '221.5.203.86', '202.96.86.18', '221.12.33.227', '202.99.96.68', '58.20.127.238', '221.3.131.11', '124.152.0.1', '221.3.131.11', '221.6.96.1', '220.248.192.13', '221.13.28.234', '211.91.88.129', '202.99.192.66', '202.99.160.68', '202.99.224.68', '58.252.65.1', '221.4.141.254', '60.2.17.49', '202.102.154.3', '36.249.127.25', '202.99.224.8']
        labels:
          group: '二线城市-联通网络监控'
      - targets: ['211.137.160.5', '218.201.17.2', '211.140.192.1', '211.140.35.1', '211.141.66.209', '211.138.225.2', '111.17.191.25', '218.203.160.195', '211.103.55.51', '211.103.114.1', '183.217.255.254', '211.139.2.18', '211.138.180.2', '211.142.12.2', '111.11.85.1', '211.138.91.2', '218.204.173.197', '183.233.223.25', '211.143.60.1', '120.192.167.2', '218.207.133.3', '120.193.138.1']
        labels:
          group: '二线城市-移动网络监控'
      - targets: ['61.234.70.2', '211.98.114.1', '61.232.157.1', '61.234.186.1', '61.235.225.1', '211.98.71.1', '211.98.72.7', '123.81.2.9', '211.98.44.65', '222.45.86.1', '222.49.82.1', '211.98.108.1', '222.48.116.17', '211.98.149.117', '61.235.145.1', '222.39.142.1', '110.211.253.9', '222.50.104.1', '61.234.76.1', '61.232.53.113', '61.234.196.185', '222.39.156.1']
        labels:
          group: '二线城市-铁通网络监控'
      - targets: ['166.111.8.28', '202.112.26.34', '202.114.240.6', '202.116.160.33', '211.65.207.170', '218.26.226.100', '222.221.252.162', '202.38.64.1', '202.201.48.1', '202.118.176.1', '121.193.138.1', '222.23.245.1', '58.195.136.3', '202.118.1.28', '59.77.229.1', '121.48.177.1', '121.250.214.1', '59.75.177.1', '59.75.112.254']
        labels:
          group: '教育网络监控'
    relabel_configs:
      - source_labels: [__address__]
        regex: (.*)(:80)?
        target_label: __param_target
        replacement: ${1}
      - source_labels: [__param_target]
        regex: (.*)
        target_label: ping
        replacement: ${1}
      - source_labels: []
        regex: .*
        target_label: __address__
        replacement: 127.0.0.1:9115  # Blackbox exporter.

顺序运行 blackbox_exporter,prometheus

grafana 配置和运行

运行grafana
在 grafana中增加 Data Sources 选 prometheus
然后按照grafana的文档新定制一个面板
ROW中指标选probe_duration_seconds{job=”ping_all”}

grafana prometheus ping监控

9 评论

  1. probe_duration_seconds这个指标是从哪里来的 是使用黑盒监控获取指标后自带的吗 我自己使用curl命令获取指标的结果里没发现有这个指标 但是在prometheus里可以看到这个指标

  2. 看了官网的doc也没发现,balackbox exporter是与prometheus部署在一起还是部署在被监控的服务器上? SNMP呢。也没看到相关的exporter之类,博主能帮忙说一下吗?

  3. 我的Prometheus里显示ping延迟值都是类似“0.00301955”,我仔细看了下,对应的应该是0.3ms,然后我在grafana里设置了ms,但显示出来的是和实际有差别,数值不对。不知道这两个地方应该怎么对应?

      1. 您好!非常感谢您的回复。我最近仔细看了下,在Prometheus查询里看到的ping value 和我在服务器上ping是有一些差别的,我不太确定Proemtheus数据库里的值是否是*1000刚好是Grafana里显示的Ping值,有没有地方可以确认?

        另外,我根据您说的设置Y坐标,单位选择seconds,数值还是不对,能否提供一个邮件地址?我把截图发您看看,谢谢!

  4. 您好!请问你这个Ping延迟怎么显示出来的?能否完整分享一下你的Grafana设置?
    谢谢!

    1. {
        "aliasColors": {},
        "bars": false,
        "datasource": "Prometheus1",
        "decimals": 3,
        "fill": 1,
        "id": 3,
        "legend": {
          "alignAsTable": true,
          "avg": true,
          "current": true,
          "hideEmpty": false,
          "hideZero": false,
          "max": true,
          "min": true,
          "rightSide": false,
          "show": true,
          "sort": "max",
          "sortDesc": true,
          "total": false,
          "values": true
        },
        "lines": true,
        "linewidth": 1,
        "links": [],
        "nullPointMode": "null",
        "percentage": false,
        "pointradius": 5,
        "points": false,
        "renderer": "flot",
        "seriesOverrides": [],
        "span": 12,
        "stack": false,
        "steppedLine": false,
        "targets": [
          {
            "expr": "probe_duration_seconds{job=\"ping_all\"}",
            "interval": "",
            "intervalFactor": 10,
            "legendFormat": "",
            "metric": "probe_duration_seconds",
            "refId": "A",
            "step": 10
          }
        ],
        "thresholds": [],
        "timeFrom": null,
        "timeShift": null,
        "title": "全国ping监控",
        "tooltip": {
          "shared": true,
          "sort": 2,
          "value_type": "cumulative",
          "msResolution": false
        },
        "type": "graph",
        "xaxis": {
          "mode": "time",
          "name": null,
          "show": true,
          "values": [
            "avg"
          ]
        },
        "yaxes": [
          {
            "format": "s",
            "label": "",
            "logBase": 1,
            "max": "0.5",
            "min": "0.01",
            "show": true
          },
          {
            "format": "s",
            "label": null,
            "logBase": 1,
            "max": null,
            "min": null,
            "show": true
          }
        ]
      }
      

回复 wwek 取消回复