Thursday, 18 June 2015

Logging Server Connection counts

The below code is used to log connection counts on a SOA gateway (Actional in this case).
The aim is to try to see when the connections spike and have a kind of history benchmark to tell if things are looking fine.

below is a simple shell command to log established connection by IP address:

netstat -nat |grep ESTAB |cut -d ":" -f8,9 |sort |uniq -c

This is made to run on a crontab job every 5 mins.
The output is exposed (from a web server) to another script on a monitoring server that inserts this data into a mysql database for furture processing or reporting:

for rec in `curl http://mywebmonitor:10080/checkTC/soa/host_con_cnt 2>/dev/null |grep EST|tr -s " "|tr " " ":"`
do
        CON_CNT=`echo $rec|cut -d":" -f2`
        IP=`echo $rec|cut -d":" -f3`
        HOST=`nslookup ${IP}|grep name |cut -d "=" -f2 |sed 's/^ //g'|sed 's/.$//g'`
        WSPORT=`echo $rec|cut -d":" -f4`
        echo "INSERT INTO ssz_monitor.Actional_host_con_count (TCP_CON_CNT,HostName,IP,WS_Port,Actional_node,Timestamp) VALUES ('${CON_CNT}','${HOST}','${IP}','${WSPORT}','act05','`date +%Y%m%d%H%M `');"
done  >insert05.sql
mysql -u root -proot <insert05.sql






The data is inserted in the table and using HiediSQL we can export to analyze in Excel or any other spread sheet.
I am looking in creating reporting graphs out of this table, that would be much quicker to help if we have an issue.

1 comment:

  1. Actually using WebPivotTable proved very useful :)
    i used the node.js application to do analytics on the fly, just needed to export the data from my table and add it on a webserver then use that URL as a datasource thats it.

    ReplyDelete