influxdb 수집 포인트 추가
This commit is contained in:
parent
45317cfd6b
commit
ff965639bc
|
@ -2,13 +2,11 @@ package consumer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"amuz.es/src/infra/cpu_ctrl/util"
|
"amuz.es/src/infra/cpu_ctrl/util"
|
||||||
//"time"
|
|
||||||
"amuz.es/src/infra/cpu_ctrl/processor"
|
"amuz.es/src/infra/cpu_ctrl/processor"
|
||||||
"amuz.es/src/infra/cpu_ctrl/logger"
|
"amuz.es/src/infra/cpu_ctrl/logger"
|
||||||
//"github.com/influxdata/influxdb/client/v2"
|
|
||||||
"github.com/influxdata/influxdb/client/v2"
|
"github.com/influxdata/influxdb/client/v2"
|
||||||
"time"
|
"time"
|
||||||
"log"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -65,7 +63,7 @@ func (m *influxMetric) StartLogging() {
|
||||||
influxDbConn = conn
|
influxDbConn = conn
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
cont := time.After(3 * time.Second)
|
cont := time.After(1 * time.Second)
|
||||||
select {
|
select {
|
||||||
case <-cont:
|
case <-cont:
|
||||||
continue
|
continue
|
||||||
|
@ -93,9 +91,17 @@ func (m *influxMetric) StartLogging() {
|
||||||
case <-ticker:
|
case <-ticker:
|
||||||
break checker
|
break checker
|
||||||
case changedSpeed := <-m.fanSpeedConsumer:
|
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:
|
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():
|
case <-m.handler.Done():
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -111,32 +117,22 @@ func (m *influxMetric) StartLogging() {
|
||||||
|
|
||||||
func (m *influxMetric) getTempeturePoint(info processor.TempetureInfo) (*client.Point, error) {
|
func (m *influxMetric) getTempeturePoint(info processor.TempetureInfo) (*client.Point, error) {
|
||||||
|
|
||||||
//// Create a point and add to batch
|
// Create a point and add to batch
|
||||||
//tags := map[string]string{"cpu": "cpu-total"}
|
tags := map[string]string{"processor": strconv.Itoa(info.Id)}
|
||||||
//fields := map[string]interface{}{
|
fields := map[string]interface{}{
|
||||||
// "idle": 10.1,
|
"tempeture": info.Tempeture,
|
||||||
// "system": 53.3,
|
}
|
||||||
// "user": 46.6,
|
|
||||||
//}
|
return client.NewPoint("processor_tempeture", tags, fields, time.Now())
|
||||||
//
|
|
||||||
//pt, err := client.NewPoint("cpu_usage", tags, fields, time.Now())
|
|
||||||
//if err != nil {
|
|
||||||
// log.Fatal(err)
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *influxMetric) getFanspeedPoint(info processor.FanspeedInfo) (*client.Point, error) {
|
func (m *influxMetric) getFanspeedPoint(info processor.FanspeedInfo) (*client.Point, error) {
|
||||||
|
|
||||||
//// Create a point and add to batch
|
// Create a point and add to batch
|
||||||
//tags := map[string]string{"cpu": "cpu-total"}
|
tags := map[string]string{"processor": strconv.Itoa(info.Id)}
|
||||||
//fields := map[string]interface{}{
|
fields := map[string]interface{}{
|
||||||
// "idle": 10.1,
|
"noob": info.FanSpeed,
|
||||||
// "system": 53.3,
|
}
|
||||||
// "user": 46.6,
|
|
||||||
//}
|
return client.NewPoint("processor_cooling_fanspeed", tags, fields, time.Now())
|
||||||
//
|
|
||||||
//pt, err := client.NewPoint("cpu_usage", tags, fields, time.Now())
|
|
||||||
//if err != nil {
|
|
||||||
// log.Fatal(err)
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue