AS Monitoring-Svr Script

#!/bin/bash

while true
do
rm req-values
#Get instance list
as-describe-auto-scaling-groups unni-autoscale-test | awk {‘print $2’} | grep -v unni-autoscale-test > inst-list

#retrieving public ip address from the instance address
for i in `cat /home/unni/as-test/inst-list`; do
ec2-describe-instances $i  | awk ‘{print $4}’ | grep amazonaws.com >> ip-list
done

#retrieving access log values
for i in `cat /home/unni/as-test/ip-list`; do
ssh -i unni.pem -o StrictHostKeyChecking=no ubuntu@$i source /home/ubuntu/requestretriever.sh >> req-values
done

#requestretriever.sh is the name of the script running in the host machines.

rm ip-list

#taking average and uploading it to cloudwatch
avg=`awk ‘{s+=$1} END {print “Average: ” s/NR}’ req-values | awk ‘{print $2}’`

mon-put-data -m “RequestCount” –namespace UnniCustomMetric –dimensions “instance=i-virtual01,servertype=apache” –value $avg -u Bytes

done

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s