mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-12-26 15:29:04 +01:00
Reuse flush timer
This commit is contained in:
parent
19ec6d06db
commit
1e606a1aa1
@ -105,7 +105,17 @@ func (s *InfluxSink) connect() error {
|
||||
func (s *InfluxSink) Write(m lp.CCMetric) error {
|
||||
|
||||
if s.flushDelay != 0 && s.flushTimerMutex.TryLock() {
|
||||
// Run a batched flush for all metrics that arrived in the last flush delay interval
|
||||
|
||||
// Setup flush timer when flush delay is configured
|
||||
// and no other timer is already running
|
||||
if s.flushTimer != nil {
|
||||
|
||||
// Restarting existing flush timer
|
||||
cclog.ComponentDebug(s.name, "Restarting flush timer")
|
||||
s.flushTimer.Reset(s.flushDelay)
|
||||
} else {
|
||||
|
||||
// Creating and starting flush timer
|
||||
cclog.ComponentDebug(s.name, "Starting new flush timer")
|
||||
s.flushTimer = time.AfterFunc(
|
||||
s.flushDelay,
|
||||
@ -117,6 +127,7 @@ func (s *InfluxSink) Write(m lp.CCMetric) error {
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Lock access to batch slice
|
||||
s.batchMutex.Lock()
|
||||
|
Loading…
Reference in New Issue
Block a user