Monitoring Uptime Website With Blackbox Exporter Prometheus

Monitoring utptime website dengan blackbox exporter prometheus grafana

Artikel Installasi Node Exporter Prometheus Grafana

  • Pastikan sudah install prometheus dan grafana
  • Buat user baru blackbox
sudo useradd -M -r -s /bin/false blackbox
  • Download blackbox exporter versi terbaru
curl -s https://api.github.com/repos/prometheus/blackbox_exporter/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi -
  • Extract blackbox exporter, masuk ke directory blackbox_exporter lalu copy ke /usr/local/bin
tar xvf  blackbox_exporter*.tar.gz
cd blackbox_exporter*
cp blackbox_exporter /usr/local/bin
  • Cek versi blackbox exporter
blackbox_exporter --version

blackbox_exporter, version 0.19.0 (branch: HEAD, revision: 5d575b88eb12c65720862e8ad2c5890ba33d1ed0)
  build user:       root@2b0258d5a55a
  build date:       20210510-12:56:44
  go version:       go1.16.4
  platform:         linux/amd64
  • Ganti kepemilikan directory/file blackbox exporter
chown blackbox:blackbox /usr/local/bin/blackbox_exporter
  • Buar directory pada /etc/blackbox, copy file blackbox.yml yang ada pada direcotry blackbox_exporter ke dalam /etc/blackbox, set permission directory/file /etc/blackbox/
sudo mkdir -p /etc/blackbox
sudo cp blackbox.yml /etc/blackbox
sudo chown -R blackbox:blackbox /etc/blackbox/*
  • Tambahkan file konfigurasi systemd service untuk blackbox di /etc/systemd/system/blackbox.service dengan isi file seperti berikut:
nano /etc/systemd/system/blackbox.service
[Unit]
Description=Blackbox Exporter Service
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=blackbox
Group=blackbox
ExecStart=/usr/local/bin/blackbox_exporter \
  --config.file=/etc/blackbox/blackbox.yml \
  --web.listen-address=:9115

Restart=always

[Install]
WantedBy=multi-user.target
  • Reload system daemon dan jalankan service blackbox
sudo systemctl daemon-reload
sudo systemctl enable blackbox
sudo systemctl start blackbox
  • Cek service blackbox nya apakah sudah running atau belum
sudo systemctl status blackbox

● blackbox.service - Blackbox Exporter Service
   Loaded: loaded (/etc/systemd/system/blackbox.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-10-06 23:08:41 WIB; 14h ago
 Main PID: 7534 (blackbox_export)
   CGroup: /system.slice/blackbox.service
           └─7534 /usr/local/bin/blackbox_exporter --config.file=/etc/blackbox/blackbox.yml --web.listen-address=:911...

Oct 06 23:08:41 icmp.my.id systemd[1]: Started Blackbox Exporter Service.
Oct 06 23:08:41 icmp.my.id blackbox_exporter[7534]: level=info ts=2021-10-06T16:08:41.096Z caller=main.go:224 msg...d0)"
Oct 06 23:08:41 icmp.my.id blackbox_exporter[7534]: level=info ts=2021-10-06T16:08:41.096Z caller=main.go:225 bui...44)"
Oct 06 23:08:41 icmp.my.id blackbox_exporter[7534]: level=info ts=2021-10-06T16:08:41.097Z caller=main.go:237 msg...ile"
Oct 06 23:08:41 icmp.my.id blackbox_exporter[7534]: level=info ts=2021-10-06T16:08:41.098Z caller=main.go:385 msg...9115
Oct 06 23:08:41 icmp.my.id blackbox_exporter[7534]: level=info ts=2021-10-06T16:08:41.099Z caller=tls_config.go:1...alse
Hint: Some lines were ellipsized, use -l to show in full.
  • Pastikan port 9115 sudah di allow oleh firewall, akses blackbox dengan url: http://ip_server_blackbox:9115 , sampai di sini installasi blackbox sudah selesai.

  • Setting pada prometheus
  • Edit file /etc/prometheus/prometheus.yml ganti pada bagian targets, tambahkan baris berikut pada bagian paling bawah:
  # Using the [http_2xx] module
  - job_name: 'Blackbox_HTTPS'
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
      - targets:
        # The http host you are targeting
        - https://icmp.my.id
        - https://lg.icmp.my.id
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        #Where Blackbox exporter was installed plust port
        replacement: icmp.my.id:9115
  • Restart service promethues
sudo systemctl restart grafana-server

  • Import dashboard pada grafana, dashboard yang akan digunakan adalah nomor 7587 (https://grafana.com/grafana/dashboards/7587).
  • Masukan nomor dashboard 7587 > Load > Edit nama dashboard > Pilih Metrics: Prometheus > Import
  • Tampilan dashboard blackbox exporter prometheus grafana

herdiana3389

A system administrator with skills in system administration, virtualization, linux, windows, networking, cloud computing, container, etc.