forked from mirrors/statsd_exporter
Merge pull request #99 from drawks/remove_add_suffix_flag
Removes `-statsd.add-suffix` option flag
This commit is contained in:
commit
bd0f2139af
4 changed files with 11 additions and 34 deletions
10
README.md
10
README.md
|
@ -48,8 +48,6 @@ without values (`#some_tag`) are not supported.
|
||||||
If set use a syslog logger or JSON logging. Example: logger:syslog?appname=bob&local=7 or logger:stdout?json=true. Defaults to stderr.
|
If set use a syslog logger or JSON logging. Example: logger:syslog?appname=bob&local=7 or logger:stdout?json=true. Defaults to stderr.
|
||||||
-log.level value
|
-log.level value
|
||||||
Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal].
|
Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal].
|
||||||
-statsd.add-suffix
|
|
||||||
Add the metric type (counter/gauge/timer) as suffix to the generated Prometheus metric (NOT recommended, but set by default for backward compatibility). (default true)
|
|
||||||
-statsd.listen-address string
|
-statsd.listen-address string
|
||||||
The UDP address on which to receive statsd metric lines. DEPRECATED, use statsd.listen-udp instead.
|
The UDP address on which to receive statsd metric lines. DEPRECATED, use statsd.listen-udp instead.
|
||||||
-statsd.listen-tcp string
|
-statsd.listen-tcp string
|
||||||
|
@ -98,13 +96,7 @@ In general, the different metric types are translated as follows:
|
||||||
-> Prometheus counter (suffix `_total`) <-- indicates total time spent
|
-> Prometheus counter (suffix `_total`) <-- indicates total time spent
|
||||||
-> Prometheus counter (suffix `_count`) <-- indicates total number of timer events
|
-> Prometheus counter (suffix `_count`) <-- indicates total number of timer events
|
||||||
|
|
||||||
If `-statsd.add-suffix` is set, the exporter appends the metric type (`_gauge`,
|
An example mapping configuration:
|
||||||
`_counter`, `_timer`) to the resulting metrics. This is enabled by default for
|
|
||||||
backward compatibility but discouraged to use. Instead, it is better to
|
|
||||||
explicitly define the full metric name in your mapping and run the exporter
|
|
||||||
with `-statsd.add-suffix=false`.
|
|
||||||
|
|
||||||
An example mapping configuration with `-statsd.add-suffix=false`:
|
|
||||||
|
|
||||||
# comments are allowed
|
# comments are allowed
|
||||||
test.dispatcher.*.*.*
|
test.dispatcher.*.*.*
|
||||||
|
|
20
exporter.go
20
exporter.go
|
@ -223,7 +223,6 @@ type Exporter struct {
|
||||||
Summaries *SummaryContainer
|
Summaries *SummaryContainer
|
||||||
Histograms *HistogramContainer
|
Histograms *HistogramContainer
|
||||||
mapper *metricMapper
|
mapper *metricMapper
|
||||||
addSuffix bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func escapeMetricName(metricName string) string {
|
func escapeMetricName(metricName string) string {
|
||||||
|
@ -237,14 +236,6 @@ func escapeMetricName(metricName string) string {
|
||||||
return metricName
|
return metricName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Exporter) suffix(metricName, suffix string) string {
|
|
||||||
str := metricName
|
|
||||||
if b.addSuffix {
|
|
||||||
str += "_" + suffix
|
|
||||||
}
|
|
||||||
return str
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Exporter) Listen(e <-chan Events) {
|
func (b *Exporter) Listen(e <-chan Events) {
|
||||||
for {
|
for {
|
||||||
events, ok := <-e
|
events, ok := <-e
|
||||||
|
@ -280,7 +271,7 @@ func (b *Exporter) Listen(e <-chan Events) {
|
||||||
}
|
}
|
||||||
|
|
||||||
counter, err := b.Counters.Get(
|
counter, err := b.Counters.Get(
|
||||||
b.suffix(metricName, "counter"),
|
metricName,
|
||||||
prometheusLabels,
|
prometheusLabels,
|
||||||
)
|
)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -294,7 +285,7 @@ func (b *Exporter) Listen(e <-chan Events) {
|
||||||
|
|
||||||
case *GaugeEvent:
|
case *GaugeEvent:
|
||||||
gauge, err := b.Gauges.Get(
|
gauge, err := b.Gauges.Get(
|
||||||
b.suffix(metricName, "gauge"),
|
metricName,
|
||||||
prometheusLabels,
|
prometheusLabels,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -323,7 +314,7 @@ func (b *Exporter) Listen(e <-chan Events) {
|
||||||
switch t {
|
switch t {
|
||||||
case timerTypeHistogram:
|
case timerTypeHistogram:
|
||||||
histogram, err := b.Histograms.Get(
|
histogram, err := b.Histograms.Get(
|
||||||
b.suffix(metricName, "timer"),
|
metricName,
|
||||||
prometheusLabels,
|
prometheusLabels,
|
||||||
mapping,
|
mapping,
|
||||||
)
|
)
|
||||||
|
@ -337,7 +328,7 @@ func (b *Exporter) Listen(e <-chan Events) {
|
||||||
|
|
||||||
case timerTypeDefault, timerTypeSummary:
|
case timerTypeDefault, timerTypeSummary:
|
||||||
summary, err := b.Summaries.Get(
|
summary, err := b.Summaries.Get(
|
||||||
b.suffix(metricName, "timer"),
|
metricName,
|
||||||
prometheusLabels,
|
prometheusLabels,
|
||||||
)
|
)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -360,9 +351,8 @@ func (b *Exporter) Listen(e <-chan Events) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExporter(mapper *metricMapper, addSuffix bool) *Exporter {
|
func NewExporter(mapper *metricMapper) *Exporter {
|
||||||
return &Exporter{
|
return &Exporter{
|
||||||
addSuffix: addSuffix,
|
|
||||||
Counters: NewCounterContainer(),
|
Counters: NewCounterContainer(),
|
||||||
Gauges: NewGaugeContainer(),
|
Gauges: NewGaugeContainer(),
|
||||||
Summaries: NewSummaryContainer(),
|
Summaries: NewSummaryContainer(),
|
||||||
|
|
|
@ -44,7 +44,7 @@ func TestNegativeCounter(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
events <- c
|
events <- c
|
||||||
ex := NewExporter(&metricMapper{}, true)
|
ex := NewExporter(&metricMapper{})
|
||||||
|
|
||||||
// Close channel to signify we are done with the listener after a short period.
|
// Close channel to signify we are done with the listener after a short period.
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -60,7 +60,7 @@ func TestNegativeCounter(t *testing.T) {
|
||||||
// It sends the same tags first with a valid value, then with an invalid one.
|
// It sends the same tags first with a valid value, then with an invalid one.
|
||||||
// The exporter should not panic, but drop the invalid event
|
// The exporter should not panic, but drop the invalid event
|
||||||
func TestInvalidUtf8InDatadogTagValue(t *testing.T) {
|
func TestInvalidUtf8InDatadogTagValue(t *testing.T) {
|
||||||
ex := NewExporter(&metricMapper{}, true)
|
ex := NewExporter(&metricMapper{})
|
||||||
for _, l := range []statsDPacketHandler{&StatsDUDPListener{}, &mockStatsDTCPListener{}} {
|
for _, l := range []statsDPacketHandler{&StatsDUDPListener{}, &mockStatsDTCPListener{}} {
|
||||||
events := make(chan Events, 2)
|
events := make(chan Events, 2)
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ func TestHistogramUnits(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
events <- c
|
events <- c
|
||||||
ex := NewExporter(&metricMapper{}, true)
|
ex := NewExporter(&metricMapper{})
|
||||||
ex.mapper.Defaults.TimerType = timerTypeHistogram
|
ex.mapper.Defaults.TimerType = timerTypeHistogram
|
||||||
|
|
||||||
// Close channel to signify we are done with the listener after a short period.
|
// Close channel to signify we are done with the listener after a short period.
|
||||||
|
@ -105,7 +105,7 @@ func TestHistogramUnits(t *testing.T) {
|
||||||
close(events)
|
close(events)
|
||||||
}()
|
}()
|
||||||
mock := &MockHistogram{}
|
mock := &MockHistogram{}
|
||||||
key := hashNameAndLabels(name+"_timer", nil)
|
key := hashNameAndLabels(name, nil)
|
||||||
ex.Histograms.Elements[key] = mock
|
ex.Histograms.Elements[key] = mock
|
||||||
ex.Listen(events)
|
ex.Listen(events)
|
||||||
if mock.value == 300 {
|
if mock.value == 300 {
|
||||||
|
|
7
main.go
7
main.go
|
@ -39,7 +39,6 @@ var (
|
||||||
statsdListenTCP = flag.String("statsd.listen-tcp", ":9125", "The TCP address on which to receive statsd metric lines. \"\" disables it.")
|
statsdListenTCP = flag.String("statsd.listen-tcp", ":9125", "The TCP address on which to receive statsd metric lines. \"\" disables it.")
|
||||||
mappingConfig = flag.String("statsd.mapping-config", "", "Metric mapping configuration file name.")
|
mappingConfig = flag.String("statsd.mapping-config", "", "Metric mapping configuration file name.")
|
||||||
readBuffer = flag.Int("statsd.read-buffer", 0, "Size (in bytes) of the operating system's transmit read buffer associated with the UDP connection. Please make sure the kernel parameters net.core.rmem_max is set to a value greater than the value specified.")
|
readBuffer = flag.Int("statsd.read-buffer", 0, "Size (in bytes) of the operating system's transmit read buffer associated with the UDP connection. Please make sure the kernel parameters net.core.rmem_max is set to a value greater than the value specified.")
|
||||||
addSuffix = flag.Bool("statsd.add-suffix", true, "Add the metric type (counter/gauge/timer) as suffix to the generated Prometheus metric (NOT recommended, but set by default for backward compatibility).")
|
|
||||||
showVersion = flag.Bool("version", false, "Print version information.")
|
showVersion = flag.Bool("version", false, "Print version information.")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -147,10 +146,6 @@ func main() {
|
||||||
log.Fatalln("At least one of UDP/TCP listeners must be specified.")
|
log.Fatalln("At least one of UDP/TCP listeners must be specified.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if *addSuffix {
|
|
||||||
log.Warnln("Warning: Using -statsd.add-suffix is discouraged. We recommend explicitly naming metrics appropriately in the mapping configuration.")
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Infoln("Starting StatsD -> Prometheus Exporter", version.Info())
|
log.Infoln("Starting StatsD -> Prometheus Exporter", version.Info())
|
||||||
log.Infoln("Build context", version.BuildContext())
|
log.Infoln("Build context", version.BuildContext())
|
||||||
log.Infof("Accepting StatsD Traffic: UDP %v, TCP %v", *statsdListenUDP, *statsdListenTCP)
|
log.Infof("Accepting StatsD Traffic: UDP %v, TCP %v", *statsdListenUDP, *statsdListenTCP)
|
||||||
|
@ -199,6 +194,6 @@ func main() {
|
||||||
}
|
}
|
||||||
go watchConfig(*mappingConfig, mapper)
|
go watchConfig(*mappingConfig, mapper)
|
||||||
}
|
}
|
||||||
exporter := NewExporter(mapper, *addSuffix)
|
exporter := NewExporter(mapper)
|
||||||
exporter.Listen(events)
|
exporter.Listen(events)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue