-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscaledown_check.sh.longver
64 lines (43 loc) · 2.51 KB
/
scaledown_check.sh.longver
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/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