Skip to content

Instantly share code, notes, and snippets.

@jonjensen
Created November 17, 2012 02:38
Show Gist options
  • Save jonjensen/4092830 to your computer and use it in GitHub Desktop.
Save jonjensen/4092830 to your computer and use it in GitHub Desktop.
Simple script to collect server statistics
#!/bin/bash
# sample command to purge collected stats older than 6 days in e.g. a crontab:
# find /var/tmp/stats -mindepth 1 -maxdepth 1 -type d -mtime +6 -print0 | xargs -r -0 rm -rf
trap "exit 1" INT
cd /var/tmp || exit 1
[ "`id -u`" = 0 ] || {
echo "This must be run as root to be very useful. Aborting." >&2
exit 1
}
while :;
do
eval `date '+date=%Y%m%d hour=%H minsec=%M%S'`
dir=stats/$date/$hour/$minsec
mkdir -p $dir
pushd $dir || exit 1
ps auxww | gzip -c > ps-auxww.gz
w > w
free > free
vmstat > vmstat
iostat > iostat
lsof | gzip -c > lsof.gz
popd
sleep 30
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment