What is going on… or, why is the server slow when your not around.
I’ve been called in the middle of the night with “the server is slow” being the emphasis of the call. Sometimes it’s not obvious using standard utilties, or sometimes it only happens during certain times.
I’ve used a simple script to eliminate this issue, and run it from cron every minute or 5 minutes to give me output on whats going on with the system.
This is ment for temporary use only, or at least make sure you clear the files every once and a while, because they get pretty big, thus I wrote a cyclecheck script and even a cyclerebootcheck script to see why a machine rebooted.
check script:
#!/bin/sh
echo “——————-” >> /data/`/bin/hostname`.load
echo “——————-” >> /data/`/bin/hostname`.psaux
/bin/date >> /data/`/bin/hostname`.load
/bin/date >> /data/`/bin/hostname`.psaux
/usr/bin/w >> /data/`/bin/hostname`.load
/usr/bin/w >> /data/`/bin/hostname`.psaux
ps -awux >> /data/`/bin/hostname`.psaux
cyclecheck script:
mv /data/`/bin/hostname`.psaux /data/`/bin/hostname`.psauwx.old
mv /data/`/bin/hostname`.load /data/`/bin/hostname`.load.old
cyclerebootcheck script:
mv /data/`/bin/hostname`.psaux /data/`/bin/hostname`.psauwx.reboot
mv /data/`/bin/hostname`.load /data/`/bin/hostname`.load.reboot
echo `hostname` rebooted `date` | mail pageadmin@site.com
install script:
echo “*/1 * * * * root /root/scripts/check” >> /etc/crontab
echo “1 0 * * * root /root/scripts/cyclecheck” >> /etc/crontab
echo “/root/scripts/cyclerebootcheck” /etc/rc.local
killall -HUP crond
I place them all in /root/scripts and chmod -R 755 /root/scripts, then run /root/scripts/install to place these things into the crontab.
Then you can view the output in /data/hostname-of-server.load or /data/hostname-of-server.psaux each with a timestamped entry.
——————-
Wed Nov 2 00:02:00 EDT 2005
12:02AM up 123 days, 23:45, 0 users, load averages: 0.15, 0.28, 0.24
(what users are logged on listed here)
USER TTY FROM LOGIN@ IDLE WHAT
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 24498 0.0 0.0 984 224 ?? R 12:02AM 0:00.00 ps -awux
It works at least.. edit for directories you need, this is written for freebsd in this case.