[collectd] [PATCH] fix xff excessive rounding

Francois-Xavier Bourlet fx at dotcloud.com
Fri Aug 5 01:26:56 CEST 2011


When generating arguments for rrd_create, the previous
format string "%.1f", was rounding up the value too aggressively.

ex: for xff==0.9999 the result would be -> 1.0 (invalid value for xff!)

The new format string is "%.10f", which lead up to 10 digits after the
dot, enough to be close to the double type limit, and so handling
correctly the previous example.
 src/utils_rrdcreate.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/utils_rrdcreate.c b/src/utils_rrdcreate.c
index 5b13238..8547702 100644
--- a/src/utils_rrdcreate.c
+++ b/src/utils_rrdcreate.c
@@ -156,7 +156,7 @@ static int rra_get (char ***ret, const value_list_t *vl,
/* {{{ */
       if (rra_num >= rra_max)

-      status = ssnprintf (buffer, sizeof (buffer), "RRA:%s:%3.1f:%u:%u",
+      status = ssnprintf (buffer, sizeof (buffer), "RRA:%s:%3.10f:%u:%u",
           rra_types[j], cfg->xff, cdp_len, cdp_num);

       if ((status < 0) || ((size_t) status >= sizeof (buffer)))

François-Xavier Bourlet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.verplant.org/pipermail/collectd/attachments/20110804/7d03ae70/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-fix-xff-excessive-rounding.patch
Type: application/octet-stream
Size: 1235 bytes
Desc: not available
URL: <http://mailman.verplant.org/pipermail/collectd/attachments/20110804/7d03ae70/attachment.obj>

More information about the collectd mailing list