From ff965639bcafcbb4b81a32d98fdcb9a4f273e4b0 Mon Sep 17 00:00:00 2001 From: Sangbum Kim Date: Tue, 12 Sep 2017 21:31:32 +0900 Subject: [PATCH] =?UTF-8?q?influxdb=20=EC=88=98=EC=A7=91=20=ED=8F=AC?= =?UTF-8?q?=EC=9D=B8=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- consumer/influx_stat.go | 56 +++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/consumer/influx_stat.go b/consumer/influx_stat.go index e9c584a..0e08dba 100644 --- a/consumer/influx_stat.go +++ b/consumer/influx_stat.go @@ -2,13 +2,11 @@ package consumer import ( "amuz.es/src/infra/cpu_ctrl/util" - //"time" "amuz.es/src/infra/cpu_ctrl/processor" "amuz.es/src/infra/cpu_ctrl/logger" - //"github.com/influxdata/influxdb/client/v2" "github.com/influxdata/influxdb/client/v2" "time" - "log" + "strconv" ) var ( @@ -65,7 +63,7 @@ func (m *influxMetric) StartLogging() { influxDbConn = conn break } - cont := time.After(3 * time.Second) + cont := time.After(1 * time.Second) select { case <-cont: continue @@ -93,9 +91,17 @@ func (m *influxMetric) StartLogging() { case <-ticker: break checker case changedSpeed := <-m.fanSpeedConsumer: - influxLogger.Debugf("id %d speed %d", changedSpeed.Id, changedSpeed.FanSpeed) + if point, err := m.getFanspeedPoint(changedSpeed); err != nil { + pointList = append(pointList, point) + } else { + influxLogger.Debugf("id %d speed err %s", changedSpeed.Id, err) + } case changedTempeture := <-m.tempetureConsumer: - influxLogger.Debugf("id %d temp %f", changedTempeture.Id, changedTempeture.Tempeture) + if point, err := m.getTempeturePoint(changedTempeture); err != nil { + pointList = append(pointList, point) + } else { + influxLogger.Debugf("id %d tempeture err %s", changedTempeture.Id, err) + } case <-m.handler.Done(): return } @@ -111,32 +117,22 @@ func (m *influxMetric) StartLogging() { func (m *influxMetric) getTempeturePoint(info processor.TempetureInfo) (*client.Point, error) { - //// Create a point and add to batch - //tags := map[string]string{"cpu": "cpu-total"} - //fields := map[string]interface{}{ - // "idle": 10.1, - // "system": 53.3, - // "user": 46.6, - //} - // - //pt, err := client.NewPoint("cpu_usage", tags, fields, time.Now()) - //if err != nil { - // log.Fatal(err) - //} + // Create a point and add to batch + tags := map[string]string{"processor": strconv.Itoa(info.Id)} + fields := map[string]interface{}{ + "tempeture": info.Tempeture, + } + + return client.NewPoint("processor_tempeture", tags, fields, time.Now()) } func (m *influxMetric) getFanspeedPoint(info processor.FanspeedInfo) (*client.Point, error) { - //// Create a point and add to batch - //tags := map[string]string{"cpu": "cpu-total"} - //fields := map[string]interface{}{ - // "idle": 10.1, - // "system": 53.3, - // "user": 46.6, - //} - // - //pt, err := client.NewPoint("cpu_usage", tags, fields, time.Now()) - //if err != nil { - // log.Fatal(err) - //} + // Create a point and add to batch + tags := map[string]string{"processor": strconv.Itoa(info.Id)} + fields := map[string]interface{}{ + "noob": info.FanSpeed, + } + + return client.NewPoint("processor_cooling_fanspeed", tags, fields, time.Now()) }