buffers: fix bug when Write called before AddMetric

This commit is contained in:
Cameron Sparr 2016-04-26 10:25:04 -06:00
parent b9c24189e4
commit c7719ac365
1 changed files with 11 additions and 0 deletions

View File

@ -124,6 +124,17 @@ func (ro *RunningOutput) Write() error {
ro.Lock() ro.Lock()
defer ro.Unlock() defer ro.Unlock()
if ro.tmpmetrics == nil {
size := ro.MetricBufferLimit / ro.MetricBatchSize
// ro.metrics already contains one batch
size = size - 1
if size < 1 {
size = 1
}
ro.tmpmetrics = make([]([]telegraf.Metric), size)
}
// Write any cached metric buffers before, as those metrics are the // Write any cached metric buffers before, as those metrics are the
// oldest // oldest
for ro.tmpmetrics[ro.readI] != nil { for ro.tmpmetrics[ro.readI] != nil {