How is percentile calculated? We've been calculating this manually, since before rrdtool offered a PERCENT function. We discovered that our manual calculation and the one supplied by rrdtool differ by one index. For example (percentile.pl program attached):<br>
<br>[Thu Aug 13, 19:58:41 | 692] $ percentile.pl -v --cf=AVERAGE --ds=ingress --dsi=0 --start=1242864000 --end=1245542399 etkfgl624456ubielg01g.rrd<br><br>percentile.pl using RRDs-1.2019<br>etkfgl624456ubielg01g.rrd:<br>
main::ptile_fetch()<br>
start = 05/21/09<br> end = 06/20/09<br> rows = 31<br> 95% of 31 = 29.45<br> 95th %-ile row index = 29<br> discarded rows of -NaN's = 0<br> row 28 = <b>1126767.40</b><br>
row 29 = <b>1521699.32</b><br> row 30 = 4132277.36<br> manual calculation using fetch() = <b>1521699.32</b><br> PERCENT calculation using graph() = <b>1126767.40</b><br> difference ~ 394931 (26%)<br>
<br><br>Our manual calculation is grabbing row 29 and PERCENT is grabbing row 28.<br><br>From rrdgraph.c:<br><br>case VDEF_PERCENT:{<br> rrd_value_t *array;<br> int field;<br><br> if ((array = malloc(steps * sizeof(double))) == NULL) {<br>
rrd_set_error("malloc VDEV_PERCENT");<br> return -1;<br> }<br><br> for (step = 0; step < steps; step++) {<br> array[step] = data[step * src->ds_cnt];<br> }<br> qsort(array, step, sizeof(double), vdef_percent_compar);<br>
<br><b> field = (steps - 1) * dst->vf.param / 100; /* <======= array index */</b><br> dst->vf.val = array[field];<br> dst->vf.when = 0; /* no time component */<br> free(array);<br>}<br><br>Should the noted line perhaps read as follows?<br>
<br> field = steps * dst->vf.param / 100;<br><br>If not, what am I missing?<br><br>Many thanks,<br>Joshua<br><br>