-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rocco Muscaritolo
authored and
Rocco Muscaritolo
committed
Apr 3, 2014
1 parent
5867180
commit 1f79a78
Showing
5 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
autoscale | ||
========= | ||
|
||
Autoscale monitoring scripts | ||
Auto scale scripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
if (metric['sysload_avg'] < 2.0 && metric['percent_memory_used'] < 30 && metric['percent_maxclients'] < 30) { | ||
return new AlarmStatus(CRITICAL, 'Auto Scale servers have been over provisioned. Auto #scale group is being scaled down!'); | ||
} | ||
|
||
return new AlarmStatus(OK, 'Auto Scale servers are being used too heavily for safe scale down.'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
#!/bin/bash | ||
|
||
load=`sh /root/scaledown_check.sh | grep sysload_avg | awk '{print $4}'` | ||
mem=`sh /root/scaledown_check.sh | grep percent_memory_used | awk '{print $4}'` | ||
maxclients=`sh /root/scaledown_check.sh | grep percent_maxclients | awk '{print $4}'` | ||
|
||
if awk -v ld=$load 'BEGIN {exit !(ld < 2)}' && awk -v mem=$mem 'BEGIN {exit !(mem < 30)}' && awk -v cli=$maxclients 'BEGIN {exit !(cli < 30)}' | ||
then | ||
echo `date` "Autoscale load check: Scaling DOWN by 1 server!" | ||
curl -X POST https://iad.autoscale.api.rackspacecloud.com/v1.0/execute/1/13aa6c05ca918b7f0cf6f04336176e4b2ba7359ab44f7f9b555a7a72b7d088b5/ | ||
else | ||
echo `date` "Autoscale load check: Not ready for scale down" | ||
fi | ||
|
||
echo " Average sysload = $load | ||
Average memory use = $mem % | ||
Average MaxClients use = $maxclients %" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/bash | ||
|
||
# Example criteria : | ||
# | ||
#if (metric['sysload_avg'] < 2.0 && metric['percent_memory_used'] < 30 && metric['percent_maxclients'] < 30) { | ||
# return new AlarmStatus(CRITICAL, 'Auto Scale servers have been over provisioned. Auto #scale group is being scaled down!'); | ||
#} | ||
# | ||
#return new AlarmStatus(OK, 'Auto Scale servers are being used too heavily for safe scale down.'); | ||
|
||
######################################################################################################################## | ||
|
||
|
||
# Getting time parameters for sar command | ||
end=`date | awk '{ print $4}'` | ||
start=`date -d "1 hour ago" | awk '{ print $4}'` | ||
|
||
|
||
# Find average sysload from last hour | ||
sysloadavg=`sar -q -s $start -e $end | grep Average | tail -n 1 | tr -s ' ' | awk '{print $4}'` | ||
|
||
# Print metric system load | ||
echo "metric sysload_avg float" $sysloadavg | ||
|
||
|
||
######################################################################################################################## | ||
|
||
|
||
# Setting proper values for average memory usage from last hour | ||
memfree=`sar -r -s $start -e $end | grep Average | tail -n 1 | tr -s ' ' | awk '{print $2}'` | ||
memused=`sar -r -s $start -e $end | grep Average | tail -n 1 | tr -s ' ' | awk '{print $3}'` | ||
memtotal=`awk -v memfree=$memfree -v memused=$memused 'BEGIN { print memfree + memused }'` | ||
buffers=`sar -r -s $start -e $end | grep Average | tail -n 1 | tr -s ' ' | awk '{print $5}'` | ||
cached=`sar -r -s $start -e $end | grep Average | tail -n 1 | tr -s ' ' | awk '{print $6}'` | ||
nocache=`awk -v memused=$memused -v buffers=$buffers -v cached=$cached 'BEGIN { print memused - ( buffers + cached ) }'` | ||
|
||
# Find use percentage | ||
mempercentage=`awk -v nocache=$nocache -v memtotal=$memtotal 'BEGIN { print nocache * 100 / memtotal }'` | ||
|
||
# Print metric memory | ||
echo "metric percent_memory_used float" $mempercentage | ||
|
||
|
||
######################################################################################################################## | ||
|
||
|
||
# Find the number of active Apache clients | ||
activeconn=`pgrep -f "httpd|apache2" | wc -l` | ||
|
||
# Find the MaxClients setting from Apache config file | ||
if [ -f /etc/apache2/apache2.conf ] | ||
then | ||
maxclients=`grep MaxClients /etc/apache2/apache2.conf | grep -v '#' | head -n 1 | awk '{print $2}'` | ||
elif [ -f /etc/httpd/conf/httpd.conf ] | ||
then | ||
maxclients=`grep MaxClients /etc/httpd/conf/httpd.conf | grep -v '#' | head -n 1 | awk '{print $2}'` | ||
fi | ||
|
||
# Find use percentage | ||
maxclientuse=`awk -v ac=$activeconn -v mc=$maxclients 'BEGIN { print ac * 100 / mc }'` | ||
|
||
# Print metric maxclients | ||
echo "metric percent_maxclients float" $maxclientuse | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
|
||
# Example criteria : | ||
# | ||
#if (metric['sysload_avg'] < 6.0 && metric['percent_memory_used'] < 30 && metric['percent_maxclients'] < 30) { | ||
# return new AlarmStatus(CRITICAL, 'Auto Scale servers have been over provisioned. Auto #scale group is being scaled down!'); | ||
#} | ||
# | ||
#return new AlarmStatus(OK, 'Auto Scale servers are being used too heavily for safe scale #down.'); | ||
|
||
|
||
|
||
# Getting time parameters for sar command | ||
endtime=`date | gawk '{ print $4}'` | ||
starttime=`date -d "1 hour ago" | gawk '{ print $4}'` | ||
|
||
|
||
# Find average sysload from last hour | ||
sysloadavg=`sar -q -s $starttime -e $endtime | grep Average | tail -n 1 | tr -s ' ' | gawk '{print $4}'` | ||
|
||
# Print metric system load | ||
echo "metric sysload_avg float" $sysloadavg | ||
|
||
|
||
# Setting proper values for average memory usage from last hour | ||
kbmemfree=`sar -r -s $starttime -e $endtime | grep Average | tail -n 1 | tr -s ' ' | gawk '{print $2}'` | ||
kbmemused=`sar -r -s $starttime -e $endtime | grep Average | tail -n 1 | tr -s ' ' | gawk '{print $3}'` | ||
memtotal=`echo $kbmemfree + $kbmemused | bc` | ||
kbbuffers=`sar -r -s $starttime -e $endtime | grep Average | tail -n 1 | tr -s ' ' | gawk '{print $5}'` | ||
kbcached=`sar -r -s $starttime -e $endtime | grep Average | tail -n 1 | tr -s ' ' | gawk '{print $6}'` | ||
withoutcache=`echo $kbmemused - \($kbbuffers+$kbcached\) | bc` | ||
|
||
# Find use percentage | ||
mempercentage=`echo $withoutcache \* 100 / $memtotal | bc` | ||
|
||
# Print metric memory usage | ||
echo "metric percent_memory_used int" $mempercentage | ||
|
||
|
||
# Find the number of active Apache clients | ||
activeconn=`pgrep -f "httpd|apache2" | wc -l` | ||
|
||
# Find the MaxClients setting from Apache config file | ||
if [ -f /etc/apache2/apache2.conf ] | ||
then | ||
maxclients=`grep MaxClients /etc/apache2/apache2.conf | grep -v '#' | head -n 1 | gawk '{print $2}'` | ||
elif [ -f /etc/httpd/conf/httpd.conf ] | ||
then | ||
maxclients=`grep MaxClients /etc/httpd/conf/httpd.conf | grep -v '#' | head -n 1 | gawk '{print $2}'` | ||
fi | ||
|
||
# Find use percentage | ||
maxclientuse=`echo $activeconn \* 100 / $maxclients | bc` | ||
|
||
echo "metric percent_maxclients int" $maxclientuse |