Prometheus output: do not remake metrics map each write

closes #1775
This commit is contained in:
Cameron Sparr 2016-09-16 15:43:53 +01:00
parent b613405f42
commit 8d3285522c
2 changed files with 22 additions and 6 deletions

View File

@ -23,13 +23,19 @@
### Bugfixes
- [#1628](https://github.com/influxdata/telegraf/issues/1628): Fix mongodb input panic on version 2.2.
- [#1738](https://github.com/influxdata/telegraf/issues/1738): Fix unmarshal of influxdb metrics with null tags
- [#1733](https://github.com/influxdata/telegraf/issues/1733): Fix statsd scientific notation parsing
- [#1716](https://github.com/influxdata/telegraf/issues/1716): Sensors plugin strconv.ParseFloat: parsing "": invalid syntax
- [#1530](https://github.com/influxdata/telegraf/issues/1530): Fix prometheus_client reload panic
- [#1764](https://github.com/influxdata/telegraf/issues/1764): Fix kafka consumer panic when nil error is returned down errs channel.
- [#1768](https://github.com/influxdata/telegraf/pull/1768): Speed up statsd parsing.
## v1.0.1 [unreleased]
### Bugfixes
- [#1775](https://github.com/influxdata/telegraf/issues/1775): Prometheus output: Fix bug with multi-batch writes.
- [#1738](https://github.com/influxdata/telegraf/issues/1738): Fix unmarshal of influxdb metrics with null tags
## v1.0 [2016-09-08]
### Release Notes

View File

@ -18,6 +18,7 @@ type PrometheusClient struct {
Listen string
metrics map[string]prometheus.Metric
lastMetrics map[string]prometheus.Metric
sync.Mutex
}
@ -28,6 +29,8 @@ var sampleConfig = `
`
func (p *PrometheusClient) Start() error {
p.metrics = make(map[string]prometheus.Metric)
p.lastMetrics = make(map[string]prometheus.Metric)
prometheus.Register(p)
defer func() {
if r := recover(); r != nil {
@ -83,8 +86,17 @@ func (p *PrometheusClient) Collect(ch chan<- prometheus.Metric) {
p.Lock()
defer p.Unlock()
for _, m := range p.metrics {
if len(p.metrics) > 0 {
p.lastMetrics = make(map[string]prometheus.Metric)
for k, m := range p.metrics {
ch <- m
p.lastMetrics[k] = m
}
p.metrics = make(map[string]prometheus.Metric)
} else {
for _, m := range p.lastMetrics {
ch <- m
}
}
}
@ -92,8 +104,6 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
p.Lock()
defer p.Unlock()
p.metrics = make(map[string]prometheus.Metric)
if len(metrics) == 0 {
return nil
}