DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Efficient String Formatting With Python f-Strings
  • Python F-Strings
  • Developing Metadata-Driven Data Engineering Pipelines Using Apache Spark and Python Dictionary
  • Python Dictionary: A Powerful Tool for Data Engineering

Trending

  • Lambda-Driven API Design: Building Composable Node.js Endpoints With Functional Primitives
  • How SaaS Architectures Break at Scale — and the Engineering Decisions That Prevent It
  • When Snowflake Lies to You: Understanding False Failures in dbt Pipelines
  • No More Cheap Claude: 4 First Principles of Token Economics in 2026
  1. DZone
  2. Data Engineering
  3. Data
  4. Convert HAProxy Statistics to a Python Dictionary

Convert HAProxy Statistics to a Python Dictionary

HAProxy provides both a GUI and a UNIX socket file. Through them, we can explore lots of critical info, especially HAProxy Statistics.

By 
Denny Zhang user avatar
Denny Zhang
·
Oct. 12, 16 · Opinion
Likes (1)
Comment
Save
Tweet
Share
6.3K Views

Join the DZone community and get the full member experience.

Join For Free

haproxy is a very popular load balancer and reverse proxy service at both l7 layer(http) and l4 layer(tcp). with easy setup, we can get the haproxy stats page in gui. 1

understand haproxy stats page

haproxy_stats_gui.jpg

from the haproxy gui, we know the below meaningful metrics:

  • normal http/https visit hits . poll the data periodically. we can have a clear understanding for the history and the trend. pretty much close to google analytics. right?
  • exceptions in server side . if we have a noticeable number of failures, raise alarms immediately.
  • slow response. mostly we shall see very few slow responses. better add monitoring items for this.
  • errors in client side . could be different reasons. e.g, being attacked by malicious users, users are calling api with old data format, etc.

interactive with unix socket file

the same metrics in the gui can be retrieved via the unix socket 2 . hmm… yes, it really is the same. just a bit complicated.

# figure out file path of haproxy socket file
# grep sock /etc/haproxy/haproxy.cfg

root@denny# echo "show stat" | nc -u /var/run/haproxy/admin.sock
# pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,...
frontend-http,frontend,,,0,1,2000,14,3738,82593,0,0,3,,,,,op...
frontend-https,frontend,,,0,1,2000,6,410,150635,0,0,2,,,,,op...
backend-http,127.0.0.1,0,0,0,1,4000,5,767,597,,0,,0,0,0,0,up...
backend-http,backend,0,0,0,1,200,5,767,597,0,0,,0,0,0,0,up,1...
backend-https,127.0.0.1,0,0,0,1,4000,3,263,130057,,0,,0,0,0,...
backend-https,backend,0,0,0,1,200,3,263,130057,0,0,,0,0,0,0,...

convert socket output into a python dictionary

the first line of the above command output is a list of field names. following that, each line is a record of data.

wrap up a python module (original in github).

haproxy_convert.jpg

if you can’t measure it, you can’t manage it. — peter drucker.

next step : add effective monitoring and pull meaningful metrics about haproxy.

more reading : generate common db data report by elk .

footnotes :

1 www.datadoghq.com/blog/how-to-collect-haproxy-metrics/
2 http://cbonte.github.io/haproxy-dconv/1.6/management.html#9.2
HAProxy Python (language) Statistics Convert (command) Dictionary (software)

Published at DZone with permission of Denny Zhang. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Efficient String Formatting With Python f-Strings
  • Python F-Strings
  • Developing Metadata-Driven Data Engineering Pipelines Using Apache Spark and Python Dictionary
  • Python Dictionary: A Powerful Tool for Data Engineering

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook