Forum Discussion
6 Replies
- Ryan_80361Cirrostratus
A number of years ago, i had to do something similar. We needed to graph numbers of internal versus external connections to a particular virtual server. I'm sure there are easier ways of achieving the same results today but here's what i did..
i made the following shell script and chmod-ed it to be executable:
set the class file where the final output is written to classfile=/var/class/pcms_active_conns.class set the tmpfile where the output from the b conn is sent so we can count stuff tmpfile=/var/class/pcms_active_conns.tmp change to ai partition `b shell partition ai` get existing internal connections oldint=`sed -n '1p' $classfile` delete the old internal connection count from our class `b class pcms_active_connections $oldint delete` get existing external connections oldext=`sed -n '2p' $classfile` delete the old external connections from our class `b class pcms_active_connections $oldext delete` get the number of current active connections for the pcms VIP `b conn server 130.220.xx.yy | awk -F":" '{print $1}' | sort > $tmpfile` mathematical crap total=`wc -l $tmpfile | awk '{print $1}'` internal=`grep -c '^10.\|^130.220' $tmpfile` external=$(($total - $internal)) do stuff with the final results echo "\"internal $internal\"" > $classfile echo "\"external $external\"" >> $classfile `b class pcms_active_connections "\"internal $internal\"" add` `b class pcms_active_connections "\"external $external\"" add`
A crontab entry was setup to run the above script once a minute. Created a new data group called pcms_active_connections, make it of type string.
Created the following iRule and applied it to my virtual server:
when HTTP_REQUEST { if {[HTTP::uri] eq "/connection-stats"} { set connlist [class get pcms_active_connections ] HTTP::respond 200 content $connlist "Content-Type" "text/html" } }
Then set up a probe in our monitoring software (we use Intermapper) to query the virtual server for the /connection-stats uri and graph the results for external and internal connections.
Hopefully you can use some of this or it helps in some way.
- Ron_130795NimbostratusThanks Ryan. What a huge help. I will take a close look at your script and see if I can apply it to our environment.
- RyannnnnnnnnAltocumulus
A number of years ago, i had to do something similar. We needed to graph numbers of internal versus external connections to a particular virtual server. I'm sure there are easier ways of achieving the same results today but here's what i did..
i made the following shell script and chmod-ed it to be executable:
set the class file where the final output is written to classfile=/var/class/pcms_active_conns.class set the tmpfile where the output from the b conn is sent so we can count stuff tmpfile=/var/class/pcms_active_conns.tmp change to ai partition `b shell partition ai` get existing internal connections oldint=`sed -n '1p' $classfile` delete the old internal connection count from our class `b class pcms_active_connections $oldint delete` get existing external connections oldext=`sed -n '2p' $classfile` delete the old external connections from our class `b class pcms_active_connections $oldext delete` get the number of current active connections for the pcms VIP `b conn server 130.220.xx.yy | awk -F":" '{print $1}' | sort > $tmpfile` mathematical crap total=`wc -l $tmpfile | awk '{print $1}'` internal=`grep -c '^10.\|^130.220' $tmpfile` external=$(($total - $internal)) do stuff with the final results echo "\"internal $internal\"" > $classfile echo "\"external $external\"" >> $classfile `b class pcms_active_connections "\"internal $internal\"" add` `b class pcms_active_connections "\"external $external\"" add`
A crontab entry was setup to run the above script once a minute. Created a new data group called pcms_active_connections, make it of type string.
Created the following iRule and applied it to my virtual server:
when HTTP_REQUEST { if {[HTTP::uri] eq "/connection-stats"} { set connlist [class get pcms_active_connections ] HTTP::respond 200 content $connlist "Content-Type" "text/html" } }
Then set up a probe in our monitoring software (we use Intermapper) to query the virtual server for the /connection-stats uri and graph the results for external and internal connections.
Hopefully you can use some of this or it helps in some way.
- Ron_130795NimbostratusThanks Ryan. What a huge help. I will take a close look at your script and see if I can apply it to our environment.
- Stefan_KlotzCumulonimbus
Hi Ron,
below code is just an idea, not tested and also not validated for correct syntax (but should give you the right direction):
when RULE_INIT { set ::last_midnight [clock scan {2014-07-21 00:00:00}] set ::connection_count 0 } when CLIENT_ACCEPTED { set current_time [clock seconds] Check if the difference to last_midnight is less than 24 hours (86400 seconds) if { [expr {$current_time - $::last_midnight} ] < 86400 } { incr $::connection_count } else { Log current connection_count value log local0. "Number of connections for the last 24 hours: $::connection_count" Reset the connection_count value set ::connection_count 0 Increment last_midnight with 24 hours (86400 seconds) set ::last_midnight [clock add $::last_midnight 86400] } }
That should be a little more easier than with the external script.
Ciao Stefan 🙂
- Stefan_KlotzCumulonimbus
Hi Ron,
please find below updated iRule without syntax errors (but still not functional tested) and logging to a remote syslog server.
when RULE_INIT { set ::last_midnight [clock scan {2014-07-21 00:00:00}] set ::connection_count 0 } when CLIENT_ACCEPTED { set current_time [clock seconds] Check if the difference to last_midnight is less than 24 hours (86400 seconds) if { [expr $current_time - $::last_midnight] < 86400 } { incr ::connection_count } else { Log current connection_count value log local0. "Number of connections for the last 24 hours: $::connection_count" Reset the connection_count value set ::connection_count 0 Increment last_midnight with 24 hours (86400 seconds) set ::last_midnight [expr $::last_midnight + 86400] } }
Please give it a try again.
Ciao Stefan 🙂