2011-03-06

Perl one-liner: count Apache connections to local app servers.

I had this one-liner lying around that I meant to drop on here. Looking at it I'm fairly certain the scenario was as follows.

This one box has a single Apache (IBM HTTP Server, really) instance talking to a lot of different application servers (WebSphere), which also run locally. Ignore the wisdom or lack thereof for this configuration. For whatever reason (verify load balance settings?), I had to count the number of connections Apache was making to each application server.

root@somebox:/tmp
# lsof -i TCP -P | perl -ane 'next unless /^httpd/ && /->somebox/; $p{(split(":", $F[-2]))[2]}++; END { for $i (keys %p) {print  "$i = $p{$i}\n"}}'
8056 = 305
8054 = 30
8053 = 27
8057 = 31
8050 = 353

So as we can see, at the time I ran this script, the balance of connections was really lopsided. The application server listening on port 8056 had 305 connections and the one listening at port 8054 had 30 connections, and so on.

No comments:

Post a Comment