From ee4dc146259dd2d56b5ab5bc3e18822022214641 Mon Sep 17 00:00:00 2001 From: mrtg Date: Sun, 18 Feb 2024 13:27:36 +0100 Subject: [PATCH] update scripts --- scripts/cryptoReport.pl | 2 +- scripts/getCryptocurrencies.sh | 2 +- scripts/getLXD.sh | 16 ++++++++++++++++ scripts/lxc-stats.sh | 15 --------------- scripts/lxc_index.sh | 2 +- scripts/lxc_mrtg.sh | 8 ++++---- scripts/lxc_rrd-tmpl.sh | 4 ++-- 7 files changed, 25 insertions(+), 24 deletions(-) create mode 100755 scripts/getLXD.sh delete mode 100755 scripts/lxc-stats.sh diff --git a/scripts/cryptoReport.pl b/scripts/cryptoReport.pl index 8d827ef..71ecee6 100755 --- a/scripts/cryptoReport.pl +++ b/scripts/cryptoReport.pl @@ -35,7 +35,7 @@ $v->{GENERATED} = localtime; sub getCurrentPrice { my ($symbol) = @_; my ($start,$step,$name,$data) = RRDs::fetch("${rrdpath}/crypto-${symbol}.rrd","LAST","--start","-10m"); - return($data->[0]->[0]); + return($data->[0]->[0] || 0); } sub getLastWeekValue { diff --git a/scripts/getCryptocurrencies.sh b/scripts/getCryptocurrencies.sh index 4ae7939..427c64c 100755 --- a/scripts/getCryptocurrencies.sh +++ b/scripts/getCryptocurrencies.sh @@ -4,7 +4,7 @@ RRDDIR="/var/www/localhost/rrd" RRDPREFIX="crypto-" TMPLDIR="/var/www/localhost/tmpl" -for c in AAVE ALGO BTC CVC DOGE DNT EOS ETH LRC LTC RAD REN SNX XLM XTZ ZRX; +for c in AAVE ALGO BTC CVC DOGE DNT EOS ETH LRC LTC REN SNX XLM XTZ; do if [[ ! -f "${RRDDIR}/${RRDPREFIX}${c}.rrd" ]]; then diff --git a/scripts/getLXD.sh b/scripts/getLXD.sh new file mode 100755 index 0000000..1b5d493 --- /dev/null +++ b/scripts/getLXD.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +RRDDIR="/var/www/localhost/rrd" +RRDPREFIX="lxc-" +TMPLDIR="/var/www/localhost/tmpl" + +/bin/echo -n > /tmp/lxd.stats + +lxc list 10.5.0.1: -f json | jq -r '.[] | "\(.name) \(.state.cpu.usage) \(.state.memory.usage) \(.state.network.eth0.counters.bytes_received) \(.state.network.eth0.counters.bytes_sent)"' | while read i; +do + echo "$i" | sed 's/null/0/g' >> /tmp/lxd.stats +done + +/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 diff --git a/scripts/lxc-stats.sh b/scripts/lxc-stats.sh deleted file mode 100755 index bcbda52..0000000 --- a/scripts/lxc-stats.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/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 index 414c44c..b7fc535 100755 --- a/scripts/lxc_index.sh +++ b/scripts/lxc_index.sh @@ -16,7 +16,7 @@ echo 'home lxc crypto power LXC - Monitoring
' -curl -s http://10.3.0.1 | sort | while read c; +awk '{print $1}' /tmp/lxd.stats | while read c; do echo "
[$c]
diff --git a/scripts/lxc_mrtg.sh b/scripts/lxc_mrtg.sh index 28e2d50..66b4595 100755 --- a/scripts/lxc_mrtg.sh +++ b/scripts/lxc_mrtg.sh @@ -3,16 +3,16 @@ echo "WorkDir: /var/www/mrtg/rrd" echo "LogFormat: rrdtool" -curl -s http://10.3.0.1 | while read c; +awk '{print $1}' /tmp/lxd.stats | while read c; do echo "# $c" - echo "Target[lxc-$c.cpu]: \`curl -s http://10.3.0.1/$c/CPU; echo 0\`" + echo "Target[lxc-$c.cpu]: \`grep '$c ' /tmp/lxd.stats | awk '{print \$2}'; 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 "Target[lxc-$c.memory]: \`grep '$c ' /tmp/lxd.stats | awk '{print \$3}'; 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 "Target[lxc-$c.net]: \`grep '$c ' /tmp/lxd.stats | awk '{print \$4 \"\n\" \$5}'\`" echo "Title[lxc-$c.net]: [Net] $c" echo "MaxBytes[lxc-$c.net]: 42949672950000000" echo "" diff --git a/scripts/lxc_rrd-tmpl.sh b/scripts/lxc_rrd-tmpl.sh index faf8b85..cabfb8c 100755 --- a/scripts/lxc_rrd-tmpl.sh +++ b/scripts/lxc_rrd-tmpl.sh @@ -3,7 +3,7 @@ DIR="/var/www/mrtg/tmpl" cpuCount=$(grep processor /proc/cpuinfo | wc -l) -curl -s http://10.3.0.1 | while read c; +awk '{print $1}' /tmp/lxd.stats | while read c; do echo "-v memory @@ -29,7 +29,7 @@ CDEF:in=i,$cpuCount,/,10000000,/ AREA:in#CC9A5780 LINE1:in#CC9A57" > "$DIR/lxc-$c.cpu.tmpl" -echo "-v in/up bps +echo "-v in/out bps -t [$c] net --full-size-mode --color=BACK#343637