mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-26 09:11:01 +00:00
Move value check before metric get
If someone is emitting negative counters we shouldn't even register the metric for them
This commit is contained in:
parent
663b6a1e69
commit
22520f4c7b
1 changed files with 5 additions and 4 deletions
|
@ -233,10 +233,6 @@ func (b *Exporter) Listen(e <-chan Events) {
|
|||
|
||||
switch ev := event.(type) {
|
||||
case *CounterEvent:
|
||||
counter := b.Counters.Get(
|
||||
b.suffix(metricName, "counter"),
|
||||
prometheusLabels,
|
||||
)
|
||||
// We don't accept negative values for counters. Incrementing the counter with a negative number
|
||||
// will cause the exporter to panic. Instead we will warn and continue to the next event.
|
||||
if event.Value() < 0.0 {
|
||||
|
@ -244,6 +240,11 @@ func (b *Exporter) Listen(e <-chan Events) {
|
|||
continue
|
||||
}
|
||||
|
||||
counter := b.Counters.Get(
|
||||
b.suffix(metricName, "counter"),
|
||||
prometheusLabels,
|
||||
)
|
||||
|
||||
counter.Add(event.Value())
|
||||
|
||||
eventStats.WithLabelValues("counter").Inc()
|
||||
|
|
Loading…
Reference in a new issue