forked from go-kit/kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prometheus.go
63 lines (55 loc) · 2.04 KB
/
prometheus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package provider
import (
stdprometheus "github.com/prometheus/client_golang/prometheus"
"github.com/go-kit/kit/metrics"
"github.com/go-kit/kit/metrics/prometheus"
)
type prometheusProvider struct {
namespace string
subsystem string
}
// NewPrometheusProvider returns a Provider that produces Prometheus metrics.
// Namespace and subsystem are applied to all produced metrics.
func NewPrometheusProvider(namespace, subsystem string) Provider {
return &prometheusProvider{
namespace: namespace,
subsystem: subsystem,
}
}
// NewCounter implements Provider via prometheus.NewCounterFrom, i.e. the
// counter is registered. The metric's namespace and subsystem are taken from
// the Provider. Help is set to the name of the metric, and no const label names
// are set.
func (p *prometheusProvider) NewCounter(name string) metrics.Counter {
return prometheus.NewCounterFrom(stdprometheus.CounterOpts{
Namespace: p.namespace,
Subsystem: p.subsystem,
Name: name,
Help: name,
}, []string{})
}
// NewGauge implements Provider via prometheus.NewGaugeFrom, i.e. the gauge is
// registered. The metric's namespace and subsystem are taken from the Provider.
// Help is set to the name of the metric, and no const label names are set.
func (p *prometheusProvider) NewGauge(name string) metrics.Gauge {
return prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Namespace: p.namespace,
Subsystem: p.subsystem,
Name: name,
Help: name,
}, []string{})
}
// NewGauge implements Provider via prometheus.NewSummaryFrom, i.e. the summary
// is registered. The metric's namespace and subsystem are taken from the
// Provider. Help is set to the name of the metric, and no const label names are
// set. Buckets are ignored.
func (p *prometheusProvider) NewHistogram(name string, _ int) metrics.Histogram {
return prometheus.NewSummaryFrom(stdprometheus.SummaryOpts{
Namespace: p.namespace,
Subsystem: p.subsystem,
Name: name,
Help: name,
}, []string{})
}
// Stop implements Provider, but is a no-op.
func (p *prometheusProvider) Stop() {}