Last active
December 31, 2015 12:19
-
-
Save deathcult/7985012 to your computer and use it in GitHub Desktop.
apache httpd monitor
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/sh | |
| logfile=/tmp/httpd.log | |
| Date=`date '+%Y-%m-%d %H:%M:%S'` | |
| httpd_proc_num=`pgrep httpd | wc -l` | |
| ## httpd进程数少于3,说明有异常,重启服务: | |
| if [ $httpd_proc_num -lt 3 ]; then | |
| echo "$Date httpd process count: $httpd_proc_num, restart it" >> $logfile | |
| service httpd restart >> $logfile 2>> $logfile | |
| fi | |
| if [ $httpd_proc_num -gt 300 ]; then | |
| netinfo=`netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' | tr '\n' '\t'` | |
| echo "$Date httpd process count: $httpd_proc_num, socket: $netinfo" >> $logfile | |
| fi | |
| ## httpd进程数超过1200,重启服务: | |
| if [ $httpd_proc_num -gt 1200 ]; then | |
| netinfo=`netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' | tr '\n' '\t'` | |
| echo "$(date '+%Y-%m-%d %H:%M:%S') httpd process count: $httpd_proc_num, socket: $netinfo. kill all" >> $logfile | |
| for pid in `pgrep httpd` | |
| do | |
| kill -9 $pid | |
| done | |
| echo "$(date '+%Y-%m-%d %H:%M:%S') restart httpd service" >> $logfile | |
| service httpd restart >> $logfile 2>> $logfile | |
| fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment