
Cập nhật lần cuối: 29/01/2026 17:00
Blackbox Exporter
Tài liệu này hướng dẫn cấu hình Blackbox Exporter để thu thập metrics giám sát tình trạng hoạt động của các endpoints qua các giao thức như HTTP, TCP, ICMP, DNS
/bin/sh -c "$(curl -fsSL https://s3hn.smartcloud.vn/agent/alloy/linux/releases/v1.8.3/install-linux.sh)"Tại đường dẫn /etc/alloy/config.alloy, chỉnh sửa Alloy để tích hợp Blackbox Exporter:
sudo vi /etc/alloy/config.alloyFile module.yml cho phép cấu hình chi tiết cách Blackbox Exporter thực hiện kiểm tra, gồm:
Ví dụ
modules:
<module_name_1>:
prober: <protocol>
timeout: <timeout>
<các tùy chọn cụ thể cho từng loại prober>
<module_name_2>:
prober: <protocol>
timeout: <timeout>
<các tùy chọn cụ thể cho từng loại prober>Ý nghĩa các trường trong file module.yml
| Trường | Ý nghĩa | Giá trị mẫu |
| module_name | Tên module dùng trong file alloy | icmp_ping |
| protocol | Giao thức sử dụng | icmp |
| timeout | Thời gian tối đa cho một probe | 10s |
Ví dụ một file cấu hình cụ thể trông như sau:
modules:
icmp_ping:
prober: icmp
timeout: 5s
tcp_connect:
prober: tcp
timeout: 5s
tcp:
preferred_ip_protocol: ip4
dns_check:
prober: dns
timeout: 5s
dns:
query_name: "vnpt.vn"
query_type: "A"
http_get:
prober: http
timeout: 10s
http:
method: GET
valid_status_codes: [200]
preferred_ip_protocol: ip4
http_post:
prober: http
timeout: 10s
http:
method: POST
valid_status_codes: [200]
preferred_ip_protocol: ip4Thay các trường ở file cấu hình sau, trong đó:
| Trường | Ý nghĩa | Giá trị mẫu |
| url | Endpoint của dịch vụ APM trên giao diện Console | https://metrics-0qcs3dsvvva.apm.vnptplatform.vn/api/v1/push |
| Authorization | Token của dịch vụ APM trên giao diện Console | a5130b91-ff9b-41ef-8722-9d923a574123 |
| tenant | Tên dịch vụ APM | apm-vnptcloud |
| module_file | Đường dẫn chứa định nghĩa giao thức | /etc/alloy/module.yml |
| target_address | Endpoint cần giám sát | facebook.com |
| module | Tên module đã được cấu hình trong module_file | tcp_connect |
| label | Thêm label cho metric thu được | purpose = "http" |
| target_name | Tên target muốn lấy metrics | ping_google |
| description | Mô tả về target của blackbox | ping google.com |
| method | Phương thức sử dụng | GET |
| domain | Tên miền cần phân giải | vnpt.com |
logging {
level = "warn"
format = "logfmt"
}
prometheus.remote_write "remote_receiver" {
endpoint {
url = "<url>"
headers = {
Authorization = "<token>",
}
}
external_labels = {
tenant = "<tenant>",
}
}
prometheus.exporter.blackbox "ping_monitor" {
config_file = "/etc/alloy/blackexporter-module.yml"
target {
name = "<target_name_1>"
address = "<target_address_1>"
module = "<module>"
labels = { purpose = "ping", target = "<target_address>", description = "<description>" }
}
target {
name = "<target_name_2>"
address = "<target_address_2>"
module = "<module>"
labels = { purpose = "ping", target = "<target_address>", description = "<description>" }
}
}
prometheus.exporter.blackbox "tcp_ports" {
config_file = "/etc/alloy/blackexporter-module.yml"
target {
name = "<target_name_3>"
address = "<target_address_3>"
module = "<module>"
labels = { purpose = "tcp",target="<target_address>",port = "443", description = "<description>" }
}
target {
name = "<target_name_4>"
address = "<target_address_4>"
module = "<module>"
labels = { purpose = "tcp",target="<target_address>", port = "465", description = "<description>" }
}
}
prometheus.exporter.blackbox "dns_monitor" {
config_file = "/etc/alloy/blackexporter-module.yml"
target {
name = "<target_name_5>"
address = "1.1.1.1"
module = "<module>"
labels = { domain = "<domain_name>", purpose = "dns", description = "<description>" }
}
target {
name = "<target_name_6>"
address = "1.1.1.1"
module = "<module>"
labels = { domain = "<domain_name>", purpose = "dns", description = "<description>" }
}
}
prometheus.exporter.blackbox "http_monitor" {
config_file = "/etc/alloy/blackexporter-module.yml"
target {
name = "<target_name_7>"
address = "<target_address_7>"
module = "<module>"
labels = { method = "<method>", target = "<target_address>", purpose = "http", description = "<description>" }
}
target {
name = "<target_name_8>"
address = "<target_address_8>"
module = "<module>"
labels = { method = "<method>", target = "<target_address>", purpose = "http", description = "<description>" }
}
}
prometheus.scrape "blackbox_all" {
targets = concat(prometheus.exporter.blackbox.dns_monitor.targets, prometheus.exporter.blackbox.tcp_ports.targets, prometheus.exporter.blackbox.ping_monitor.targets, prometheus.exporter.blackbox.http_monitor.targets)
scrape_interval = "5m"
forward_to = [prometheus.remote_write.remote_receiver.receiver]
}Thực hiện lệnh sau:
sudo systemctl status alloyKết quả nếu thành công:
alloy.service - Vendor-agnostic OpenTelemetry Collector distribution with programmable pipelines
Loaded: loaded (/lib/systemd/system/alloy.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2025-04-23 10:44:50 +07; 5s ago
Docs: https://grafana.com/docs/alloy
Main PID: 3119454 (alloy)
Tasks: 13 (limit: 9385)
Memory: 61.3M
CPU: 848ms
CGroup: /system.slice/alloy.service
└─3119454 /usr/bin/alloy run --server.http.listen-addr=0.0.0.0:30000 --storage.path=/var/lib/alloy/data /etc/alloy/config.alloyNếu chưa thành công, thực hiện lệnh sau để xem log của Alloy:
sudo journalctl -u alloySau đó, sửa lại giá trị của cấu hình và restart lại Alloy:
sudo systemctl restart alloy2.5 Kiểm tra tích hợp
Tham khảo hướng dẫn tích hợp dashboard, kiểm tra metrics Blackbox Exporter trên giao diện Dashboard:
Một số dashboard mẫu khi tích hợp thành công: