Skip to content

Instantly share code, notes, and snippets.

@phred
Created April 30, 2010 16:43
Show Gist options
  • Save phred/385455 to your computer and use it in GitHub Desktop.
Save phred/385455 to your computer and use it in GitHub Desktop.
#!/bin/sh
# super-simple request per minute statistics from an Apache log file
# watch it live, now with JSON output!
# while [ /bin/true ]; do sh logstats.sh ; sleep 60 ; done
#
LOGFILE=/var/log/apache2/access_log
HOUR=`date +%H`
MIN=`date +%M`
MIN=`expr $MIN - 1`
if [ $MIN -lt 0 ]; then
MIN=59
HOUR=`expr $HOUR - 1`
if [ $HOUR -lt 0 ]; then
HOUR=23
fi
fi
TIME=$HOUR:$MIN
echo '{'date: \"$TIME\", hits: `grep $TIME: $LOGFILE | wc -l`, load: "[`uptime | awk '{print $10, $11, $12}'`]"'}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment