From a0464a329f7959e7283a024124bc1f7f126034d3 Mon Sep 17 00:00:00 2001 From: Keith Whyte Date: Tue, 28 Mar 2023 08:40:38 +0200 Subject: [PATCH] improve check for empty rrd --- modules/rhizo_base/files/collectd-hack | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/rhizo_base/files/collectd-hack b/modules/rhizo_base/files/collectd-hack index 22a490d..e76e396 100644 --- a/modules/rhizo_base/files/collectd-hack +++ b/modules/rhizo_base/files/collectd-hack @@ -13,8 +13,15 @@ is_empty () { exit fi if [ "$_o" == "" -o "$_o" == "0.0000000000e+00" -o "$_o" == "NaN" ] ;then - debug $1 "$2 is empty" - return 1 + _o=`rrdtool xport DEF:A=/var/lib/collectd/rrd/$(hostname -f)/$2:value:LAST XPORT:A -s -1min -m10 | xmllint --xpath 'string(xport/data/row[v>0]/v)' -` + if [ $? != 0 ] ; then + echo "Error. exiting." + exit + fi + if [ "$_o" == "" -o "$_o" == "0.0000000000e+00" -o "$_o" == "NaN" ] ;then + debug $1 "$2 is empty" + return 1 + fi fi if [ "$1" == "ne" ] ; then echo "$2 has data"