initial commit

This commit is contained in:
tim 2021-08-19 10:28:46 +09:30
parent 7a142b9f45
commit ed03c2646e
1 changed files with 38 additions and 0 deletions

38
web-stats.sh Executable file
View File

@ -0,0 +1,38 @@
#!/bin/bash
# Dependencies: vnstat vnstati base64 scp free df date uptime head
name='name'
interface1='eth0'
interface2='wg0'
tempfile="$(mktemp)"
# Remote server ssh configs (must have ssh keys setup)
uname='webserver' # UserName that is used for sshlogin for remote weserver
server='webserver.example.com' # Domain name or IP for remote webserver
path="/var/www/webserver/stats.example.com/$name/index.htm" # Directory where reports are stored on remote webserver
port='22' # SSH port (usually 22)
webstat () {
echo '<!DOCTYPE html><html><head><title>'$name' Stats</title><link rel="stylesheet" href="//static.tjw.moe/styles.css"><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"></head><body><h1>'$name' Stats</h1><hr><br>'
echo '<h2>Time of last report:</h2><pre>'$(date --utc)'</pre><br>'
echo -e '<h2>Disk Usage:</h2><pre>'"$(df -h -x squashfs -x tmpfs -x devtmpfs)"'</pre><br>'
echo '<h2>Memory:</h2><pre>'"$(free -h)"'</pre><br>'
echo '<h2>Uptime:</h2><pre>'"$(uptime)"'</pre><br>'
echo '<h2>Network Usage:</h2>'
echo -e "<img src=\"data:image/png;base64,$(vnstati -i $interface1 -m -o - | base64 -w0)\"><br><img src=\"data:image/png;base64,$(vnstati -i $interface1 -d -o - | base64 -w0)\"><br><img src=\"data:image/png;base64,$(vnstati -i $interface1 -h -o - | base64 -w0)\">"
echo "<pre>$(vnstat -i $interface1 -h | tail -n 9)</pre>"
if [ ! -z $interface2 ]; then
echo -e "<br><br><img src=\"data:image/png;base64,$(vnstati -i $interface2 -m -o - | base64 -w0)\"><br><img src=\"data:image/png;base64,$(vnstati -i $interface2 -d -o - | base64 -w0)\"><br><img src=\"data:image/png;base64,$(vnstati -i $interface2 -h -o - | base64 -w0)\">"
echo "<pre>$(vnstat -i $interface2 -h | tail -n 9)</pre>"
fi
echo '</body></html>'
}
main () {
webstat > $tempfile
scp -C -P $port $tempfile $uname@$server:$path
rm $tempfile
}
main