From aab5631ca721dbf4a874a96518f518a2802b78c8 Mon Sep 17 00:00:00 2001 From: Sangbum Kim Date: Sun, 24 Sep 2017 20:17:56 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B2=B4=EB=84=90=20=EC=9A=A9=EB=9F=89=20?= =?UTF-8?q?=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- consumer/influx_stat.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/consumer/influx_stat.go b/consumer/influx_stat.go index e3bc257..131622c 100644 --- a/consumer/influx_stat.go +++ b/consumer/influx_stat.go @@ -15,7 +15,7 @@ var ( type data struct { Tempeture float64 - FanSpeed int + FanSpeed int } type influxMetric struct { @@ -37,8 +37,8 @@ func NewInfluxMetric(host string, processorCount int, handler util.Handler) Infl host: host, processorCount: processorCount, handler: handler, - fanSpeedConsumer: make(chan processor.FanspeedInfo, 1), - tempetureConsumer: make(chan processor.TempetureInfo, 1), + fanSpeedConsumer: make(chan processor.FanspeedInfo, processorCount), + tempetureConsumer: make(chan processor.TempetureInfo, processorCount), } } @@ -86,18 +86,18 @@ func (m *influxMetric) StartLogging() { panic(err) } ticker := time.Tick(time.Second) - dataList := make([]data,m.processorCount) + metricData := make([]data, m.processorCount) for { select { case <-ticker: - sendData := make([]data,m.processorCount) - copy(sendData,dataList) + sendData := make([]data, m.processorCount) + copy(sendData, metricData) go m.sendPoint(influxDbConn, batchPoint, sendData) case changedSpeed := <-m.fanSpeedConsumer: - dataList[changedSpeed.Id].FanSpeed =changedSpeed.FanSpeed + metricData[changedSpeed.Id].FanSpeed = changedSpeed.FanSpeed case changedTempeture := <-m.tempetureConsumer: - dataList[changedTempeture.Id].Tempeture =changedTempeture.Tempeture + metricData[changedTempeture.Id].Tempeture = changedTempeture.Tempeture case <-m.handler.Done(): return } @@ -108,9 +108,9 @@ func (m *influxMetric) sendPoint( batchPoint client.BatchPoints, datas []data) { pointList := make([]*client.Point, 0, 0) - at:=time.Now() + at := time.Now() for id, data := range datas { - if point, err := m.getPoint(id,data,at); err == nil { + if point, err := m.getPoint(id, data, at); err == nil { pointList = append(pointList, point) } else { influxLogger.Debugf("id %d err %s", id, err) @@ -128,14 +128,14 @@ func (m *influxMetric) sendPoint( } -func (m *influxMetric) getPoint(id int,data data,at time.Time) (*client.Point, error) { +func (m *influxMetric) getPoint(id int, data data, at time.Time) (*client.Point, error) { // Create a point and add to batch tags := map[string]string{"processor": strconv.Itoa(id)} fields := map[string]interface{}{ "tempeture": data.Tempeture, - "fan": data.FanSpeed, + "fan": data.FanSpeed, } return client.NewPoint("processor", tags, fields, at) -} \ No newline at end of file +}