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

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