Skip to content

Instantly share code, notes, and snippets.

@tezvi
Last active July 11, 2017 18:11
Show Gist options
  • Save tezvi/2eac4a95166e972650654ebc384228e6 to your computer and use it in GitHub Desktop.
Save tezvi/2eac4a95166e972650654ebc384228e6 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Author Andrej Vitez
# Utility script for printing very simple Apache and PHP process statistics based on netstat and ps output
function usage() {
echo -e "usage: $0 toolname\n
Available options:
proc - count apache processes
php - count php processes
port80 - Connections to port 80
ssl - Connections to port 443
count - Number of connections to port 80
countssl - Number of connections to port 443
ips - List the remote IPs connecting to your server
all - List the uniq remote IPs and the number of connections from each IP
"
}
if [ -z "$1" ]; then
usage
exit 0
fi
if [ $1 == "proc" ]; then
echo "total processes: " $(ps aux | grep -v 'grep' | grep 'apache\|http' | wc -l)
ps aux | grep -v 'grep' | grep "apache\|httpd"
elif [ $1 == "php" ]; then
php_bin=$(which php)
echo "total processes: " $(ps aux | grep -v 'grep' | grep "$php_bin" | wc -l)
ps aux | grep -v 'grep' | grep "$php_bin"
elif [ $1 == "port80" ]; then
netstat -alntp | grep ":80"
elif [ $1 == "ssl" ]; then
netstat -alntp | grep ":443"
elif [ $1 == "count" ]; then
netstat -alntp | grep ":80" | wc -l
elif [ $1 == "countssl" ]; then
netstat -alntp | grep ":443" | wc -l
elif [ $1 == "ips" ]; then
netstat -alntp | awk '{print $5}' | cut -d: -f1 | sort
elif [ $1 == "all" ]; then
netstat -alntp | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nk 1
else
usage
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment