pnp4nagios extracting averages

Extract average for previous month for given server, metric

#!/bin/bash
HN=$1
DB=$2
CF=$3
if [ "$DB" = "" ]; then
    DB="Memory_Usage"
fi
rrd1="${DB}.rrd"
if [ "$CF" = "" ]; then
    CF="AVERAGE"
fi
PERFDATA_DIR=/var/lib/pnp4nagios/perfdata
cd $PERFDATA_DIR
#
stime=$(date -d "`date +%Y%m01` -1 month" +%s)
etime=$(date -d "`date +%Y%m01`" +%s)
rrdtool fetch $PERFDATA_DIR/$HN/${DB}.rrd $CF -s $stime -e $etime | \
  grep -v nan | \
  awk '{sum+=$2; ++n} END {avg=sum/n; print avg}'
exit

Table of Contents
QR Code
QR Code tech:linux:pnp4nagios_averages (generated for current page)