Page 1 of 1

PNP4Nagios - 95th percentile

Posted: Wed Nov 09, 2016 2:49 am
by joshv
Does anyone know how to configure the 95th percentile calculation in a PNP4Nagios template? Yes, I am using XI (all I had to do to get Nagios Core to see PNP graphs was put a few URL's in the host and service templates).

So, I'd like to add the 95th percentile calculation into a graph template. The following is "working", but not providing the correct calculation:

$def[$i] = "DEF:var1=$rrdfile:$DS[$i]:AVERAGE ";
$def[$i] .= "CDEF:var1_pct=var1,0.95,/ ";
$def[$i] .= "GPRINT:var1_pct:AVERAGE:\"%3.4lf $UNIT[$i] 95th_Percentile \\n\" ";

Which does put a value properly on the graph, but it is really calculating 95% of the AVERAGE of var1, not the 95th percentile. 95th percentile is calculated by first ordering the dataset from greatest to least, second dropping the top 5% of the data, then finally the 95th percentile is the MAX value of the remaining data.

Can anyone here help me do this in PNP4Nagios? Or recommend the best forum for an answer (should I go to RRD or PNP4Nagios)?

TIA!
-Josh

Re: PNP4Nagios - 95th percentile

Posted: Wed Nov 09, 2016 10:15 am
by tmcdonald
joshv wrote:Can anyone here help me do this in PNP4Nagios? Or recommend the best forum for an answer (should I go to RRD or PNP4Nagios)?
Either of those would be preferable since we did not write and do not maintain/support PNP4Nagios.

Re: PNP4Nagios - 95th percentile

Posted: Wed Nov 09, 2016 5:15 pm
by joshv
I solved this. There were some other posts that helped, so this isn't original material, but the formatting for files in /usr/local/nagios/share/templates.dist is valid for Nagios XI 5.2.9 and/or Nagios Core 4.1.1:

Here are the relevant updates to a copy of the default.php. When the .php file is named for a check command you want to calculate the 95th percentile of, it will display the result on the legend, and draw a horizontal line on the graph to label the value.

.....snip.....
$def[$i] = "DEF:var1=$rrdfile:$DS[$i]:AVERAGE ";
$def[$i] .= "AREA:var1" . _AREA . ":\"$NAME[$i] \" ";
$def[$i] .= "LINE1:var1" . _LINE . ":\"\" ";
$def[$i] .= "VDEF:var1_pct=var1,95,PERCENT ";
$def[$i] .= "GPRINT:var1:LAST:\"%6.4lf $UNIT[$i] LAST \" ";
$def[$i] .= "GPRINT:var1:MAX:\"%6.4lf $UNIT[$i] MAX \" ";
$def[$i] .= "GPRINT:var1:AVERAGE:\"%6.4lf $UNIT[$i] AVERAGE \\n\" ";
$def[$i] .= "HRULE:var1_pct#ff8080:95th ";
$def[$i] .= "GPRINT:var1_pct:\"%6.4lf $UNIT[$i] 95th_percentile \\n\" ";
......snip......

I have seen several requests for 95th Percentile calculations in Nagios graphs as I searched the forum - so I hope this helps someone else use PNP4Nagios / RRD. Note that this does not update the new Highpoint graphs in Nagios XI - but you can still access Nagios Core PNP graphs by browsing /nagios instead of /nagiosxi.

I only needed to add the following to my Host & Service Templates so that the Action URL icon appears and works properly in the GUI:
Hosts - Action URL:
/nagios/pnp/index.php?host=$HOSTNAME$

Services - Action URL:
/nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$

-Josh

Re: PNP4Nagios - 95th percentile

Posted: Thu Nov 10, 2016 11:59 am
by avandemore
@joshv Good work, thanks for sharing. Locking this thread to preserve the answer.