mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-26 17:21:01 +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)
|
hash := hashNameAndLabels(metricName, labels)
|
||||||
counter, ok := c.Elements[hash]
|
counter, ok := c.Elements[hash]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -80,10 +80,10 @@ func (c *CounterContainer) Get(metricName string, labels prometheus.Labels) prom
|
||||||
})
|
})
|
||||||
c.Elements[hash] = counter
|
c.Elements[hash] = counter
|
||||||
if err := prometheus.Register(counter); err != nil {
|
if err := prometheus.Register(counter); err != nil {
|
||||||
log.Fatalf(regErrF, metricName, err)
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return counter
|
return counter, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type GaugeContainer struct {
|
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)
|
hash := hashNameAndLabels(metricName, labels)
|
||||||
gauge, ok := c.Elements[hash]
|
gauge, ok := c.Elements[hash]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -107,10 +107,10 @@ func (c *GaugeContainer) Get(metricName string, labels prometheus.Labels) promet
|
||||||
})
|
})
|
||||||
c.Elements[hash] = gauge
|
c.Elements[hash] = gauge
|
||||||
if err := prometheus.Register(gauge); err != nil {
|
if err := prometheus.Register(gauge); err != nil {
|
||||||
log.Fatalf(regErrF, metricName, err)
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return gauge
|
return gauge, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type SummaryContainer struct {
|
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)
|
hash := hashNameAndLabels(metricName, labels)
|
||||||
summary, ok := c.Elements[hash]
|
summary, ok := c.Elements[hash]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -135,10 +135,10 @@ func (c *SummaryContainer) Get(metricName string, labels prometheus.Labels) prom
|
||||||
})
|
})
|
||||||
c.Elements[hash] = summary
|
c.Elements[hash] = summary
|
||||||
if err := prometheus.Register(summary); err != nil {
|
if err := prometheus.Register(summary); err != nil {
|
||||||
log.Fatalf(regErrF, metricName, err)
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return summary
|
return summary, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Event interface {
|
type Event interface {
|
||||||
|
@ -240,37 +240,48 @@ func (b *Exporter) Listen(e <-chan Events) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
counter := b.Counters.Get(
|
counter, err := b.Counters.Get(
|
||||||
b.suffix(metricName, "counter"),
|
b.suffix(metricName, "counter"),
|
||||||
prometheusLabels,
|
prometheusLabels,
|
||||||
)
|
)
|
||||||
|
if err == nil {
|
||||||
|
counter.Add(event.Value())
|
||||||
|
|
||||||
counter.Add(event.Value())
|
eventStats.WithLabelValues("counter").Inc()
|
||||||
|
} else {
|
||||||
eventStats.WithLabelValues("counter").Inc()
|
log.Errorf(regErrF, metricName, err)
|
||||||
|
}
|
||||||
|
|
||||||
case *GaugeEvent:
|
case *GaugeEvent:
|
||||||
gauge := b.Gauges.Get(
|
gauge, err := b.Gauges.Get(
|
||||||
b.suffix(metricName, "gauge"),
|
b.suffix(metricName, "gauge"),
|
||||||
prometheusLabels,
|
prometheusLabels,
|
||||||
)
|
)
|
||||||
|
|
||||||
if ev.relative {
|
if err == nil {
|
||||||
gauge.Add(event.Value())
|
if ev.relative {
|
||||||
|
gauge.Add(event.Value())
|
||||||
|
} else {
|
||||||
|
gauge.Set(event.Value())
|
||||||
|
}
|
||||||
|
|
||||||
|
eventStats.WithLabelValues("gauge").Inc()
|
||||||
} else {
|
} else {
|
||||||
gauge.Set(event.Value())
|
log.Errorf(regErrF, metricName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
eventStats.WithLabelValues("gauge").Inc()
|
|
||||||
|
|
||||||
case *TimerEvent:
|
case *TimerEvent:
|
||||||
summary := b.Summaries.Get(
|
summary, err := b.Summaries.Get(
|
||||||
b.suffix(metricName, "timer"),
|
b.suffix(metricName, "timer"),
|
||||||
prometheusLabels,
|
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:
|
default:
|
||||||
log.Errorln("Unsupported event type")
|
log.Errorln("Unsupported event type")
|
||||||
|
|
Loading…
Reference in a new issue