체널 용량 조정
This commit is contained in:
parent
b297c3d6ed
commit
aab5631ca7
|
@ -15,7 +15,7 @@ var (
|
||||||
|
|
||||||
type data struct {
|
type data struct {
|
||||||
Tempeture float64
|
Tempeture float64
|
||||||
FanSpeed int
|
FanSpeed int
|
||||||
}
|
}
|
||||||
|
|
||||||
type influxMetric struct {
|
type influxMetric struct {
|
||||||
|
@ -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,13 +128,13 @@ 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)}
|
||||||
fields := map[string]interface{}{
|
fields := map[string]interface{}{
|
||||||
"tempeture": data.Tempeture,
|
"tempeture": data.Tempeture,
|
||||||
"fan": data.FanSpeed,
|
"fan": data.FanSpeed,
|
||||||
}
|
}
|
||||||
|
|
||||||
return client.NewPoint("processor", tags, fields, at)
|
return client.NewPoint("processor", tags, fields, at)
|
||||||
|
|
Loading…
Reference in New Issue