add lxc statistics and graphs scripts

This commit is contained in:
root 2020-04-18 20:39:12 +02:00
parent 03189601ce
commit a781e83669
5 changed files with 118 additions and 0 deletions

15
scripts/lxc-stats.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/sh
DIR=/var/www/lxc-api/htdocs
lxc-ls -1 --running > "$DIR/index.html"
lxc-ls -1 --running | while read c;
do
[ ! -d "$DIR/$c" ] && mkdir "$DIR/$c";
t="$(lxc-info -H -S -n $c)"
for i in CPU Memory RX TX
do
echo -e "$t" | grep "$i " | awk -F: '{print $2}' | sed 's/^[ ]*//g' > "$DIR/$c/$i"
done
done

33
scripts/lxc_index.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/sh
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>MRTG Index Page</TITLE>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-15" >
<META HTTP-EQUIV="Refresh" CONTENT="600" >
<META HTTP-EQUIV="Cache-Control" content="no-cache" >
<META HTTP-EQUIV="Pragma" CONTENT="no-cache" >
<LINK HREF="/cgi-bin/details.pl?graph=favicon.ico" rel="shortcut icon" >
<LINK rel="stylesheet" type="text/css" HREF="style.css"/>
</HEAD>
<BODY>
<H1><a href="/">home</a>&nbsp;<a href="/lxc.html">lxc</a>&nbsp;<a href="/crypto.html">crypto</a>&nbspLXC - Monitoring</H1>
<DIV>
'
curl -s http://10.3.0.1 | while read c;
do
echo "<DIV>
<B>[$c]</B><BR/>
<A HREF=\"/cgi-bin/details.pl?graph=lxc-$c.net\"><IMG ALT=\"lxc-$c.net\" SRC=\"/cgi-bin/graph.pl?width=540&height=200&graph=lxc-$c.net\"></A>
<A HREF=\"/cgi-bin/details.pl?graph=lxc-$c.cpu\"><IMG ALT=\"lxc-$c.cpu\" SRC=\"/cgi-bin/graph.pl?width=540&height=200&graph=lxc-$c.cpu\"></A>
<A HREF=\"/cgi-bin/details.pl?graph=lxc-$c.memory\"><IMG ALT=\"lxc-$c.memory\" SRC=\"/cgi-bin/graph.pl?width=540&height=200&graph=lxc-$c.memory\"></A>
</DIV>"
done
echo "
</DIV>
</BODY>
</HTML>
"

19
scripts/lxc_mrtg.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
echo "WorkDir: /var/www/mrtg/rrd"
echo "LogFormat: rrdtool"
curl -s http://10.3.0.1 | while read c;
do
echo "# $c"
echo "Target[lxc-$c.cpu]: \`curl -s http://10.3.0.1/$c/CPU; echo 0\`"
echo "Title[lxc-$c.cpu]: [CPU] $c"
echo "MaxBytes[lxc-$c.cpu]: 42949672950000000"
echo "Target[lxc-$c.memory]: \`curl -s http://10.3.0.1/$c/Memory; echo 0\`"
echo "Title[lxc-$c.memory]: [Memory] $c"
echo "MaxBytes[lxc-$c.memory]: 42949672950000000"
echo "Target[lxc-$c.net]: \`curl -s http://10.3.0.1/$c/RX http://10.3.0.1/$c/TX\`"
echo "Title[lxc-$c.net]: [Net] $c"
echo "MaxBytes[lxc-$c.net]: 42949672950000000"
echo ""
done

46
scripts/lxc_rrd-tmpl.sh Executable file
View File

@ -0,0 +1,46 @@
#!/bin/sh
DIR="/var/www/mrtg/tmpl"
curl -s http://10.3.0.1 | while read c;
do
for m in cpu memory
do
echo "-v $m
-t [$c] $m
--full-size-mode
--color=BACK#343637
--color=CANVAS#F0F0F0
--color=FONT#F0F0F0
--font=TITLE:12:DejaVu Bold
DEF:in=/var/www/mrtg/rrd/lxc-$c.$m.rrd:ds0:AVERAGE
AREA:in#CC9A5780
LINE1:in#CC9A57" > "$DIR/lxc-$c.$m.tmpl"
done
echo "-v in/up bps
-t [$c] net
--full-size-mode
--color=BACK#343637
--color=CANVAS#F0F0F0
--color=FONT#F0F0F0
--font=TITLE:12:DejaVu Bold
DEF:rx=/var/www/mrtg/rrd/lxc-$c.net.rrd:ds0:AVERAGE
DEF:tx=/var/www/mrtg/rrd/lxc-$c.net.rrd:ds1:AVERAGE
CDEF:RX=rx,8,*
CDEF:TX=tx,8,*
COMMENT: max. avg. min. cur.\n
AREA:RX#CC9A5760:Rx
GPRINT:RX:MAX:%6.2lf %sbps
GPRINT:RX:AVERAGE:%6.2lf %sbps
GPRINT:RX:MIN:%6.2lf %sbps
GPRINT:RX:LAST:%6.2lf %sbps\n
LINE1:TX#2EA349:Tx
GPRINT:TX:MAX:%6.2lf %sbps
GPRINT:TX:AVERAGE:%6.2lf %sbps
GPRINT:TX:MIN:%6.2lf %sbps
GPRINT:TX:LAST:%6.2lf %sbps\n
LINE1:0#000000" > "$DIR/lxc-$c.net.tmpl"
done

5
scripts/lxc_update.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
/usr/bin/lxc_index.sh > /var/www/localhost/htdocs/lxc.html
/usr/bin/lxc_mrtg.sh > /var/www/localhost/config/lxc.cfg
/usr/bin/lxc_rrd-tmpl.sh