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
Newsletter
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

  • Getting Started With Milvus: Vector Search for Enterprise Java Applications
  • PWA on iOS, Part 6: Performance, Rendering, and Keyboard
  • Choosing Voice AI Infrastructure: 7 Capabilities To Evaluate
  • Static and Dynamic Application Security Testing With IBM Appscan

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Oct. 12, 16 · Opinion
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
6.5K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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