Skip to content

Instantly share code, notes, and snippets.

@first-developer
Created July 29, 2015 11:37
Show Gist options
  • Save first-developer/4b3696d7ff51798faead to your computer and use it in GitHub Desktop.
Save first-developer/4b3696d7ff51798faead to your computer and use it in GitHub Desktop.
Return the average memory size of httpd processes running on a server
#!/bin/bash
# --------------------------------------------------------------------------
# Script : httpd_avg_mem_size
# Created on : 27/07/2015
# Copyright : (c) 2015 - fdsolutions
# --------------------------------------------------------------------------
usage(){
echo "Usage: httpd_avg_mem_size [-s SIZE]
-s SIZE : Set the memory size to Kilobyte(K), Megabyte(M), Gigabyte(K)
"
}
get_httpd_mem_size() {
local size=${1:-K}
local avgMemSize="$(ps aux | grep 'httpd' | awk '{print $6;}' | awk '{avg += ($1 - avg) / NR;} END {print avg;}')"
if [[ $? != "0" ]]; then
return 1
fi;
case $size in
M) memSize=$(echo $avgMemSize | awk '{print $1/1024}' );;
G) memSize=$(echo $avgMemSize | awk '{print $1/1024/1024}' );;
*) memSize=$avgMemSize ;;
esac
echo $memSize
return 0
}
unset OPTIND
while getopts ":s:" option; do
case $option in
s) optionSize=$OPTARG ;;
esac
done && shift $(($OPTIND - 1))
get_httpd_mem_size $optionSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment