mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-29 18:50:59 +00:00
Merge pull request #162 from prometheus/grobie/reduce-indentation
Break out event handling into its own function
This commit is contained in:
commit
040760ec22
1 changed files with 125 additions and 120 deletions
25
exporter.go
25
exporter.go
|
@ -253,6 +253,8 @@ func escapeMetricName(metricName string) string {
|
||||||
return metricName
|
return metricName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Listen handles all events sent to the given channel sequentially. It
|
||||||
|
// terminates when the channel is closed.
|
||||||
func (b *Exporter) Listen(e <-chan Events) {
|
func (b *Exporter) Listen(e <-chan Events) {
|
||||||
for {
|
for {
|
||||||
events, ok := <-e
|
events, ok := <-e
|
||||||
|
@ -261,24 +263,29 @@ func (b *Exporter) Listen(e <-chan Events) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, event := range events {
|
for _, event := range events {
|
||||||
var help string
|
b.handleEvent(event)
|
||||||
metricName := ""
|
}
|
||||||
prometheusLabels := event.Labels()
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleEvent processes a single Event according to the configured mapping.
|
||||||
|
func (b *Exporter) handleEvent(event Event) {
|
||||||
mapping, labels, present := b.mapper.GetMapping(event.MetricName(), event.MetricType())
|
mapping, labels, present := b.mapper.GetMapping(event.MetricName(), event.MetricType())
|
||||||
if mapping == nil {
|
if mapping == nil {
|
||||||
mapping = &mapper.MetricMapping{}
|
mapping = &mapper.MetricMapping{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if mapping.Action == mapper.ActionTypeDrop {
|
if mapping.Action == mapper.ActionTypeDrop {
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if mapping.HelpText == "" {
|
help := defaultHelp
|
||||||
help = defaultHelp
|
if mapping.HelpText != "" {
|
||||||
} else {
|
|
||||||
help = mapping.HelpText
|
help = mapping.HelpText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metricName := ""
|
||||||
|
prometheusLabels := event.Labels()
|
||||||
if present {
|
if present {
|
||||||
metricName = escapeMetricName(mapping.Name)
|
metricName = escapeMetricName(mapping.Name)
|
||||||
for label, value := range labels {
|
for label, value := range labels {
|
||||||
|
@ -296,7 +303,7 @@ func (b *Exporter) Listen(e <-chan Events) {
|
||||||
if event.Value() < 0.0 {
|
if event.Value() < 0.0 {
|
||||||
log.Debugf("Counter %q is: '%f' (counter must be non-negative value)", metricName, event.Value())
|
log.Debugf("Counter %q is: '%f' (counter must be non-negative value)", metricName, event.Value())
|
||||||
eventStats.WithLabelValues("illegal_negative_counter").Inc()
|
eventStats.WithLabelValues("illegal_negative_counter").Inc()
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
counter, err := b.Counters.Get(
|
counter, err := b.Counters.Get(
|
||||||
|
@ -381,8 +388,6 @@ func (b *Exporter) Listen(e <-chan Events) {
|
||||||
log.Debugln("Unsupported event type")
|
log.Debugln("Unsupported event type")
|
||||||
eventStats.WithLabelValues("illegal").Inc()
|
eventStats.WithLabelValues("illegal").Inc()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExporter(mapper *mapper.MetricMapper) *Exporter {
|
func NewExporter(mapper *mapper.MetricMapper) *Exporter {
|
||||||
|
|
Loading…
Reference in a new issue