Skip to content

Instantly share code, notes, and snippets.

@whiteinge
Created March 19, 2012 02:55
Show Gist options
  • Save whiteinge/2091989 to your computer and use it in GitHub Desktop.
Save whiteinge/2091989 to your computer and use it in GitHub Desktop.
Grab RAM usage, load, and Apache processes
#!/usr/bin/env bash
# List stats helpful for tuning Apache
APIDS=$(pgrep apache | wc -l)
LOADAVG=$(< /proc/loadavg)
# hopefully the prefork section is the first match...
MAXCLIENT=$(grep -m 1 "^MaxClient" /etc/apache2/apache2.conf | cut -d' ' -f 2)
free -mt | awk '
BEGIN {
OFS="\t"
}
# Get total RAM
/^Mem/ { total = $2 }
# Get used RAM
/^-/ { used = $3 }
END {
split(loadavg, load, " ")
# if ( --no-headers )
# print "Num Apache Procs", "Used/Total Memory", "Load"
print apids "/" maxclient, " ", " ", used "/" total " KB", " ", load[1] " " load[2] " " load[3]
}' apids=$APIDS "loadavg=$LOADAVG" maxclient=$MAXCLIENT
Copy link

ghost commented Mar 19, 2012

Debian based:
APIDS=$(pgrep apache2 | wc -l)
MAXCLIENT=$(awk '/^[[:space:]]+MaxClients/ { print $2 }' /etc/apache2/apache2.conf)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment