TJW-Tech Wiki

Mandatory Happiness

User Tools

Site Tools


scripts:bash:web-stats

web-stats v1.6

2016-01-18

#!/bin/bash
 
# Dependencies: vnstat vnstati base64 scp free df date uptime
 
name='TIMOTHY-E4300'
interface='wlan0'
 
# Remote server ssh configs (must have ssh keys setup)
uname='webserver'  # UserName that is used for sshlogin for remote weserver
server='vps3.tjw.moe'  # Domain name or IP for remote webserver
path="/home/webserver/www/stats.tjw.moe/$name/index.htm"  # Directory where reports are stored on remote webserver
 
echo '<!DOCTYPE html>'"<html><head><title>$name.TJW.MOE Stats</title></head><body style=\"background:#000;color:#00ff00;\"><h1>$name.TJW.MOE Stats</h1><hr><br>" > /tmp/webvnstat.tmp
echo '<h2>Time of last report:</h2>' >> /tmp/webvnstat.tmp
echo "<pre>$(date)</pre><br>" >> /tmp/webvnstat.tmp
echo '<h2>Disk Usage:</h2>' >> /tmp/webvnstat.tmp
echo -e "<pre>$(df -h | grep Filesystem)\n$(df -h | grep \/dev\/)</pre><br>" >> /tmp/webvnstat.tmp
echo '<h2>Memory:</h2>' >> /tmp/webvnstat.tmp
echo "<pre>$(free -h)</pre><br>" >> /tmp/webvnstat.tmp
echo '<h2>Uptime:</h2>' >> /tmp/webvnstat.tmp
echo "<pre>$(uptime)</pre><br>" >> /tmp/webvnstat.tmp
echo '<h2>Network Usage:</h2>' >> /tmp/webvnstat.tmp
echo -e "<img src=\"data:image/png;base64,$(vnstati -i $interface -m -o /tmp/vnstatimonth.png ; base64 -w0 /tmp/vnstatimonth.png ; rm /tmp/vnstatimonth.png)\"><br><img src=\"data:image/png;base64,$(vnstati -i $interface -d -o /tmp/vnstatiday.png ; base64 -w0 /tmp/vnstatiday.png ; rm /tmp/vnstatiday.png)\"><br><img src=\"data:image/png;base64,$(vnstati -i $interface -h -o /tmp/vnstatihour.png ; base64 -w0 /tmp/vnstatihour.png ; rm /tmp/vnstatihour.png)\">" >> /tmp/webvnstat.tmp
echo "<pre>$(vnstat -i $interface -h | tail -n 9)</pre>" >> /tmp/webvnstat.tmp
echo '</body></html>' >> /tmp/webvnstat.tmp
scp -C /tmp/webvnstat.tmp $uname@$server:$path
rm /tmp/webvnstat.tmp

Demo

scripts/bash/web-stats.txt · Last modified: 2016/02/20 22:17 (external edit)