Created
October 9, 2018 10:33
-
-
Save boxrick/06b1e5ec2903a96e1e441af18043fdff to your computer and use it in GitHub Desktop.
Get stats
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
#!/bin/bash | |
# Small script to check max processes and apache max memory usage | |
max_mem=0 | |
max_processes=0 | |
file_store='./max_values.txt' | |
touch $file_store | |
source $file_store | |
cleanup () | |
{ | |
echo Max memory value found ${max_mem} | |
echo Max processes value found ${max_processes} | |
echo "max_mem=${max_mem}" > $file_store | |
echo "max_processes=${max_processes}" >> $file_store | |
exit 0 | |
} | |
trap cleanup SIGINT SIGTERM | |
while [ 1 ] | |
do | |
# Sleep for a short period | |
sleep 0.1 | |
# Get current apache memory and processes | |
apache_memory=( $( ps aux | grep 'httpd' | grep -v grep | awk '{print $6}') ) | |
apache_processes=$(ps aux --no-heading | grep httpd | grep -v grep | wc -l) | |
# Check processes and memory usage against historical values | |
for i in "${apache_memory[@]}" | |
do | |
if [ "$i" -gt "$max_mem" ] | |
then | |
echo "New max memory value found ${i}" | |
max_mem=$i | |
fi | |
done | |
if [ "$apache_processes" -gt "$max_processes" ] | |
then | |
echo "New max apache processes found ${apache_processes}" | |
max_processes=$apache_processes | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment