Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tech:linux:pnp4nagios_averages [2017/01/04 06:25] (current)
Line 1: Line 1:
 +====== pnp4nagios extracting averages ======
 +Extract average for previous month for given server, metric
 +<code bash>
 +#!/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
 +</​code>​
  

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