DZone
Performance Zone
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
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Performance Zone > 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.

Denny Zhang user avatar by
Denny Zhang
·
Oct. 12, 16 · Performance Zone · Opinion
Like (1)
Save
Tweet
5.20K 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, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How Low Code Demands More Creativity From Developers
  • Understand Source Code — Deep Into the Codebase, Locally and in Production
  • Monolith vs Microservices Architecture: To Split or Not to Split?
  • Implementing Microservices Architectures

Comments

Performance Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo