
Cập nhật lần cuối: 29/01/2026 17:00
HAProxy
Tài liệu hướng dẫn cấu hình Alloy để thu thập Metrics từ ứng dụng HAProxy
/bin/sh -c "$(curl -fsSL https://s3hn.smartcloud.vn/agent/alloy/linux/releases/v1.8.3/install-linux.sh)"defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend metrics
bind *:8404
mode http
http-request use-service prometheus-exporter if { path /metrics }2. Cấu hình tích hợp
Tại đường dẫn /etc/alloy/config.alloy, chỉnh sửa Alloy để tích hợp HAProxy:
sudo vi /etc/alloy/config.alloyThay các trường trong 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-cvnptcloud |
| IP | IP VM đang chạy HAProxy | 10.168.17.30 |
logging {
level = "warn"
format = "logfmt"
}
prometheus.remote_write "metrics_integrations_haproxy" {
endpoint {
url = "<endpoint dịch vụ APM>"
headers = {
"Authorization" = "<token dịch vụ APM>",
}
}
external_labels = {
tenant = "<tên dịch vụ APM>",
}
}
discovery.relabel "metrics_integrations_haproxy" {
targets = [{
__address__ = "<IP>:8404",
}]
rule {
source_labels = ["__address__"]
regex = "([^:]+):.*"
target_label = "instance"
replacement = "$1"
}
}
prometheus.scrape "metrics_integrations_haproxy" {
targets = discovery.relabel.metrics_integrations_haproxy.output
forward_to = [prometheus.relabel.metrics_integrations_haproxy.receiver]
job_name = "integrations/haproxy"
}
prometheus.relabel "metrics_integrations_haproxy" {
forward_to = [prometheus.remote_write.metrics_integrations_haproxy.receiver]
rule {
source_labels = ["__name__"]
regex = "up|haproxy_backend_bytes_in_total|haproxy_backend_bytes_out_total|haproxy_backend_check_up_down_total|haproxy_backend_connect_time_average_seconds|haproxy_backend_connection_attempts_total|haproxy_backend_connection_errors_total|haproxy_backend_http_requests_total|haproxy_backend_internal_errors_total|haproxy_backend_max_connect_time_seconds|haproxy_backend_max_queue_time_seconds|haproxy_backend_max_response_time_seconds|haproxy_backend_max_total_time_seconds|haproxy_backend_queue_time_average_seconds|haproxy_backend_response_errors_total|haproxy_backend_response_time_average_seconds|haproxy_backend_status|haproxy_backend_total_time_average_seconds|haproxy_frontend_bytes_in_total|haproxy_frontend_bytes_out_total|haproxy_frontend_connections_total|haproxy_frontend_http_requests_total|haproxy_frontend_internal_errors_total|haproxy_frontend_request_errors_total|haproxy_frontend_status|haproxy_process_current_connections|haproxy_process_dropped_logs_total|haproxy_process_limit_connection_rate|haproxy_process_limit_session_rate|haproxy_process_limit_ssl_rate|haproxy_process_max_connections|haproxy_process_max_fds|haproxy_process_max_memory_bytes|haproxy_process_max_pipes|haproxy_process_max_sockets|haproxy_process_nbproc|haproxy_process_nbthread|haproxy_process_pool_allocated_bytes|haproxy_process_pool_used_bytes|haproxy_process_start_time_seconds|haproxy_server_bytes_in_total|haproxy_server_bytes_out_total|haproxy_server_check_up_down_total|haproxy_server_connect_time_average_seconds|haproxy_server_connection_attempts_total|haproxy_server_connection_errors_total|haproxy_server_http_responses_total|haproxy_server_internal_errors_total|haproxy_server_max_connect_time_seconds|haproxy_server_max_queue_time_seconds|haproxy_server_max_response_time_seconds|haproxy_server_max_total_time_seconds|haproxy_server_queue_time_average_seconds|haproxy_server_response_errors_total|haproxy_server_response_time_average_seconds|haproxy_server_status|haproxy_server_total_time_average_seconds"
action = "keep"
}
}Thực hiện lệnh sau để khởi động Alloy:
sudo systemctl start alloyThự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.alloy
Nế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 alloyTham khảo hướng dẫn tích hợp dashboard, kiểm tra metrics HAProxy trên giao diện Dashboard:
Một số dashboard mẫu khi tích hợp thành công: