第1章 部署blackbox_exporter

1.1下载地址:

https://github.com/prometheus/blackbox_exporter

1.2解压后修改blackbox.yml配置文件

modules:

  http_2xx:

    prober: http

    http:     #下面两个参数要加上,表示支持http版本和http状态码的监控

     valid_http_versions: ["HTTP/1.1", "HTTP/2"]

     valid_status_codes: [200]

      method: GET

      preferred_ip_protocol: "ip4"

 http_post_2xx:

    prober: http

    http:

      method: POST

     preferred_ip_protocol: "ip4"

 tcp_connect:

    prober: tcp

 pop3s_banner:

    prober: tcp

    tcp:

     query_response:

      - expect: "^+OK"

      tls: true

     tls_config:

       insecure_skip_verify: false

  ssh_banner:

    prober: tcp

    tcp:

     query_response:

      - expect: "^SSH-2.0-"

  irc_banner:

    prober: tcp

    tcp:

     query_response:

      - send: "NICK prober"

      - send: "USER prober prober prober :prober"

      - expect: "PING :([^ ]+)"

        send: "PONG ${1}"

      - expect: "^:[^ ]+ 001"

  icmp:

prober: icmp

1.3启动命令:

./blackbox_exporter --config.file=./blackbox.yml

第2章 修改promethus主配文件:

  - job_name: 'http-status-test'

    scrape_interval: 30s #每次获取数据的时间间隔

   metrics_path: /probe

    params:

      module: [http_2xx]

   static_configs:

      - targets:

        - http://jiang.test.com

        - http://www.baidu.com

   relabel_configs:

      - source_labels: [__address__]

       target_label: __param_target

      - source_labels: [__param_target]

       target_label: instance

      - target_label: __address__

       replacement: 10.133.201.127:9115

2.1promethusUI界面上查看监控数据

第3章 部署rabbitmq_exporter

3.1下载rabbitmq_exporter

wget https://github.com/kbudde/rabbitmq_exporter/releases/download/v0.29.0/rabbitmq_exporter-0.29.0.linux-amd64.tar.gz

3.2解压

tar xf rabbitmq_exporter-0.29.0.linux-amd64.tar.gz

3.3运行rabbitmq时需要加上几个环境变量

PUBLISH_PORT=9990 RABBIT_URL="http://localhost:15672" RABBIT_CAPABILITIES="no_sort,bert" ./rabbitmq_exporter

3.4出现一下信息证明promethus连接rabbitmq_exporter正常

INFO[0000] Using default certificate pool

INFO[0000] Starting RabbitMQ exporter                    BRANCH=heads/v0.29.0 BUILD_DATE="20180823-19:06:05" REVISION=fc78ab0a47bc6557e1b8a218b0b0c307aa7946ea VERSION=0.29.0

INFO[0000] Active Configuration                          CAFILE=ca.pem INCLUDE_QUEUES=".*" INCLUDE_VHOST=".*" MAX_QUEUES=0 OUTPUT_FORMAT=TTY PUBLISH_ADDR= PUBLISH_PORT=9990 RABBIT_CAPABILITIES="bert,no_sort" RABBIT_EXPORTERS="[exchange node overview queue]" RABBIT_TIMEOUT=30 RABBIT_URL="http://localhost:15672" RABBIT_USER=guest SKIPVERIFY=false SKIP_QUEUES="^$" SKIP_VHOST="^$"

INFO[0001] Metrics updated                              duration=9.21538ms

INFO[0011] Metrics updated                              duration=17.240458ms

3.5rabbitmq_exporter注册到consul

curl -H "Content-Type: application/json" -XPUT http://10.133.201.127:8500/v1/agent/service/register -d '{"ID":"rabbitmq_exporter_1","Name": "rabbitmq_exporter","Tags": ["rabbitmq_export"],"Address": "10.3.2.15","Port": 9419,"EnableTagOverride": false,"Check": {"Name": "rabbitmq_export on port 9419","TCP":"10.3.2.15:9419","Interval": "10s","Timeout": "1s"}}'

3.6登录到rabbitmq上添加队列测试监控数据是否正常

3.7web页面查看监控数据