0

I’m using rate limiting with my haproxy18 and I’d like to somehow squeeze out metrics from it based on ip addresses, who is close to the limit or how the users are hitting the limits.

This is my config related to rate limiting:

...
    stick-table type ip size 1m expire 10s store http_req_rate(10s)

    tcp-request inspect-delay 10s
    tcp-request content track-sc0 src
    http-request deny deny_status 429 if { sc_http_req_rate(0) gt 5000 }
...

At the moment what I can do is a very silly solution and I don’t like, in a while loop I’m listening the socket and I might redirect to a file the output:

while sleep 0.5;do
                printf 'show table https\nshow table http\n' |nc -U /var/lib/haproxy/stats done

This is the output of the while, what I'm interested in is the ip and the last number in the line:

0x561fd2fe50b0: key=10.118.171.119 use=6 exp=8726 http_req_rate(10000)=9
0x561fd31b0270: key=10.118.172.20 use=6 exp=9104 http_req_rate(10000)=10
0x561fd31d0ac0: key=10.118.172.192 use=34 exp=9999 http_req_rate(10000)=1736

I’d like to know is there any other more elegant solution please or how can I convert this to log entry?

I was thinking to put the date command like this but I should append all the lines in the table so I need to redirect this output to a file and edit then let the metric collector pick up, I assume there is some prettier solution.

while sleep 0.5;do date;printf 'show table https\nshow table http\n' |nc -U /var/lib/haproxy/stats;done

Thank you

Badb0y
  • 15
  • 2

0 Answers0