mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-12-01 19:51:00 +00:00
Allow help text to be customized (#87)
* Updated mappings to accept custom help text in YAML config * Updated exporter to display configured help messages * Update README to reflect aditional configurability * Removed inaccurate comment * Removed some cruft from a rebase
This commit is contained in:
parent
9accf494a9
commit
ab2a88c06f
3 changed files with 33 additions and 8 deletions
11
README.md
11
README.md
|
@ -128,6 +128,17 @@ follows:
|
||||||
=> test_web__server_foo_bar{}
|
=> test_web__server_foo_bar{}
|
||||||
|
|
||||||
|
|
||||||
|
If the default metric help text is insufficient for your needs you may use the YAML
|
||||||
|
configuration to specify a custom help text for each mapping:
|
||||||
|
```yaml
|
||||||
|
mappings:
|
||||||
|
- match: http.request.*
|
||||||
|
help: "Total number of http requests"
|
||||||
|
labels:
|
||||||
|
name: "http_requests_total"
|
||||||
|
code: "$1"
|
||||||
|
```
|
||||||
|
|
||||||
In the configuration, one may also set the timer type to "histogram". The
|
In the configuration, one may also set the timer type to "histogram". The
|
||||||
default is "summary" as in the plain text configuration format. For example,
|
default is "summary" as in the plain text configuration format. For example,
|
||||||
to set the timer type for a single metric:
|
to set the timer type for a single metric:
|
||||||
|
|
29
exporter.go
29
exporter.go
|
@ -71,13 +71,13 @@ func NewCounterContainer() *CounterContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CounterContainer) Get(metricName string, labels prometheus.Labels) (prometheus.Counter, error) {
|
func (c *CounterContainer) Get(metricName string, labels prometheus.Labels, help string) (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 {
|
||||||
counter = prometheus.NewCounter(prometheus.CounterOpts{
|
counter = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
Name: metricName,
|
Name: metricName,
|
||||||
Help: defaultHelp,
|
Help: help,
|
||||||
ConstLabels: labels,
|
ConstLabels: labels,
|
||||||
})
|
})
|
||||||
if err := prometheus.Register(counter); err != nil {
|
if err := prometheus.Register(counter); err != nil {
|
||||||
|
@ -98,13 +98,13 @@ func NewGaugeContainer() *GaugeContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GaugeContainer) Get(metricName string, labels prometheus.Labels) (prometheus.Gauge, error) {
|
func (c *GaugeContainer) Get(metricName string, labels prometheus.Labels, help string) (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 {
|
||||||
gauge = prometheus.NewGauge(prometheus.GaugeOpts{
|
gauge = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Name: metricName,
|
Name: metricName,
|
||||||
Help: defaultHelp,
|
Help: help,
|
||||||
ConstLabels: labels,
|
ConstLabels: labels,
|
||||||
})
|
})
|
||||||
if err := prometheus.Register(gauge); err != nil {
|
if err := prometheus.Register(gauge); err != nil {
|
||||||
|
@ -125,14 +125,14 @@ func NewSummaryContainer() *SummaryContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SummaryContainer) Get(metricName string, labels prometheus.Labels) (prometheus.Summary, error) {
|
func (c *SummaryContainer) Get(metricName string, labels prometheus.Labels, help string) (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 {
|
||||||
summary = prometheus.NewSummary(
|
summary = prometheus.NewSummary(
|
||||||
prometheus.SummaryOpts{
|
prometheus.SummaryOpts{
|
||||||
Name: metricName,
|
Name: metricName,
|
||||||
Help: defaultHelp,
|
Help: help,
|
||||||
ConstLabels: labels,
|
ConstLabels: labels,
|
||||||
})
|
})
|
||||||
if err := prometheus.Register(summary); err != nil {
|
if err := prometheus.Register(summary); err != nil {
|
||||||
|
@ -155,7 +155,7 @@ func NewHistogramContainer(mapper *metricMapper) *HistogramContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HistogramContainer) Get(metricName string, labels prometheus.Labels, mapping *metricMapping) (prometheus.Histogram, error) {
|
func (c *HistogramContainer) Get(metricName string, labels prometheus.Labels, help string, mapping *metricMapping) (prometheus.Histogram, error) {
|
||||||
hash := hashNameAndLabels(metricName, labels)
|
hash := hashNameAndLabels(metricName, labels)
|
||||||
histogram, ok := c.Elements[hash]
|
histogram, ok := c.Elements[hash]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -166,7 +166,7 @@ func (c *HistogramContainer) Get(metricName string, labels prometheus.Labels, ma
|
||||||
histogram = prometheus.NewHistogram(
|
histogram = prometheus.NewHistogram(
|
||||||
prometheus.HistogramOpts{
|
prometheus.HistogramOpts{
|
||||||
Name: metricName,
|
Name: metricName,
|
||||||
Help: defaultHelp,
|
Help: help,
|
||||||
ConstLabels: labels,
|
ConstLabels: labels,
|
||||||
Buckets: buckets,
|
Buckets: buckets,
|
||||||
})
|
})
|
||||||
|
@ -244,10 +244,19 @@ func (b *Exporter) Listen(e <-chan Events) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, event := range events {
|
for _, event := range events {
|
||||||
|
var help string
|
||||||
metricName := ""
|
metricName := ""
|
||||||
prometheusLabels := event.Labels()
|
prometheusLabels := event.Labels()
|
||||||
|
|
||||||
mapping, labels, present := b.mapper.getMapping(event.MetricName())
|
mapping, labels, present := b.mapper.getMapping(event.MetricName())
|
||||||
|
if mapping == nil {
|
||||||
|
mapping = &metricMapping{}
|
||||||
|
}
|
||||||
|
if mapping.HelpText == "" {
|
||||||
|
help = defaultHelp
|
||||||
|
} else {
|
||||||
|
help = mapping.HelpText
|
||||||
|
}
|
||||||
if present {
|
if present {
|
||||||
metricName = labels["name"]
|
metricName = labels["name"]
|
||||||
for label, value := range labels {
|
for label, value := range labels {
|
||||||
|
@ -273,6 +282,7 @@ func (b *Exporter) Listen(e <-chan Events) {
|
||||||
counter, err := b.Counters.Get(
|
counter, err := b.Counters.Get(
|
||||||
metricName,
|
metricName,
|
||||||
prometheusLabels,
|
prometheusLabels,
|
||||||
|
help,
|
||||||
)
|
)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
counter.Add(event.Value())
|
counter.Add(event.Value())
|
||||||
|
@ -287,6 +297,7 @@ func (b *Exporter) Listen(e <-chan Events) {
|
||||||
gauge, err := b.Gauges.Get(
|
gauge, err := b.Gauges.Get(
|
||||||
metricName,
|
metricName,
|
||||||
prometheusLabels,
|
prometheusLabels,
|
||||||
|
help,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -316,6 +327,7 @@ func (b *Exporter) Listen(e <-chan Events) {
|
||||||
histogram, err := b.Histograms.Get(
|
histogram, err := b.Histograms.Get(
|
||||||
metricName,
|
metricName,
|
||||||
prometheusLabels,
|
prometheusLabels,
|
||||||
|
help,
|
||||||
mapping,
|
mapping,
|
||||||
)
|
)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -330,6 +342,7 @@ func (b *Exporter) Listen(e <-chan Events) {
|
||||||
summary, err := b.Summaries.Get(
|
summary, err := b.Summaries.Get(
|
||||||
metricName,
|
metricName,
|
||||||
prometheusLabels,
|
prometheusLabels,
|
||||||
|
help,
|
||||||
)
|
)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
summary.Observe(event.Value())
|
summary.Observe(event.Value())
|
||||||
|
|
|
@ -52,6 +52,7 @@ type metricMapping struct {
|
||||||
TimerType timerType `yaml:"timer_type"`
|
TimerType timerType `yaml:"timer_type"`
|
||||||
Buckets []float64 `yaml:"buckets"`
|
Buckets []float64 `yaml:"buckets"`
|
||||||
MatchType matchType `yaml:"match_type"`
|
MatchType matchType `yaml:"match_type"`
|
||||||
|
HelpText string `yaml:"help"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *metricMapper) initFromYAMLString(fileContents string) error {
|
func (m *metricMapper) initFromYAMLString(fileContents string) error {
|
||||||
|
|
Loading…
Reference in a new issue