LoginSignup
15
15

More than 5 years have passed since last update.

Prometheusのすすめ - blackbox_exporterで死活監視をしよう -

Last updated at Posted at 2018-07-24

blackbox exporterとは何か。

今までのexpoterは監視対象のサーバに導入してPrometheusサーバからPullしてメトリクスを取得していました。
この場合ICMP(ping)監視や、URL監視についてはどうあがいても出来ません。
それを解決してくれるのが「blackbox exporter」になります。

外形監視をしてくれるexpoterなので、Prometheusサーバに導入して動かします。(別サーバでも大丈夫です)

公式 - Download
GitHub - prometheus/blackbox_exporter

導入(ansible)

node_exporterもansibleを使って導入してサービス登録までしたので、それを基にymlを作成します。

blackbox-exporter.yml
---
- hosts: samplehost
  user: sampleuser
  sudo: yes
  tasks:
  - name: check exist file
    stat:
      path: /usr/bin/blackbox_exporter
    register: file
  - name: wget blackbox_exporter
    get_url:
      url: https://github.com/prometheus/blackbox_exporter/releases/download/v0.12.0/blackbox_exporter-0.12.0.linux-amd64.tar.gz
      dest: /tmp/blackbox_exporter-0.12.0.linux-amd64.tar.gz
  - name: unarchive blackbox-exporter
    unarchive:
      src: /tmp/blackbox_exporter-0.12.0.linux-amd64.tar.gz
      remote_src: yes
      dest: /tmp/
  - name: copy exporter binary
    shell: cp /tmp/blackbox_exporter-0.12.0.linux-amd64/blackbox_exporter /usr/bin/blackbox_exporter
    when: not file.stat.exists

  - name: add system account prometheus
    user:
      system: yes
      name: prometheus
      state: present
      home: /var/lib/prometheus
      shell: /bin/false
      comment: Prometheus daemon
  - name: create prometheus home directory
    file:
      state: directory
      path: /var/lib/prometheus
      mode: 0755
      group: prometheus
      owner: prometheus
  - name: create blackbox_exporter systemd
    blockinfile:
      path: /etc/systemd/system/blackbox_exporter.service
      create: yes
      block: |
        [Unit]
        Description=black_exporter for Prometheus

        [Service]
        Restart=always
        User=prometheus
        ExecStart=/usr/bin/blackbox_exporter \
            --web.listen-address=0.0.0.0:9115 \
            --config.file=/usr/local/blackbox_exporter/blackbox.yml
        ExecReload=/bin/kill -HUP $MAINPID
        TimeoutStopSec=20s
        SendSIGKILL=no

        [Install]
        WantedBy=multi-user.target
  - name: add blackbox_exporter systemd
    systemd:
      name: blackbox_exporter.service
      enabled: yes
      state: started
  - name: setup icmp
    shell: setcap cap_net_raw+ep /usr/local/blackbox_exporter/blackbox_exporter

blackbox_exporter設定

デフォルトで以下の様になっていました。まだ調べていないのでとりあえずデフォルトのままにしておきます。

blackbox.yml
modules:
  http_2xx:
    prober: http
    http:
  http_post_2xx:
    prober: http
    http:
      method: POST
  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

Prometheus側の設定

どこに対してどのプロトコルで、という設定はscrape_configsに記載するみたいです。
PrometheusとBlackbox Exporterでサーバ死活監視
内容は上記を パクリ 参考にしました。(有難うございます!)

まあまあ、カスタムするのはどんなもんか確認してからです。

ICMPを使う場合の設定

file_sdで管理した方が良さそうです。

prometheus.yml(抜粋)
scrape_configs:
  - job_name: "Blackbox_ICMP"
    metrics_path: /probe
    params:
      module: [icmp]
    file_sd_configs:
      - files:
        - /usr/local/prometheus-2.3.1/filesd/ICMP.yml
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115 # blackbox_exporterのIP:Port(今回はPrometheusサーバ自身なので127.0.0.1)

/usr/local/prometheus-2.3.1/filesd/ICMP.yml
- targets:
    - XXXXX01
    - XXXXXXX01
  labels:
    project: XXXXXT
- targets:
    - 13.XXX.XXX.234
  labels:
    instance: XX-XXXXX18
    project: XXXXXXXXAI

確認

設定が終わったらサービスを再起動して、とりあえずTargetsに出ているか確認。

blackbox01.PNG

targetsが複数だとどうなるのか確認。
blackbox01.PNG

アラート設定しておく。
alert.PNG









以上!

Prometheus 過去記事
Prometheusのすすめ - 初期導入 -
Prometheusのすすめ - Service Discovery -
Prometheusのすすめ - exporter導入 node-exporter(apt-get) -
Prometheusのすすめ - exporter導入 node-exporter(バイナリ) -
Prometheusのすすめ - Service Discovery - EndPointが「http://:9100/metrics」になって、自分自身になってしまう件
Prometheusのすすめ - Grafanaで監視対象のユーザ一覧が欲しい -
Prometheusのすすめ - Grafana で AlertをTeamsに通知するのは簡単です -

15
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
15