ToiVietBlog - Bài viết này mình sẽ hướng dẫn các bạn monitor ping host với blackbox exporter. Việc monitor host/website up hoặc down thông qua việc check ping khá hữu ích.
Bạn có thể sử dụng ping ICMP để check bất kì dạng host nào: website, server, firewall, switch, camera,…
Recommended Reading: Cài đặt Prometheus Blackbox exporter trên Ubuntu 18
Thiết lập cho Prometheus sử dụng Blackbox exporter
Đầu tiên, bạn mở file cấu hình của prometheus lên.
nano /etc/prometheus/prometheus.yml
Sau đó, bạn thêm nội dung sau vào cuối file prometheus.yml
. Bạn lưu ý việc sử dụng các khoảng trắng (space) phải đúng theo định dạng file yml nhé.
- job_name: 'blackbox_ping' metrics_path: /probe params: module: [icmp] static_configs: - targets: - 8.8.8.8 - host.example.com 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
Bạn lưu file lại và reload prometheus.
service prometheus reload
Bây giờ, bạn truy cập domain prometheus, vào menu Status -> Targets
. Bạn xem phần job blackbox_ping
, các endpoint đều UP
như vậy là thành công.

Recommended Reading: Thiết lập nginx proxy cho prometheus và grafana
Thiết lập data sources cho Grafana
Phần này khá đơn giản, bạn login vào domain Grafana.
Tại menu bên trái, bạn chọn Configuration -> Data Sources
. Tiếp theo bạn chọn kiểu data source là Prometheus
.
Bạn điền địa chỉ database prometheus (http://localhost:9090
) vào ô URL như hình dưới đây và bấm Save & Test
.

Thiết lập dashboard Grafana monitor ping
Bây giờ tới lượt sử dụng dashboard grafana. Tại menu trái, bạn bấm nút tạo dashboard (+
) và chọn Import
.
Bạn nhập ID dashboard là 12412 và bấm Load.

Cửa sổ tiếp theo, tại phần localhost
ở dưới cùng, bạn chọn data source prometheus và bấm Import
là xong.
Kết luận
Với bài viết này, mình đã hướng dẫn các bạn từng bước để monitor ping host sử dụng Blackbox exporter. Từ việc thiết lập cấu hình prometheus cho đến việc thiết lập dashboard grafana.
If you appreciate what we share in this blog, you can support us by:
- Stay connected to: Facebook | Twitter | Google Plus | YouTube
- Subscribe email to recieve new posts from us: Sign up now.
- Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
- Become a Supporter - Make a contribution via PayPal.
- Support us by purchasing Ribbon Lite Child theme being using on this website.
We are thankful for your support.