Created
November 30, 2010 05:08
-
-
Save PhirePhly/721191 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# Kenneth Finnegan, 2010 | |
# kennethfinnegan.blogspot.com | |
# | |
# status.sh - CGI script to print current Chumby health and statistics | |
# | |
# Install in web server cgi-bin/ folder | |
# Schedule with cron to prevent stale cache: | |
# 0 * * * * /.../cgi-bin/status.sh > /dev/null | |
# | |
# Revision History: | |
# 2010 11 28: Initial implementation | |
# 2010 11 29: Implement status caching to prevent excessive CPU usage | |
# 2010 12 03: Fix ifconfig status to automatically switch ifs and | |
# to not print lo status. | |
# Moved cache to /tmp/ | |
# 2010 12 05: Fixed header spacing to match updated ACC_TOTAL output from | |
# logrotate.sh | |
# Set file location variables | |
STUBDIR="/mnt/storage/lighty/cgi-bin" | |
CACHEDIR="/tmp" | |
LOGDIR="/mnt/storage/logs" | |
STATCACHE="$CACHEDIR/cgi.cache.status" | |
ACC_TODAY="$LOGDIR/lighttpd.access.log" | |
ACC_TOTAL="$LOGDIR/lighttpd.access.log.total" | |
ANALYTICS="$STUBDIR/analytics.html.part" | |
# Calculate seconds since epoch for cache and current time | |
if [ -f $STATCACHE ]; then | |
CACHEAGE=`stat -c %Y $STATCACHE` | |
else | |
touch $STATCACHE | |
CACHEAGE=0 | |
fi | |
NOW=`date +%s` | |
# Print cache to current request | |
echo "Content-type: text/html" | |
echo "" | |
echo "<html><head><title>Chumby Status</title></head>" | |
echo "<body>" | |
cat $ANALYTICS | |
echo "<pre>" | |
echo " ---- Current Chumby Status ----</pre>" | |
echo '<a href="http://kennethfinnegan.blogspot.com/2010/11/chumby-status-cgi-script.html"><pre>How this web page works</pre></a><br><pre>' | |
cat $STATCACHE | |
echo "</pre>" | |
echo "<pre>" | |
cat /etc/motd | |
echo "</pre>" | |
echo "</body>" | |
# Generate new status cache if older than 20 seconds | |
if [ `expr $NOW - $CACHEAGE` -gt 20 ] | |
then | |
cat > $STATCACHE << EOF | |
`awk '{print "Load avg (1/5/15 min): "$1" "$2" "$3}' /proc/loadavg` | |
HTTP requests processed since midnight: `wc -l < $ACC_TODAY` | |
`echo -e "DATE\t UNIQUIE\tTOTAL"` | |
`tail -n 7 $ACC_TOTAL` | |
`df -m | grep -v -e none -e tmpfs` | |
`free | head -n 2` | |
`ifconfig | grep -e Link -e inet -e bytes | grep -A 3 -e eth0 -e wlan0` | |
Report generated at: `date "+%F %k:%M:%S %Z"` | |
EOF | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment