수치 매초 보내도록 함
This commit is contained in:
parent
e35a6df56d
commit
b297c3d6ed
|
@ -13,6 +13,11 @@ var (
|
||||||
influxLogger = logger.NewLogger("influx")
|
influxLogger = logger.NewLogger("influx")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type data struct {
|
||||||
|
Tempeture float64
|
||||||
|
FanSpeed int
|
||||||
|
}
|
||||||
|
|
||||||
type influxMetric struct {
|
type influxMetric struct {
|
||||||
host string
|
host string
|
||||||
processorCount int
|
processorCount int
|
||||||
|
@ -80,19 +85,19 @@ func (m *influxMetric) StartLogging() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
ticker := time.Tick(time.Second*2)
|
ticker := time.Tick(time.Second)
|
||||||
fanspeedList, tempetureList := make([]processor.FanspeedInfo, 0, 0), make([]processor.TempetureInfo, 0, 0)
|
dataList := make([]data,m.processorCount)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker:
|
case <-ticker:
|
||||||
fanspeedListTemp, tempetureListTemp := fanspeedList, tempetureList
|
sendData := make([]data,m.processorCount)
|
||||||
fanspeedList, tempetureList = make([]processor.FanspeedInfo, 0, 0), make([]processor.TempetureInfo, 0, 0)
|
copy(sendData,dataList)
|
||||||
go m.sendPoint(influxDbConn, batchPoint, fanspeedListTemp, tempetureListTemp)
|
go m.sendPoint(influxDbConn, batchPoint, sendData)
|
||||||
case changedSpeed := <-m.fanSpeedConsumer:
|
case changedSpeed := <-m.fanSpeedConsumer:
|
||||||
fanspeedList = append(fanspeedList, changedSpeed)
|
dataList[changedSpeed.Id].FanSpeed =changedSpeed.FanSpeed
|
||||||
case changedTempeture := <-m.tempetureConsumer:
|
case changedTempeture := <-m.tempetureConsumer:
|
||||||
tempetureList = append(tempetureList, changedTempeture)
|
dataList[changedTempeture.Id].Tempeture =changedTempeture.Tempeture
|
||||||
case <-m.handler.Done():
|
case <-m.handler.Done():
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -101,22 +106,14 @@ func (m *influxMetric) StartLogging() {
|
||||||
func (m *influxMetric) sendPoint(
|
func (m *influxMetric) sendPoint(
|
||||||
influxDbConn client.Client,
|
influxDbConn client.Client,
|
||||||
batchPoint client.BatchPoints,
|
batchPoint client.BatchPoints,
|
||||||
fanspeeds []processor.FanspeedInfo, tempetures []processor.TempetureInfo) {
|
datas []data) {
|
||||||
pointList := make([]*client.Point, 0, 0)
|
pointList := make([]*client.Point, 0, 0)
|
||||||
|
at:=time.Now()
|
||||||
for _, fanspeed := range fanspeeds {
|
for id, data := range datas {
|
||||||
if point, err := m.getFanspeedPoint(fanspeed); err == nil {
|
if point, err := m.getPoint(id,data,at); err == nil {
|
||||||
pointList = append(pointList, point)
|
pointList = append(pointList, point)
|
||||||
} else {
|
} else {
|
||||||
influxLogger.Debugf("id %d speed err %s", fanspeed.Id, err)
|
influxLogger.Debugf("id %d err %s", id, err)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tempeture := range tempetures {
|
|
||||||
if point, err := m.getTempeturePoint(tempeture); err == nil {
|
|
||||||
pointList = append(pointList, point)
|
|
||||||
} else {
|
|
||||||
influxLogger.Debugf("id %d tempeture err %s", tempeture.Id, err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,24 +128,14 @@ func (m *influxMetric) sendPoint(
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *influxMetric) getTempeturePoint(info processor.TempetureInfo) (*client.Point, error) {
|
func (m *influxMetric) getPoint(id int,data data,at time.Time) (*client.Point, error) {
|
||||||
|
|
||||||
// Create a point and add to batch
|
// Create a point and add to batch
|
||||||
tags := map[string]string{"processor": strconv.Itoa(info.Id)}
|
tags := map[string]string{"processor": strconv.Itoa(id)}
|
||||||
fields := map[string]interface{}{
|
fields := map[string]interface{}{
|
||||||
"tempeture": info.Tempeture,
|
"tempeture": data.Tempeture,
|
||||||
|
"fan": data.FanSpeed,
|
||||||
}
|
}
|
||||||
|
|
||||||
return client.NewPoint("processor_tempeture", tags, fields, info.At)
|
return client.NewPoint("processor", tags, fields, at)
|
||||||
}
|
|
||||||
|
|
||||||
func (m *influxMetric) getFanspeedPoint(info processor.FanspeedInfo) (*client.Point, error) {
|
|
||||||
|
|
||||||
// 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, info.At)
|
|
||||||
}
|
}
|
4
main.go
4
main.go
|
@ -117,8 +117,8 @@ func main() {
|
||||||
handler.NotifyError(errors.New("cpu not found!"))
|
handler.NotifyError(errors.New("cpu not found!"))
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
tempetureChannel = make(chan processor.TempetureInfo)
|
tempetureChannel = make(chan processor.TempetureInfo,1)
|
||||||
fanspeedChannel = make(chan processor.FanspeedInfo)
|
fanspeedChannel = make(chan processor.FanspeedInfo,1)
|
||||||
)
|
)
|
||||||
processors = make([]processor.Processor, 0, processorCount)
|
processors = make([]processor.Processor, 0, processorCount)
|
||||||
for i := 0; i < processorCount; i++ {
|
for i := 0; i < processorCount; i++ {
|
||||||
|
|
|
@ -142,7 +142,6 @@ func (p *processor) StartMonitoring() {
|
||||||
SELECT mean("tempeture") as tempeture FROM "processor_tempeture" WHERE $timeFilter GROUP BY "processor", time(5s) fill(previous)
|
SELECT mean("tempeture") as tempeture FROM "processor_tempeture" WHERE $timeFilter GROUP BY "processor", time(5s) fill(previous)
|
||||||
*/
|
*/
|
||||||
highestTemp = p.getMaxTempetureOnProcessor(tempeturePathGlob)
|
highestTemp = p.getMaxTempetureOnProcessor(tempeturePathGlob)
|
||||||
if highestTemp != p.tempeture {
|
|
||||||
if p.tempetureChanged != nil {
|
if p.tempetureChanged != nil {
|
||||||
select {
|
select {
|
||||||
case p.tempetureChanged <- TempetureInfo{
|
case p.tempetureChanged <- TempetureInfo{
|
||||||
|
@ -155,13 +154,11 @@ func (p *processor) StartMonitoring() {
|
||||||
}
|
}
|
||||||
p.tempeture = highestTemp
|
p.tempeture = highestTemp
|
||||||
log.Debugf("processor %d : tempeture changed %f", p.id, highestTemp)
|
log.Debugf("processor %d : tempeture changed %f", p.id, highestTemp)
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
SELECT mean("noob") as noob FROM "processor_cooling_fanspeed" WHERE $timeFilter GROUP BY "processor", time(5s) fill(previous) CREATE CONTINUOUS QUERY "processor_cooling_fanspeed_5s" ON "core" BEGIN SELECT max("noob") AS "mean_noob" INTO "processor_cooling_fanspeed_5s" FROM "processor_cooling_fanspeed" GROUP BY "processor", time(5s) fill(previous) END
|
SELECT mean("noob") as noob FROM "processor_cooling_fanspeed" WHERE $timeFilter GROUP BY "processor", time(5s) fill(previous) CREATE CONTINUOUS QUERY "processor_cooling_fanspeed_5s" ON "core" BEGIN SELECT max("noob") AS "mean_noob" INTO "processor_cooling_fanspeed_5s" FROM "processor_cooling_fanspeed" GROUP BY "processor", time(5s) fill(previous) END
|
||||||
*/
|
*/
|
||||||
fanspeed = p.normalizeFanspeed(p.fanController.Update(highestTemp))
|
fanspeed = p.normalizeFanspeed(p.fanController.Update(highestTemp))
|
||||||
if fanspeed != p.fanSpeed {
|
|
||||||
if p.fanSpeedChanged != nil {
|
if p.fanSpeedChanged != nil {
|
||||||
select {
|
select {
|
||||||
case p.fanSpeedChanged <- FanspeedInfo{
|
case p.fanSpeedChanged <- FanspeedInfo{
|
||||||
|
@ -174,7 +171,6 @@ func (p *processor) StartMonitoring() {
|
||||||
}
|
}
|
||||||
p.fanSpeed = fanspeed
|
p.fanSpeed = fanspeed
|
||||||
log.Debugf("processor %d : fan changed 0x%x", p.id, fanspeed)
|
log.Debugf("processor %d : fan changed 0x%x", p.id, fanspeed)
|
||||||
}
|
|
||||||
case <-p.handler.Done():
|
case <-p.handler.Done():
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue