Collect Logs and Metrics for HAProxy
This page provides instructions for configuring logs and metrics collection for the Sumo Logic App for HAProxy.
Collection Process Overview
Configuring log and metric collection for the HAProxy App includes the following tasks:
- Step 1: Configure Fields in Sumo Logic.
- Step 2: Configure Collection for HAProxy
Step 1: Configure Fields in Sumo Logic
Create the following Fields in Sumo Logic prior to configuring collection. This ensures that your logs and metrics are tagged with relevant metadata, which is required by the app dashboards. For information on setting up fields, see the Fields help page.
If you are using HAProxy in a non-Kubernetes environment create the fields:
- component
- environment
- proxy_system
- proxy_cluster
- pod
If you are using HAProxy in a Kubernetes environment create the fields:
- pod_labels_component
- pod_labels_environment
- pod_labels_proxy_system
- pod_labels_proxy_cluster
Step 2: Configure Collection for HAProxy
Sumo Logic supports collection of logs and metrics data from HAProxy in both Kubernetes and non-Kubernetes environments.
Please click on the appropriate links below based on the environment where your HAProxy servers are hosted.
Verify logs are flowing into Sumo Logic by running the following logs query:
component=”proxy” proxy_cluster=”<Your-HAProxy-Server>” proxy_system=”haproxy”
Sample Log Message
Kubernetes:
{ "timestamp": 1620894084572, "log": "<150>May 13 08:21:20 haproxy[9]: 127.0.0.1:38718 stats stats/<STATS> 0/0/0/0/0 200 3926 - - LR-- 1/1/0/0/0 0/0 \"GET /haproxy?stats/;csv HTTP/1.1\"", "stream": "stdout", "time": "2021-05-13T08:21:20.005706219Z" }
Non-Kubernetes:
May 13 08:24:43 localhost haproxy[21813]: 27.2.81.92:64274 [13/May/2021:08:24:43.921] web-edupia.vn-443~ cluster-host-service.edupia.vn/172.25.80.119 64/0/0/1/66 200 629 - - ---- 63/62/2/1/0 0/0 "POST /service/words/info HTTP/1.1"
Query sample
This query is from Top 5 Clients causing Errors panels from HAProxy - Overview dashboard.
<HAProxy_Cluster_Filter> proxy_system=haproxy component=proxy | json "log" as _rawlog nodrop | if (isEmpty(_rawlog), _raw, _rawlog) as haproxy_log_message | parse regex field=haproxy_log_message "(?<syslog_host>[\w\-\.]+) (?<ps>\w+)\[(?<pid>\d+)\]: (?<c_ip>[\w\.]+):(?<c_port>\d+) (?<rs>[^\"]*) (?<status_code>\d+) (?<bytes>\d+) (?<req_cookie>\S+) (?<res_cookie>\S+) (?<t_state>[\w-]+) (?<actconn>\d+)/(?<feconn>\d+)/(?<beconn>\d+)\/(?<srv_conn>\d+)/(?<retries>\d+) (?<srv_queue>\d+)/(?<backend_queue>\d+) \"(?<method>\w+) (?<request>[^\"]*) (?<http_version>\w+)" | where status_code matches "4*" or status_code matches "5*" and !isEmpty(c_ip) | count by c_ip | sort by _count | limit 5