[collectd] Strange Time value in notification test

George B. list1 at gir.me.uk
Thu Jun 19 00:54:02 CEST 2014


On 18/06/14 21:54, Dan Fandrich wrote:
> On Wed, Jun 18, 2014 at 06:50:44PM +0100, George B. wrote:
>> I have configured a simple test notification using the Exec plugin. This works, however, the Time value in the notification message is changed into something strange (1.307) - can anyone suggest why this is happening?
>
> Maybe it's a coincidence, but if 1403113649 were in bytes, it would be exactly
> 1.307 GiB.  Maybe a conversion gone wrong somewhere?

You are right!

Looking at the source code:

In src/exec.c we have:

----
   fprintf (fh,
       "Severity: %s\n"
       "Time: %.3f\n",
       severity, CDTIME_T_TO_DOUBLE (n->time));
----

In src/utils_time.h we have:

----
#define CDTIME_T_TO_DOUBLE(t) (((double) (t)) / 1073741824.0)
----

(and 1073741824 == 1024^3)

There is also a CDTIME_T_TO_TIME_T macro defined, which I'm guessing was supposed to be used somewhere before the printf got the value - looks like this might be a bug?

src/utils_time.h also provides this explanation for the conversion:

----
/*
* "cdtime_t" is a 64bit unsigned integer. The time is stored at a 2^-30 second
* resolution, i.e. the most significant 34 bit are used to store the time in
* seconds, the least significant bits store the sub-second part in something
* very close to nanoseconds. *The* big advantage of storing time in this
* manner is that comparing times and calculating differences is as simple as
* it is with "time_t", i.e. a simple integer comparison / subtraction works.
*/
----


George



More information about the collectd mailing list