• 【夜莺监控方案】09-监控服务主机存活和服务端口(ICMP/TCP/HTTP)(prometheuse+n9e+blackbox_exporter)


    1. 安装 blackbox_exporter

    • 创建 /opt/ blackbox_exporter目录
    • /opt/ blackbox_exporter目录下创建docker-compose.yml文件如下:
    version: '3.3'
    services:
      blackbox_exporter:
        image: bitnami/blackbox-exporter
        container_name: blackbox_exporter
        #network_mode: "host"
        ports:
          - 9115:9115
        restart: always
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 启动服务
    docker-compose up -d
    
    • 1
    • 查看启动结果
          Name                     Command               State   Ports
    ------------------------------------------------------------------
    blackbox_exporter   /opt/bitnami/blackbox-expo ...   Up     0.0.0.0:9115->9115/tcp
    
    • 1
    • 2
    • 3
    • 验证
      访问 http://IP:9115 看到数据说明启动成功

    2. 配置prometheus

    • 配置prometheus.yml,添加项目如下:

    2.1 主机存活(ICMP)

    ##########################################
    #             [black-box]                #
    ##########################################
    ################## liubei ############################
      - job_name: icmp_hq_node
        metrics_path: /probe
        params:
           module: [icmp]
        static_configs:
          - targets: ['10.xxx.xxx.65','10.xxx.xxx.66','10.xxx.xxx.67','10.xxx.xxx.68','10.xxx.xxx.69','10.xxx.xxx.70','10.xxx.xxx.71','10.1.30.72']
            labels:
              group: 'node'
              project: 'HQ-AllInOne-PC'
        relabel_configs:
          - source_labels: [__address__]
            target_label: __param_target
          - source_labels: [__param_target]
            target_label: instance
          - target_label: __address__
            replacement: 10.10.xxx.64:9115
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    2.2 TCP端口状态

    ############### liubei ########################
      - job_name: 'port_hq_emqx'
        metrics_path: /probe
        params:
          module: [tcp_connect]
        static_configs:
          - targets: ['10.xxx.xxx.65:1883','10.xxx.xxx.65:18083','10.xxx.xxx.66:1883','10.xxx.xxx.66:18083','10.xxx.xxx.67:1883','10.xxx.xxx.67:18083','10.xxx.xxx.68:1883','10.xxx.xxx.69:1883']
            labels:
              group: 'tcp'
              project: 'HQ-AllInOne-PC'
        relabel_configs:
          - source_labels: [__address__]
            target_label: __param_target
          - source_labels: [__param_target]
            target_label: instance
          - target_label: __address__
            replacement: 10.10.xxx.64:9115
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    2.3 HTTP端口状态

    ############### liubei ########################
      - job_name: 'http_hq_iot'
        metrics_path: /probe
        params:
          module: [http_2xx]
        static_configs:
          - targets: ['10.xxx.xxx.70:8000','10.xxx.xxx.70:8080','10.xxx.xxx.71:8000','10.xxx.xxx.71:8080','10.xxx.xxx.72:8888']
            labels:
              group: 'http'
              project: 'HQ-AllInOne-PC'
        relabel_configs:
          - source_labels: [__address__]
            target_label: __param_target
          - source_labels: [__param_target]
            target_label: instance
          - target_label: __address__
            replacement: 10.10.xxx.64:9115
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    2.4 重启 prometheus

    3. 配置n9e图表

    3.1 手动配置(方法一)

    参考《04-监控redis集群-prometheuse+n9e》中“3.2 配置图表"

    指标可以访问 http://IP:9115自己找

    
    
    • 1

    3.2 导入模板(方法二)

    >选择 “监控看图”--> “监控”
    我写的模板内容如下:

    [
      {
        "id": 0,
        "name": "端口和主机存活",
        "tags": "",
        "configs": "{\"tags\":[{\"tagName\":\"job\",\"key\":\"job\",\"value\":\"*\",\"prefix\":false,\"metric\":\"probe_success\"},{\"tagName\":\"project\",\"key\":\"project\",\"value\":\"HQ-AllInOne-PC\",\"prefix\":false,\"metric\":\"probe_success\"}]}",
        "chart_groups": [
          {
            "id": 0,
            "dashboard_id": 0,
            "name": "Default chart group",
            "weight": 0,
            "charts": [
              {
                "id": 538,
                "group_id": 156,
                "configs": "{\"name\":\"端口是否存活\",\"mode\":\"nightingale\",\"metric\":[\"probe_success\"],\"tags\":{\"group\":[\"http\",\"tcp\"]},\"layout\":{\"h\":2,\"w\":24,\"x\":0,\"y\":0,\"i\":\"0\"}}",
                "weight": 0
              },
              {
                "id": 539,
                "group_id": 156,
                "configs": "{\"name\":\"嗅探花费时间(秒)\",\"mode\":\"nightingale\",\"metric\":[\"probe_dns_lookup_time_seconds\"],\"tags\":{},\"layout\":{\"h\":2,\"w\":24,\"x\":0,\"y\":4,\"i\":\"1\"}}",
                "weight": 0
              },
              {
                "id": 540,
                "group_id": 156,
                "configs": "{\"name\":\"主机存活\",\"mode\":\"nightingale\",\"metric\":[\"probe_success\"],\"tags\":{\"group\":[\"node\"]},\"layout\":{\"h\":2,\"w\":24,\"x\":0,\"y\":2,\"i\":\"2\"}}",
                "weight": 0
              }
            ]
          }
        ]
      }
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

  • 相关阅读:
    ambari搭建HDP集群后修改存储元数据的mysql数据库配置
    java获取文件编码方式
    Python如何使用HanNLP工具
    5种在TypeScript中使用的类型保护
    VS Code Java 2 月更新!教育特别版:单元测试、GUI开发支持、Gradle项目创建、以及更多!
    数据好合: Argilla 和 Hugging Face Spaces 携手赋能社区合力构建更好的数据集
    prototype 原型对象
    【数据仓库设计基础1】关系数据模型理论与数据仓库Inmon方法论
    (多级缓存)多级缓存
    echarts 实现tooltip提示框样式自定义
  • 原文地址:https://blog.csdn.net/xingzuo_1840/article/details/126155635