mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-14 11:21:17 +00:00
Adds a separate counter for events discarded due to errors
Signed-off-by: Ivan Izaguirre <ivanizag@gmail.com>
This commit is contained in:
parent
c477c7703f
commit
c9e5e94ed2
3 changed files with 36 additions and 2 deletions
|
@ -334,7 +334,8 @@ func (b *Exporter) handleEvent(event Event) {
|
|||
prometheusLabels := event.Labels()
|
||||
if present {
|
||||
if mapping.Name == "" {
|
||||
log.Debugf("The mapping for match \"%v\" generates an empty metric name.", mapping.Match)
|
||||
log.Debugf("The mapping of '%s' for match '%s' generates an empty metric name", event.MetricName(), mapping.Match)
|
||||
errorEventStats.WithLabelValues("empty_metric_name").Inc()
|
||||
return
|
||||
}
|
||||
metricName = escapeMetricName(mapping.Name)
|
||||
|
@ -352,7 +353,7 @@ func (b *Exporter) handleEvent(event Event) {
|
|||
// will cause the exporter to panic. Instead we will warn and continue to the next event.
|
||||
if event.Value() < 0.0 {
|
||||
log.Debugf("Counter %q is: '%f' (counter must be non-negative value)", metricName, event.Value())
|
||||
eventStats.WithLabelValues("illegal_negative_counter").Inc()
|
||||
errorEventStats.WithLabelValues("illegal_negative_counter").Inc()
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -52,8 +52,16 @@ func TestNegativeCounter(t *testing.T) {
|
|||
close(events)
|
||||
}()
|
||||
|
||||
errorCounter := errorEventStats.WithLabelValues("illegal_negative_counter")
|
||||
prev := getTelemetryCounterValue(errorCounter)
|
||||
|
||||
ex := NewExporter(&mapper.MetricMapper{})
|
||||
ex.Listen(events)
|
||||
|
||||
updated := getTelemetryCounterValue(errorCounter)
|
||||
if updated-prev != 1 {
|
||||
t.Fatal("Empty metric name error event not counted")
|
||||
}
|
||||
}
|
||||
|
||||
// TestEmptyStringMetric validates when a metric name ends up
|
||||
|
@ -84,8 +92,16 @@ mappings:
|
|||
t.Fatalf("Config load error: %s %s", config, err)
|
||||
}
|
||||
|
||||
errorCounter := errorEventStats.WithLabelValues("empty_metric_name")
|
||||
prev := getTelemetryCounterValue(errorCounter)
|
||||
|
||||
ex := NewExporter(testMapper)
|
||||
ex.Listen(events)
|
||||
|
||||
updated := getTelemetryCounterValue(errorCounter)
|
||||
if updated-prev != 1 {
|
||||
t.Fatal("Empty metric name error event not counted")
|
||||
}
|
||||
}
|
||||
|
||||
// TestInvalidUtf8InDatadogTagValue validates robustness of exporter listener
|
||||
|
@ -388,3 +404,12 @@ func labelPairsAsLabels(pairs []*dto.LabelPair) (labels prometheus.Labels) {
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getTelemetryCounterValue(counter prometheus.Counter) float64 {
|
||||
var metric dto.Metric
|
||||
err := counter.Write(&metric)
|
||||
if err != nil {
|
||||
return 0.0
|
||||
}
|
||||
return metric.Counter.GetValue()
|
||||
}
|
||||
|
|
|
@ -102,6 +102,13 @@ var (
|
|||
},
|
||||
[]string{"type"},
|
||||
)
|
||||
errorEventStats = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "statsd_exporter_events_error_total",
|
||||
Help: "The total number of StatsD events discarded due to errors.",
|
||||
},
|
||||
[]string{"reason"},
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -119,4 +126,5 @@ func init() {
|
|||
prometheus.MustRegister(configLoads)
|
||||
prometheus.MustRegister(mappingsCount)
|
||||
prometheus.MustRegister(conflictingEventStats)
|
||||
prometheus.MustRegister(errorEventStats)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue