diff --git a/consumer/influx_stat.go b/consumer/influx_stat.go index 8bccca0..d4ee6b8 100644 --- a/consumer/influx_stat.go +++ b/consumer/influx_stat.go @@ -77,26 +77,19 @@ func (m *influxMetric) StartLogging() { } } - // Create a new point batch - batchPoint, err := client.NewBatchPoints(client.BatchPointsConfig{ - Database: "core", - Precision: "s", - }) - if err != nil { - panic(err) - } ticker := time.Tick(time.Second) - pastMetricData, newMetricData := make([]data, m.processorCount), make([]data, m.processorCount) + metricData := make([]data, m.processorCount) + sendData := make([]data, m.processorCount) for { select { case <-ticker: - copy(pastMetricData, newMetricData) - go m.sendPoint(influxDbConn, batchPoint, pastMetricData) + copy(sendData, metricData) + go m.sendPoint(influxDbConn, sendData) case changedSpeed := <-m.fanSpeedConsumer: - newMetricData[changedSpeed.Id].FanSpeed = changedSpeed.FanSpeed + metricData[changedSpeed.Id].FanSpeed = changedSpeed.FanSpeed case changedTempeture := <-m.tempetureConsumer: - newMetricData[changedTempeture.Id].Tempeture = changedTempeture.Tempeture + metricData[changedTempeture.Id].Tempeture = changedTempeture.Tempeture case <-m.handler.Done(): return } @@ -104,7 +97,6 @@ func (m *influxMetric) StartLogging() { } func (m *influxMetric) sendPoint( influxDbConn client.Client, - batchPoint client.BatchPoints, datas []data) { pointList := make([]*client.Point, 0, 0) at := time.Now() @@ -120,6 +112,15 @@ func (m *influxMetric) sendPoint( return } + // Create a new point batch + batchPoint, err := client.NewBatchPoints(client.BatchPointsConfig{ + Database: "core", + Precision: "s", + }) + if err != nil { + influxLogger.Warn(err) + return + } batchPoint.AddPoints(pointList) if err := influxDbConn.Write(batchPoint); err != nil { influxLogger.Warn(err)