1
0
Fork 0

influxdb 수집 포인트 추가

This commit is contained in:
Sangbum Kim 2017-09-12 21:31:32 +09:00
parent 45317cfd6b
commit ff965639bc
1 changed files with 26 additions and 30 deletions

View File

@ -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())
}