0% found this document useful (0 votes)
27 views2 pages

HAProxy Configuration and Stats Guide

The document describes configuration parameters for HAProxy that define scripts to retrieve statistics from HAProxy and discover configuration details. It defines over 50 UserParameter configurations that each point to a haproxy_stats.sh script to retrieve specific statistics, such as requests, bytes, and session rates. It also provides instructions for manually running the discovery and stats scripts to explore the HAProxy socket output.

Uploaded by

sukhdevjadhav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views2 pages

HAProxy Configuration and Stats Guide

The document describes configuration parameters for HAProxy that define scripts to retrieve statistics from HAProxy and discover configuration details. It defines over 50 UserParameter configurations that each point to a haproxy_stats.sh script to retrieve specific statistics, such as requests, bytes, and session rates. It also provides instructions for manually running the discovery and stats scripts to explore the HAProxy socket output.

Uploaded by

sukhdevjadhav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

File: /home/sukhdev/Downloads/zabbi…ter/userparameter_haproxy.

conf
Page 1 of 2

#
# Discovery Rule
#

# HAProxy Frontend, Backend and Server Discovery rules


UserParameter=[Link][*],/usr/local/bin/haproxy_discovery.sh $1 $2

# cached results
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 $4

# support legacy way


UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 qcur
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 qmax
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 scur
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 smax
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 slim
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 bin
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 bout
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 dreq
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 dresp
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 ereq
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 econ
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 eresp
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 wretr
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 wredis
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 weight
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 act
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 bck
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 chkfail
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 chkdown
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 lastchg
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 downtime
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 qlimit
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 throttle
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 lbtot
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 tracked
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 type
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 rate
UserParameter=[Link].rate_lim[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 rate_lim
UserParameter=[Link].rate_max[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 rate_max
UserParameter=[Link].check_status[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3
check_status
UserParameter=[Link].check_code[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3
check_code
UserParameter=[Link].check_duration[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3
check_duration
UserParameter=[Link].req_rate[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 req_rate
UserParameter=[Link].req_rate_max[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3
req_rate_max
UserParameter=[Link].req_tot[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 req_tot
UserParameter=[Link].cli_abrt[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 cli_abrt
UserParameter=[Link].srv_abrt[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 srv_abrt
UserParameter=[Link].comp_in[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 comp_in
UserParameter=[Link].comp_out[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 comp_out
UserParameter=[Link].comp_byp[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 comp_byp
UserParameter=[Link].comp_rsp[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 comp_rsp
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 lastsess
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 qtime
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 ctime
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 rtime
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 status
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 pid
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 iid
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 sid
UserParameter=[Link].hrsp_1xx[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 hrsp_1xx
UserParameter=[Link].hrsp_2xx[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 hrsp_2xx
File: /home/sukhdev/Downloads/zabbi…ter/userparameter_haproxy.conf
Page 2 of 2

UserParameter=[Link].hrsp_3xx[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 hrsp_3xx
UserParameter=[Link].hrsp_4xx[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 hrsp_4xx
UserParameter=[Link].hrsp_5xx[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 hrsp_5xx
UserParameter=[Link].hrsp_other[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3
hrsp_other
UserParameter=[Link][*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 hanafail
UserParameter=[Link].last_chk[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 last_chk
UserParameter=[Link].last_agt[*],/usr/local/bin/haproxy_stats.sh $1 $2 $3 last_agt

# Debugging / Running it manually


## Discover: /usr/local/bin/haproxy_discovery.sh $1 $2
### $1 is a path to haproxy socket
### $2 is FRONTEND or BACKEND or SERVERS
# /usr/local/bin/haproxy_discovery.sh /var/run/haproxy/[Link] FRONTEND # second
argument is optional
# /usr/local/bin/haproxy_discovery.sh /var/run/haproxy/[Link] BACKEND # second
argument is optional
# /usr/local/bin/haproxy_discovery.sh /var/run/haproxy/[Link] SERVERS # second
argument is optional

# haproxy_stats.sh script
## haproxy_stats.sh $1 $2 $3 $4
### $1 is a path to haproxy socket - optional, defaults to haproxy_stats.sh
### $2 is a name of the backend, as set in [Link]
### $3 is a name of the server, as set in [Link]
### $4 is a stat as references by HAProxy terminology
# haproxy_stats.sh /var/run/haproxy/[Link] www-backend www01 status
# haproxy_stats.sh www-backend BACKEND status
# haproxy_stats.sh https-frontend FRONTEND status

# For the list of stats HAProxy supports as of version 1.5


# see TEXT: [Link]
# see HTML: [Link]

# Getting stats from HAProxy manually


## Bytes In: echo "show stat" | socat $1 stdio | grep "^$2,$3" | cut -d, -f9
## Bytes Out: echo "show stat" | socat $1 stdio | grep "^$2,$3" | cut -d, -f10
## Session Rate: echo "show stat" | socat $1 stdio | grep "^$2,$3" | cut -d, -f5
### $1 is a path to haproxy socket
### $2 is a name of the backend, as set in [Link]
### $3 is a name of the server, as set in [Link]
# echo "show stat" | socat /var/run/haproxy/[Link] stdio | grep "^www-backend,www01" |
cut -d, -f9
# echo "show stat" | socat /var/run/haproxy/[Link] stdio | grep "^www-backend,BACKEND"
| cut -d, -f10
# echo "show stat" | socat /var/run/haproxy/[Link] stdio | grep "^https-
frontend,FRONTEND" | cut -d, -f5
# echo "show stat" | socat /var/run/haproxy/[Link] stdio | grep "^api-backend,api02" |
cut -d, -f18 | cut -d\ -f1
##
# Take a look at the output of the following to learn more about what is available though
HAProxy socket
# echo "show stat" | socat /var/run/haproxy/[Link] stdio

Common questions

Powered by AI

To access HAProxy statistics manually using the socat command, the 'show stat' command can be piped through socat, connecting it to the HAProxy socket. Specific statistics can be extracted by filtering the output with the 'grep' command for the relevant identifier and using 'cut' to select the appropriate field number. For example, to get the 'Bytes In' for a specific server, the command is: 'echo "show stat" | socat $1 stdio | grep "^$2,$3" | cut -d, -f9' where $1 is the path to the HAProxy socket, $2 is the backend name, and $3 is the server name .

The output of the 'echo "show stat"' command through socat provides detailed insights into HAProxy's performance and operational statistics. Critical pieces of information, such as bytes in and out, session rate, and detailed backend or frontend performance metrics, can be extracted. This allows system administrators to assess traffic patterns, identify bottlenecks, and monitor the health and efficiency of HAProxy-managed services. Each field in the output corresponds to a specific metric as defined in HAProxy's configuration, empowering administrators with the real-time data necessary for informed decision-making .

Scripting is vital for automating the discovery and statistics gathering processes in HAProxy. Scripts like 'haproxy_discovery.sh' and 'haproxy_stats.sh' are used to automate the retrieval and reporting of HAProxy statistics. These scripts facilitate dynamic discovery of frontends, backends, and servers, allowing for efficient configuration management and the gathering of real-time data with minimal manual intervention. This automation supports scalability and helps maintain consistent monitoring setups across complex environments .

In large-scale deployments, the discovery of HAProxy Frontend, Backend, and Server entities is crucial for dynamic configuration management and scalability. This discovery process ensures that new components are automatically detected, integrated into the HAProxy configuration, and monitored without manual intervention. This capability facilitates rapid, large-scale expansions and reductions which are common in cloud environments and ensures that HAProxy configurations remain synchronized with the actual infrastructure, enhancing resilience, and operational efficiency .

The use of statistics scripts in HAProxy is critical for maintaining performance and reliability in production environments. These scripts provide essential data for performance analysis, helping to detect potential issues early and ensuring that HAProxy maintains its role effectively as a load balancer. However, if improperly configured, these scripts might introduce overhead, consume resources, or lead to incorrect data collection, potentially degrading performance or leading to misinformed decisions regarding system optimizations .

Organizations might utilize Zabbix in conjunction with HAProxy UserParameter configurations to achieve a comprehensive, integrated monitoring solution. Zabbix offers an extensive platform for gathering, visualizing, and alerting based on data from various sources, including those configured by UserParameters. By leveraging this integration, organizations can benefit from automated, detailed, and centralized monitoring, which helps in ensuring high availability, performance optimization, and rapid issue resolution across their IT infrastructure .

'UserParameter' definitions in Zabbix play a crucial role by specifying how particular statistics and metrics should be gathered for monitoring purposes. They define the shell commands, such as those invoking 'haproxy_stats.sh' with specific arguments, to execute in order to collect data about various HAProxy metrics. This allows Zabbix to interface with HAProxy, retrieve statistics like queue current ('qcur') or session max ('smax'), and use them for real-time monitoring and alerting .

Manual execution of discovery and stats scripts in HAProxy might be necessary during troubleshooting, where immediate, direct access to statistics is required to diagnose issues. Additionally, in instances where automated systems malfunction or fail to capture new configurations promptly, manual execution ensures timely updates. It might also be necessary for testing and development purposes, providing a controlled environment for validating new configurations without affecting automated processes .

Using the 'haproxy_stats.sh' script for monitoring HAProxy performance might pose several challenges. Firstly, there is dependency on shell scripts, which can present issues with portability and compatibility across different environments. Secondly, errors or inefficiencies in the script logic can lead to inaccurate data collection, impacting monitoring effectiveness. Additionally, any changes in HAProxy configuration or version updates may require modifications in the script to accommodate those changes, demanding continuous maintenance and potential downtimes in monitoring capabilities .

UserParameter definitions such as 'haproxy.stat.qcur' enable the extraction of specific operational metrics, like the current queue length, from HAProxy. This supports real-time monitoring by allowing tools like Zabbix to retrieve, process, and visualize the immediate state of the queues, which are critical in managing load distribution and preventing service bottlenecks. By continuously tracking such metrics, administrators can proactively handle potential issues before they escalate into major outages .

You might also like