mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-22 15:30:59 +00:00
Don't crash on conflicting metric names
This patch simply moves the error message from a log.Fatalf() to a log.Errorf() to continue on. Fixes #63
This commit is contained in:
parent
22520f4c7b
commit
d9aa6e2867
1 changed files with 33 additions and 22 deletions
55
exporter.go
55
exporter.go
|
@ -69,7 +69,7 @@ func NewCounterContainer() *CounterContainer {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *CounterContainer) Get(metricName string, labels prometheus.Labels) prometheus.Counter {
|
||||
func (c *CounterContainer) Get(metricName string, labels prometheus.Labels) (prometheus.Counter, error) {
|
||||
hash := hashNameAndLabels(metricName, labels)
|
||||
counter, ok := c.Elements[hash]
|
||||
if !ok {
|
||||
|
@ -80,10 +80,10 @@ func (c *CounterContainer) Get(metricName string, labels prometheus.Labels) prom
|
|||
})
|
||||
c.Elements[hash] = counter
|
||||
if err := prometheus.Register(counter); err != nil {
|
||||
log.Fatalf(regErrF, metricName, err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return counter
|
||||
return counter, nil
|
||||
}
|
||||
|
||||
type GaugeContainer struct {
|
||||
|
@ -96,7 +96,7 @@ func NewGaugeContainer() *GaugeContainer {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *GaugeContainer) Get(metricName string, labels prometheus.Labels) prometheus.Gauge {
|
||||
func (c *GaugeContainer) Get(metricName string, labels prometheus.Labels) (prometheus.Gauge, error) {
|
||||
hash := hashNameAndLabels(metricName, labels)
|
||||
gauge, ok := c.Elements[hash]
|
||||
if !ok {
|
||||
|
@ -107,10 +107,10 @@ func (c *GaugeContainer) Get(metricName string, labels prometheus.Labels) promet
|
|||
})
|
||||
c.Elements[hash] = gauge
|
||||
if err := prometheus.Register(gauge); err != nil {
|
||||
log.Fatalf(regErrF, metricName, err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return gauge
|
||||
return gauge, nil
|
||||
}
|
||||
|
||||
type SummaryContainer struct {
|
||||
|
@ -123,7 +123,7 @@ func NewSummaryContainer() *SummaryContainer {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *SummaryContainer) Get(metricName string, labels prometheus.Labels) prometheus.Summary {
|
||||
func (c *SummaryContainer) Get(metricName string, labels prometheus.Labels) (prometheus.Summary, error) {
|
||||
hash := hashNameAndLabels(metricName, labels)
|
||||
summary, ok := c.Elements[hash]
|
||||
if !ok {
|
||||
|
@ -135,10 +135,10 @@ func (c *SummaryContainer) Get(metricName string, labels prometheus.Labels) prom
|
|||
})
|
||||
c.Elements[hash] = summary
|
||||
if err := prometheus.Register(summary); err != nil {
|
||||
log.Fatalf(regErrF, metricName, err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return summary
|
||||
return summary, nil
|
||||
}
|
||||
|
||||
type Event interface {
|
||||
|
@ -240,37 +240,48 @@ func (b *Exporter) Listen(e <-chan Events) {
|
|||
continue
|
||||
}
|
||||
|
||||
counter := b.Counters.Get(
|
||||
counter, err := b.Counters.Get(
|
||||
b.suffix(metricName, "counter"),
|
||||
prometheusLabels,
|
||||
)
|
||||
if err == nil {
|
||||
counter.Add(event.Value())
|
||||
|
||||
counter.Add(event.Value())
|
||||
|
||||
eventStats.WithLabelValues("counter").Inc()
|
||||
eventStats.WithLabelValues("counter").Inc()
|
||||
} else {
|
||||
log.Errorf(regErrF, metricName, err)
|
||||
}
|
||||
|
||||
case *GaugeEvent:
|
||||
gauge := b.Gauges.Get(
|
||||
gauge, err := b.Gauges.Get(
|
||||
b.suffix(metricName, "gauge"),
|
||||
prometheusLabels,
|
||||
)
|
||||
|
||||
if ev.relative {
|
||||
gauge.Add(event.Value())
|
||||
if err == nil {
|
||||
if ev.relative {
|
||||
gauge.Add(event.Value())
|
||||
} else {
|
||||
gauge.Set(event.Value())
|
||||
}
|
||||
|
||||
eventStats.WithLabelValues("gauge").Inc()
|
||||
} else {
|
||||
gauge.Set(event.Value())
|
||||
log.Errorf(regErrF, metricName, err)
|
||||
}
|
||||
|
||||
eventStats.WithLabelValues("gauge").Inc()
|
||||
|
||||
case *TimerEvent:
|
||||
summary := b.Summaries.Get(
|
||||
summary, err := b.Summaries.Get(
|
||||
b.suffix(metricName, "timer"),
|
||||
prometheusLabels,
|
||||
)
|
||||
summary.Observe(event.Value())
|
||||
if err == nil {
|
||||
summary.Observe(event.Value())
|
||||
|
||||
eventStats.WithLabelValues("timer").Inc()
|
||||
eventStats.WithLabelValues("timer").Inc()
|
||||
} else {
|
||||
log.Errorf(regErrF, metricName, err)
|
||||
}
|
||||
|
||||
default:
|
||||
log.Errorln("Unsupported event type")
|
||||
|
|
Loading…
Reference in a new issue