Fix the timestamps set by the collectd plugin

Timestamps should be in microseconds instead of milliseconds.

Fix #1075. Close #1076
pull/1076/merge
David Norton 2014-10-29 17:11:19 -04:00 committed by John Shahid
parent 1b50c7d310
commit a428042899
3 changed files with 9 additions and 6 deletions

View File

@ -9,6 +9,9 @@
- [Issue #996](https://github.com/influxdb/influxdb/issues/996). Fill should
fill the time range even if no points exists in the given time range
- [Issue #1076](https://github.com/influxdb/influxdb/issues/1076). Fix
the timestamps of data points written by the collectd plugin. (Thanks,
@renchap for reporting this bug)
## v0.8.5 [2014-10-27]

View File

@ -110,13 +110,13 @@ func (s *Server) HandleSocket(socket *net.UDPConn) {
}
func packetToSeries(p *collectd.Packet) []*protocol.Series {
// Prefer high resolution timestamp (TimeHR is 2^-30 seconds,
// convert to milliseconds for influxdb)
uts := (p.TimeHR >> 30) * 1000
// Prefer high resolution timestamp. TimeHR is 2^-30 seconds, so shift
// right 30 to get seconds then convert to microseconds for InfluxDB
uts := (p.TimeHR >> 30) * 1000 * 1000
// Fallback on unix timestamp if high res is 0
if uts == 0 {
uts = p.Time * 1000
uts = p.Time * 1000 * 1000
}
// Collectd time is uint64 but influxdb expects int64

View File

@ -40,7 +40,7 @@ func (cas *CollectdApiSuite) TestPacketToSeriesWithUnixTimestamp(c *C) {
packet := &(*packets)[0]
series := packetToSeries(packet)
timestamp := *series[0].Points[0].Timestamp
c.Assert(timestamp, Equals, int64(1414080767000))
c.Assert(timestamp, Equals, int64(1414080767000000))
}
func (cas *CollectdApiSuite) TestPacketToSeriesWithHiResTimestamp(c *C) {
@ -61,7 +61,7 @@ func (cas *CollectdApiSuite) TestPacketToSeriesWithHiResTimestamp(c *C) {
packet := &(*packets)[0]
series := packetToSeries(packet)
timestamp := *series[0].Points[0].Timestamp
c.Assert(timestamp, Equals, int64(1414187920000))
c.Assert(timestamp, Equals, int64(1414187920000000))
}
// Taken from /usr/share/collectd/types.db on a Ubuntu system