python-diamond / Diamond

Diamond is a python daemon that collects system metrics and publishes them to Graphite (and others). It is capable of collecting cpu, memory, network, i/o, load and disk metrics. Additionally, it features an API for implementing custom collectors for gathering metrics from almost any source.
http://diamond.readthedocs.org/
MIT License
1.74k stars 601 forks source link

GraphiteHandler sends ntpd.offset value as 0 #115

Open sacharv opened 9 years ago

sacharv commented 9 years ago

moved this issue from the old repo to this one (if I shouldn't have don this p[lease let me know)

I switched from the GraphitePickleHandler to the GraphiteHandler yesterday and noticed that all ntpd offset values where suddenly reported as 0. When looking into this I noticed when I switch back to the GraphitePickleHandler the correct value is being sent, in this case: 0.00162993

ntpdc -c kerninfo pll offset: 0.00162993 s pll frequency: -9.166 ppm maximum error: 0.267084 s estimated error: 0.01685 s status: 2001 pll nano pll time constant: 7 precision: 1e-09 s frequency tolerance: 500 ppm To verify I enabled the ArchiveHandler to see what is being logged by that handler and it also logs 0 while I see the correct value from the GraphitePickleHandler.

Running diamond in debug mode did not show any errors

first observed with version 3.3.510 and still and issue in version 4.0.60

zzl0 commented 9 years ago

@sacharv I have encountered this bug too. I found many collectors didn't specify the precision parameter (it's default value is 0), and when use GraphiteHandler to send metric, the precision will cause this bug, the fractional-part will be dropped.


## The following is copyed from Metric.__repr__ function

# Set the format string
fstring = "%%s %%0.%if %%i\n" % self.precision

# Return formated string
return fstring % (self.path, self.value, self.timestamp)

There are many ways to fix this bug:

precision = 0 if value > 50 else 3

@mattrobenolt @kormoc @rtoma @josegonzalez Can you give me some suggestions to fix this bug ?