mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-26 01:01:01 +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{}
|
||||
|
||||
|
||||
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
|
||||
default is "summary" as in the plain text configuration format. For example,
|
||||
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)
|
||||
counter, ok := c.Elements[hash]
|
||||
if !ok {
|
||||
counter = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Name: metricName,
|
||||
Help: defaultHelp,
|
||||
Help: help,
|
||||
ConstLabels: labels,
|
||||
})
|
||||
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)
|
||||
gauge, ok := c.Elements[hash]
|
||||
if !ok {
|
||||
gauge = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Name: metricName,
|
||||
Help: defaultHelp,
|
||||
Help: help,
|
||||
ConstLabels: labels,
|
||||
})
|
||||
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)
|
||||
summary, ok := c.Elements[hash]
|
||||
if !ok {
|
||||
summary = prometheus.NewSummary(
|
||||
prometheus.SummaryOpts{
|
||||
Name: metricName,
|
||||
Help: defaultHelp,
|
||||
Help: help,
|
||||
ConstLabels: labels,
|
||||
})
|
||||
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)
|
||||
histogram, ok := c.Elements[hash]
|
||||
if !ok {
|
||||
|
@ -166,7 +166,7 @@ func (c *HistogramContainer) Get(metricName string, labels prometheus.Labels, ma
|
|||
histogram = prometheus.NewHistogram(
|
||||
prometheus.HistogramOpts{
|
||||
Name: metricName,
|
||||
Help: defaultHelp,
|
||||
Help: help,
|
||||
ConstLabels: labels,
|
||||
Buckets: buckets,
|
||||
})
|
||||
|
@ -244,10 +244,19 @@ func (b *Exporter) Listen(e <-chan Events) {
|
|||
return
|
||||
}
|
||||
for _, event := range events {
|
||||
var help string
|
||||
metricName := ""
|
||||
prometheusLabels := event.Labels()
|
||||
|
||||
mapping, labels, present := b.mapper.getMapping(event.MetricName())
|
||||
if mapping == nil {
|
||||
mapping = &metricMapping{}
|
||||
}
|
||||
if mapping.HelpText == "" {
|
||||
help = defaultHelp
|
||||
} else {
|
||||
help = mapping.HelpText
|
||||
}
|
||||
if present {
|
||||
metricName = labels["name"]
|
||||
for label, value := range labels {
|
||||
|
@ -273,6 +282,7 @@ func (b *Exporter) Listen(e <-chan Events) {
|
|||
counter, err := b.Counters.Get(
|
||||
metricName,
|
||||
prometheusLabels,
|
||||
help,
|
||||
)
|
||||
if err == nil {
|
||||
counter.Add(event.Value())
|
||||
|
@ -287,6 +297,7 @@ func (b *Exporter) Listen(e <-chan Events) {
|
|||
gauge, err := b.Gauges.Get(
|
||||
metricName,
|
||||
prometheusLabels,
|
||||
help,
|
||||
)
|
||||
|
||||
if err == nil {
|
||||
|
@ -316,6 +327,7 @@ func (b *Exporter) Listen(e <-chan Events) {
|
|||
histogram, err := b.Histograms.Get(
|
||||
metricName,
|
||||
prometheusLabels,
|
||||
help,
|
||||
mapping,
|
||||
)
|
||||
if err == nil {
|
||||
|
@ -330,6 +342,7 @@ func (b *Exporter) Listen(e <-chan Events) {
|
|||
summary, err := b.Summaries.Get(
|
||||
metricName,
|
||||
prometheusLabels,
|
||||
help,
|
||||
)
|
||||
if err == nil {
|
||||
summary.Observe(event.Value())
|
||||
|
|
|
@ -52,6 +52,7 @@ type metricMapping struct {
|
|||
TimerType timerType `yaml:"timer_type"`
|
||||
Buckets []float64 `yaml:"buckets"`
|
||||
MatchType matchType `yaml:"match_type"`
|
||||
HelpText string `yaml:"help"`
|
||||
}
|
||||
|
||||
func (m *metricMapper) initFromYAMLString(fileContents string) error {
|
||||
|
|
Loading…
Reference in a new issue