From 237e011068a27ac8698e8fe31ebebad40607d4a5 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Tue, 18 Apr 2017 03:10:16 +0200 Subject: [PATCH] Pass the time to addPoint --- database/influxdb/database.go | 4 ++-- database/influxdb/global.go | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/database/influxdb/database.go b/database/influxdb/database.go index 74345569..0ca036b8 100644 --- a/database/influxdb/database.go +++ b/database/influxdb/database.go @@ -78,8 +78,8 @@ func Connect(configuration interface{}) (database.Connection, error) { return db, nil } -func (conn *Connection) addPoint(name string, tags models.Tags, fields models.Fields, time time.Time) { - point, err := client.NewPoint(name, tags.Map(), fields, time) +func (conn *Connection) addPoint(name string, tags models.Tags, fields models.Fields, t ...time.Time) { + point, err := client.NewPoint(name, tags.Map(), fields, t...) if err != nil { panic(err) } diff --git a/database/influxdb/global.go b/database/influxdb/global.go index de2495a5..26d27bb2 100644 --- a/database/influxdb/global.go +++ b/database/influxdb/global.go @@ -10,8 +10,8 @@ import ( // InsertGlobals implementation of database func (conn *Connection) InsertGlobals(stats *runtime.GlobalStats, time time.Time) { conn.addPoint(MeasurementGlobal, nil, GlobalStatsFields(stats), time) - conn.addCounterMap(CounterMeasurementModel, stats.Models) - conn.addCounterMap(CounterMeasurementFirmware, stats.Firmwares) + conn.addCounterMap(CounterMeasurementModel, stats.Models, time) + conn.addCounterMap(CounterMeasurementFirmware, stats.Firmwares, time) } // GlobalStatsFields returns fields for InfluxDB @@ -29,8 +29,7 @@ func GlobalStatsFields(stats *runtime.GlobalStats) map[string]interface{} { // Saves the values of a CounterMap in the database. // The key are used as 'value' tag. // The value is used as 'counter' field. -func (conn *Connection) addCounterMap(name string, m runtime.CounterMap) { - now := time.Now() +func (conn *Connection) addCounterMap(name string, m runtime.CounterMap, t time.Time) { for key, count := range m { conn.addPoint( name, @@ -38,7 +37,7 @@ func (conn *Connection) addCounterMap(name string, m runtime.CounterMap) { models.Tag{Key: []byte("value"), Value: []byte(key)}, }, models.Fields{"count": count}, - now, + t, ) } }