From a781e836696be1bcc9da8a25bb086126777dfc6f Mon Sep 17 00:00:00 2001 From: root <root@mrtg.local> Date: Sat, 18 Apr 2020 20:39:12 +0200 Subject: [PATCH] add lxc statistics and graphs scripts --- scripts/lxc-stats.sh | 15 ++++++++++++++ scripts/lxc_index.sh | 33 +++++++++++++++++++++++++++++ scripts/lxc_mrtg.sh | 19 +++++++++++++++++ scripts/lxc_rrd-tmpl.sh | 46 +++++++++++++++++++++++++++++++++++++++++ scripts/lxc_update.sh | 5 +++++ 5 files changed, 118 insertions(+) create mode 100755 scripts/lxc-stats.sh create mode 100755 scripts/lxc_index.sh create mode 100755 scripts/lxc_mrtg.sh create mode 100755 scripts/lxc_rrd-tmpl.sh create mode 100755 scripts/lxc_update.sh diff --git a/scripts/lxc-stats.sh b/scripts/lxc-stats.sh new file mode 100755 index 0000000..bcbda52 --- /dev/null +++ b/scripts/lxc-stats.sh @@ -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 diff --git a/scripts/lxc_index.sh b/scripts/lxc_index.sh new file mode 100755 index 0000000..17289cd --- /dev/null +++ b/scripts/lxc_index.sh @@ -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> <a href="/lxc.html">lxc</a> <a href="/crypto.html">crypto</a> LXC - 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> +" diff --git a/scripts/lxc_mrtg.sh b/scripts/lxc_mrtg.sh new file mode 100755 index 0000000..28e2d50 --- /dev/null +++ b/scripts/lxc_mrtg.sh @@ -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 diff --git a/scripts/lxc_rrd-tmpl.sh b/scripts/lxc_rrd-tmpl.sh new file mode 100755 index 0000000..3ff8fa6 --- /dev/null +++ b/scripts/lxc_rrd-tmpl.sh @@ -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 diff --git a/scripts/lxc_update.sh b/scripts/lxc_update.sh new file mode 100755 index 0000000..7da8bae --- /dev/null +++ b/scripts/lxc_update.sh @@ -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