1
0
Fork 0

체널 용량 조정

This commit is contained in:
Sangbum Kim 2017-09-24 20:17:56 +09:00
parent b297c3d6ed
commit aab5631ca7
1 changed files with 13 additions and 13 deletions

View File

@ -37,8 +37,8 @@ func NewInfluxMetric(host string, processorCount int, handler util.Handler) Infl
host: host, host: host,
processorCount: processorCount, processorCount: processorCount,
handler: handler, handler: handler,
fanSpeedConsumer: make(chan processor.FanspeedInfo, 1), fanSpeedConsumer: make(chan processor.FanspeedInfo, processorCount),
tempetureConsumer: make(chan processor.TempetureInfo, 1), tempetureConsumer: make(chan processor.TempetureInfo, processorCount),
} }
} }
@ -86,18 +86,18 @@ func (m *influxMetric) StartLogging() {
panic(err) panic(err)
} }
ticker := time.Tick(time.Second) ticker := time.Tick(time.Second)
dataList := make([]data,m.processorCount) metricData := make([]data, m.processorCount)
for { for {
select { select {
case <-ticker: case <-ticker:
sendData := make([]data,m.processorCount) sendData := make([]data, m.processorCount)
copy(sendData,dataList) copy(sendData, metricData)
go m.sendPoint(influxDbConn, batchPoint, sendData) go m.sendPoint(influxDbConn, batchPoint, sendData)
case changedSpeed := <-m.fanSpeedConsumer: case changedSpeed := <-m.fanSpeedConsumer:
dataList[changedSpeed.Id].FanSpeed =changedSpeed.FanSpeed metricData[changedSpeed.Id].FanSpeed = changedSpeed.FanSpeed
case changedTempeture := <-m.tempetureConsumer: case changedTempeture := <-m.tempetureConsumer:
dataList[changedTempeture.Id].Tempeture =changedTempeture.Tempeture metricData[changedTempeture.Id].Tempeture = changedTempeture.Tempeture
case <-m.handler.Done(): case <-m.handler.Done():
return return
} }
@ -108,9 +108,9 @@ func (m *influxMetric) sendPoint(
batchPoint client.BatchPoints, batchPoint client.BatchPoints,
datas []data) { datas []data) {
pointList := make([]*client.Point, 0, 0) pointList := make([]*client.Point, 0, 0)
at:=time.Now() at := time.Now()
for id, data := range datas { 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) pointList = append(pointList, point)
} else { } else {
influxLogger.Debugf("id %d err %s", id, err) influxLogger.Debugf("id %d err %s", id, err)
@ -128,7 +128,7 @@ 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 // Create a point and add to batch
tags := map[string]string{"processor": strconv.Itoa(id)} tags := map[string]string{"processor": strconv.Itoa(id)}