From bcd906c850ba91297c188e7c7aa57f53ffb62735 Mon Sep 17 00:00:00 2001 From: Sangbum Kim Date: Tue, 26 Sep 2017 08:05:34 +0900 Subject: [PATCH] =?UTF-8?q?=ED=8F=AC=EC=9D=B8=ED=8A=B8=EA=B0=80=20?= =?UTF-8?q?=EA=B3=84=EC=86=8D=20=EB=8A=98=EC=96=B4=EB=82=98=EB=8A=94=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- consumer/influx_stat.go | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) 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)