[collectd] Strange Time value in notification test
Hello, 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? root@croaker:~# cat /etc/collectd/collectd.conf LoadPlugin exec Plugin exec NotificationExec www-data /srv/www/notify.sh Exec www-data /srv/www/test.sh /Plugin root@croaker:~# cat /srv/www/test.sh #!/bin/bash MESSAGE=Some random text SEVERITY=warning TIME=`date +%s` LINE=PUTNOTIF message=\$MESSAGE\ severity=$SEVERITY time=$TIME echo $LINE /tmp/out.txt echo $LINE root@croaker:~# cat /srv/www/notify.sh #!/bin/bash echo $(cat) /tmp/out.txt root@croaker:~# tail -n 5 /tmp/out.txt PUTNOTIF message=Some random text severity=warning time=1403113649 Severity: WARNING Time: 1.307 Some random text I am running collectd 5.1.0 (Debian Wheezy). Thanks, George ___ collectd mailing list collectd@verplant.org http://mailman.verplant.org/listinfo/collectd
Re: [collectd] Strange Time value in notification test
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? Dan ___ collectd mailing list collectd@verplant.org http://mailman.verplant.org/listinfo/collectd
Re: [collectd] Strange Time value in notification test
In utils_time.h #define CDTIME_T_TO_TIME_T(t) ((time_t) ((t) / 1073741824)) The problem is that when it parses the time in PUTNOTIF it's not converted from a timestamp to cdtime_t Fixed in https://github.com/collectd/collectd/pull/644 On Wed, Jun 18, 2014 at 10:54 PM, Dan Fandrich d...@coneharvesters.com 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? Dan ___ collectd mailing list collectd@verplant.org http://mailman.verplant.org/listinfo/collectd ___ collectd mailing list collectd@verplant.org http://mailman.verplant.org/listinfo/collectd
Re: [collectd] Strange Time value in notification test
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 ___ collectd mailing list collectd@verplant.org http://mailman.verplant.org/listinfo/collectd
Re: [collectd] Strange Time value in notification test
On 18/06/14 23:52, Manuel Luis SanmartĂn Rozada wrote: In utils_time.h #define CDTIME_T_TO_TIME_T(t) ((time_t) ((t) / 1073741824)) The problem is that when it parses the time in PUTNOTIF it's not converted from a timestamp to cdtime_t LOL you beat me to the analysis by a few seconds! Fixed in https://github.com/collectd/collectd/pull/644 Thanks! :-) Now just have to wait a few years before that fix makes it into Debian Stable... :-( George ___ collectd mailing list collectd@verplant.org http://mailman.verplant.org/listinfo/collectd