mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-26 09:11:01 +00:00
Allow overriding default timing type
This commit is contained in:
parent
3048412df6
commit
1488f0f902
1 changed files with 19 additions and 5 deletions
24
exporter.go
24
exporter.go
|
@ -143,11 +143,13 @@ func (c *SummaryContainer) Get(metricName string, labels prometheus.Labels) prom
|
||||||
|
|
||||||
type HistogramContainer struct {
|
type HistogramContainer struct {
|
||||||
Elements map[uint64]prometheus.Histogram
|
Elements map[uint64]prometheus.Histogram
|
||||||
|
mapper *metricMapper
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHistogramContainer() *HistogramContainer {
|
func NewHistogramContainer(mapper *metricMapper) *HistogramContainer {
|
||||||
return &HistogramContainer{
|
return &HistogramContainer{
|
||||||
Elements: make(map[uint64]prometheus.Histogram),
|
Elements: make(map[uint64]prometheus.Histogram),
|
||||||
|
mapper: mapper,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,13 +157,16 @@ func (c *HistogramContainer) Get(metricName string, labels prometheus.Labels, ma
|
||||||
hash := hashNameAndLabels(metricName, labels)
|
hash := hashNameAndLabels(metricName, labels)
|
||||||
histogram, ok := c.Elements[hash]
|
histogram, ok := c.Elements[hash]
|
||||||
if !ok {
|
if !ok {
|
||||||
// TODO: buckets
|
buckets := c.mapper.Defaults.Buckets
|
||||||
|
if mapping != nil && mapping.Buckets != nil && len(mapping.Buckets) > 0 {
|
||||||
|
buckets = mapping.Buckets
|
||||||
|
}
|
||||||
histogram = prometheus.NewHistogram(
|
histogram = prometheus.NewHistogram(
|
||||||
prometheus.HistogramOpts{
|
prometheus.HistogramOpts{
|
||||||
Name: metricName,
|
Name: metricName,
|
||||||
Help: defaultHelp,
|
Help: defaultHelp,
|
||||||
ConstLabels: labels,
|
ConstLabels: labels,
|
||||||
Buckets: mapping.Buckets,
|
Buckets: buckets,
|
||||||
})
|
})
|
||||||
c.Elements[hash] = histogram
|
c.Elements[hash] = histogram
|
||||||
if err := prometheus.Register(histogram); err != nil {
|
if err := prometheus.Register(histogram); err != nil {
|
||||||
|
@ -294,7 +299,15 @@ func (b *Exporter) Listen(e <-chan Events) {
|
||||||
eventStats.WithLabelValues("gauge").Inc()
|
eventStats.WithLabelValues("gauge").Inc()
|
||||||
|
|
||||||
case *TimerEvent:
|
case *TimerEvent:
|
||||||
if mapping.TimerType == "histogram" {
|
timerType := ""
|
||||||
|
if mapping != nil {
|
||||||
|
timerType = mapping.TimerType
|
||||||
|
}
|
||||||
|
if timerType == "" {
|
||||||
|
timerType = b.mapper.Defaults.TimerType
|
||||||
|
}
|
||||||
|
|
||||||
|
if timerType == "histogram" {
|
||||||
histogram := b.Histograms.Get(
|
histogram := b.Histograms.Get(
|
||||||
b.suffix(metricName, "timer"),
|
b.suffix(metricName, "timer"),
|
||||||
prometheusLabels,
|
prometheusLabels,
|
||||||
|
@ -308,6 +321,7 @@ func (b *Exporter) Listen(e <-chan Events) {
|
||||||
)
|
)
|
||||||
summary.Observe(event.Value())
|
summary.Observe(event.Value())
|
||||||
}
|
}
|
||||||
|
|
||||||
eventStats.WithLabelValues("timer").Inc()
|
eventStats.WithLabelValues("timer").Inc()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -324,7 +338,7 @@ func NewExporter(mapper *metricMapper, addSuffix bool) *Exporter {
|
||||||
Counters: NewCounterContainer(),
|
Counters: NewCounterContainer(),
|
||||||
Gauges: NewGaugeContainer(),
|
Gauges: NewGaugeContainer(),
|
||||||
Summaries: NewSummaryContainer(),
|
Summaries: NewSummaryContainer(),
|
||||||
Histograms: NewHistogramContainer(),
|
Histograms: NewHistogramContainer(mapper),
|
||||||
mapper: mapper,
|
mapper: mapper,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue