Created
May 11, 2011 10:11
-
-
Save amr/966236 to your computer and use it in GitHub Desktop.
Tells you the average size of your Apache processes
This file contains hidden or 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 | |
# | |
# Tells you the average size of your Apache processes | |
# It must run on a live apache server (unless you know what you are doing). | |
# It requires pmap, /proc, ps, grep, awk, sed and bc, | |
# | |
# Written by: Amr Mostafa" <[email protected]> | |
# | |
# Courtesy of Egypt Development Centre (c). | |
# Licensed under GPL v3 or later. | |
# | |
# =| USAGE |=================================================================== | |
# | |
# echo <parent-apache-process-id> | avg-apache-process.sh | |
# | |
# In Debian systems, that translates to: | |
# | |
# cat /var/run/apache2.pid | max-clients.sh | |
# | |
# In RedHat systems, that translates to: | |
# | |
# cat /var/run/httpd.pid | max-clients.sh | |
# | |
# Enjoy! | |
if [ ! "$UID" -eq "0" ] | |
then echo "WARNING: This should be run as root." >&2; fi | |
read APACHE_PID | |
MEM_TOTAL=$(cat /proc/meminfo | awk '/MemTotal/ {print $2}') | |
# Before someone WTFs the next ps line.. | |
# h: omit header | |
# opid: only print 'pid' column. | |
# ppid: print only processes whose parent process' id equal to given pid. | |
HTTPD_AVG_MEM=$(ps --ppid $APACHE_PID h opid | | |
# Use pmap to retrieve process memory consumption | |
while read pid; do | |
pmap -d $pid | | |
tail -n1 | | |
sed 's/.*private: \([0-9]*\).*/\1/'; | |
done | | |
# Get average | |
awk '{ SUM += $1 } END {print SUM/NR}') | |
echo "scale=2; $HTTPD_AVG_MEM / 1024" | bc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment