-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchkload.sh
executable file
·39 lines (34 loc) · 1.98 KB
/
chkload.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# Script to run frequently via cron and report system info during CPU spikes
# Originally written to troubleshoot Moodle performance problems,
# hence the PHP/Apache-centric checks.
#
# For original source and to suggest patches:
# https://github.com/usernamenumber/sysadmisc
#
# Comment these out to skip log dumps
APACHE_ACCESS_LOG="/var/log/apache2/access_log"
APACHE_ERROR_LOG="/var/log/apache2/error_log"
# Exit if another instance is running, or if load average isn't high
[ $(pgrep $(basename $0) | wc -l) -gt 1 ] && exit
U=$(uptime | sed 's,.*load average: ,,' | tr -d , | awk '$1 > .95')
[ -z "$U" ] && exit
echo "Load Average: $U"
echo "*** START ***" ; date ; echo ""
echo "=== PHP INSTANCES ===" ; ps axo '%cpu %mem user pid args' | grep php5 | grep -v grep ; echo ""
for p in $(ps axo '%cpu %mem user pid args' | grep php5 | grep -v grep | awk '{print $4}'); do echo "== LSOF for pid $p =="; lsof -p $p; echo ""; done
echo "=== BIGGEST CPU USERS ===" ; ps axo '%cpu pid args' | tail -n +2 | sort -rn | head ; echo ""
echo "=== BIGGEST MEM USERS ===" ; ps axo '%mem pid args' | tail -n +2 | sort -rn | head ; echo ""
echo "=== TOP ===" ; TERM=vt100 top -b -n 1 ; echo ""
(
(X=$(vmstat -n 10 12) ; echo "=== VMSTAT ===" ; echo "$X" ; echo "")&
(sleep 5; X=$(iostat -dmxz 10 12) ; echo "=== IOSTAT ===" ; echo "$X" ; echo "")&
([ -z "$APACHE_ACCESS_LOG" ] || (X=$(sleep 122 ; tail $APACHE_ACCESS_LOG) ; echo "==== ACCESS LOG ===" ; echo "$X"; echo ""))&
([ -z "$APACHE_ERROR_LOG" ] || (X=$(sleep 124 ; tail $APACHE_ERROR_LOG) ; echo "==== ERROR LOG ===" ; echo "$X"; echo ""))&
wait
)
echo "*** END ***" ; date ; echo ""
echo "=== PHP CHECK ===" ; ps axo '%cpu %mem user pid args' | grep php5 | grep -v grep ; echo ""
echo "=== BIGGEST CPU USERS ===" ; ps axo '%cpu pid args' | tail -n +2 | sort -rn | head ; echo ""
echo "=== BIGGEST MEM USERS ===" ; ps axo '%mem pid args' | tail -n +2 | sort -rn | head ; echo ""
echo "=== TOP ===" ; TERM=vt100 top -b -n 1 ; echo ""