포인트가 계속 늘어나는 문제 해결
This commit is contained in:
parent
a2d7f5e720
commit
bcd906c850
|
@ -77,26 +77,19 @@ func (m *influxMetric) StartLogging() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new point batch
|
|
||||||
batchPoint, err := client.NewBatchPoints(client.BatchPointsConfig{
|
|
||||||
Database: "core",
|
|
||||||
Precision: "s",
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
ticker := time.Tick(time.Second)
|
ticker := time.Tick(time.Second)
|
||||||
pastMetricData, newMetricData := make([]data, m.processorCount), make([]data, m.processorCount)
|
metricData := make([]data, m.processorCount)
|
||||||
|
sendData := make([]data, m.processorCount)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker:
|
case <-ticker:
|
||||||
copy(pastMetricData, newMetricData)
|
copy(sendData, metricData)
|
||||||
go m.sendPoint(influxDbConn, batchPoint, pastMetricData)
|
go m.sendPoint(influxDbConn, sendData)
|
||||||
case changedSpeed := <-m.fanSpeedConsumer:
|
case changedSpeed := <-m.fanSpeedConsumer:
|
||||||
newMetricData[changedSpeed.Id].FanSpeed = changedSpeed.FanSpeed
|
metricData[changedSpeed.Id].FanSpeed = changedSpeed.FanSpeed
|
||||||
case changedTempeture := <-m.tempetureConsumer:
|
case changedTempeture := <-m.tempetureConsumer:
|
||||||
newMetricData[changedTempeture.Id].Tempeture = changedTempeture.Tempeture
|
metricData[changedTempeture.Id].Tempeture = changedTempeture.Tempeture
|
||||||
case <-m.handler.Done():
|
case <-m.handler.Done():
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -104,7 +97,6 @@ func (m *influxMetric) StartLogging() {
|
||||||
}
|
}
|
||||||
func (m *influxMetric) sendPoint(
|
func (m *influxMetric) sendPoint(
|
||||||
influxDbConn client.Client,
|
influxDbConn client.Client,
|
||||||
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()
|
||||||
|
@ -120,6 +112,15 @@ func (m *influxMetric) sendPoint(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a new point batch
|
||||||
|
batchPoint, err := client.NewBatchPoints(client.BatchPointsConfig{
|
||||||
|
Database: "core",
|
||||||
|
Precision: "s",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
influxLogger.Warn(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
batchPoint.AddPoints(pointList)
|
batchPoint.AddPoints(pointList)
|
||||||
if err := influxDbConn.Write(batchPoint); err != nil {
|
if err := influxDbConn.Write(batchPoint); err != nil {
|
||||||
influxLogger.Warn(err)
|
influxLogger.Warn(err)
|
||||||
|
|
Loading…
Reference in New Issue