Documentation ¶
Overview ¶
Package prometheus implements an prometheus stats client.
Index ¶
- func RegisterCounter(stats *statter.Statter, name string, lblNames []string, help string) bool
- func RegisterGauge(stats *statter.Statter, name string, lblNames []string, help string) bool
- func RegisterHistogram(stats *statter.Statter, name string, lblNames []string, buckets []float64, ...) bool
- func SetMetricBuckets(stats *statter.Statter, name string, buckets []float64)deprecated
- type Option
- type Prometheus
- func (p *Prometheus) Close() error
- func (p *Prometheus) Counter(name string, v int64, tags [][2]string)
- func (p *Prometheus) Gauge(name string, v float64, tags [][2]string)
- func (p *Prometheus) Handler() http.Handler
- func (p *Prometheus) Histogram(name string, tags [][2]string) func(v float64)
- func (p *Prometheus) Timing(name string, tags [][2]string) func(v time.Duration)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterCounter ¶ added in v2.2.0
RegisterCounter registers a counter with the given label names with the prometheus registrar, returning false if it has already been registered.
Example ¶
reporter := prometheus.New("my-namespace") stats := statter.New(reporter, 10*time.Second).With("my-prefix") prometheus.RegisterCounter(stats, "my-counter", []string{"tag"}, "my awesome counter")
Output:
func RegisterGauge ¶ added in v2.2.0
RegisterGauge registers a gauge with the given label names with the prometheus registrar, returning false if it has already been registered.
Example ¶
reporter := prometheus.New("my-namespace") stats := statter.New(reporter, 10*time.Second).With("my-prefix") prometheus.RegisterGauge(stats, "my-gauge", []string{"tag"}, "my awesome gauge")
Output:
func RegisterHistogram ¶ added in v2.2.0
func RegisterHistogram(stats *statter.Statter, name string, lblNames []string, buckets []float64, help string) bool
RegisterHistogram registers a histogram with the given label names and buckets with the prometheus registrar, returning false if it has already been registered.
Example ¶
reporter := prometheus.New("my-namespace") stats := statter.New(reporter, 10*time.Second).With("my-prefix") buckets := []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10} prometheus.RegisterHistogram(stats, "my-gauge", []string{"tag"}, buckets, "my awesome histogram")
Output:
func SetMetricBuckets
deprecated
added in
v2.1.1
SetMetricBuckets sets the buckets for a metric by name.
This must be called before the metric is used, otherwise will be ignored or can have unexpected results.
Deprecated: Use RegisterHistogram instead, this function will be removed in a future release.
Types ¶
type Option ¶
type Option func(p *Prometheus)
Option represents statsd option function.
func WithBuckets ¶
WithBuckets sets the buckets to used with histograms.
type Prometheus ¶
type Prometheus struct {
// contains filtered or unexported fields
}
Prometheus is a prometheus stats collector.
func New ¶
func New(namespace string, opts ...Option) *Prometheus
New returns a new prometheus reporter.
Example ¶
buckets := []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10} reporter := prometheus.New("my-namespace", prometheus.WithBuckets(buckets)) statter.New(reporter, 10*time.Second)
Output:
func (*Prometheus) Close ¶
func (p *Prometheus) Close() error
Close closes the client and flushes buffered stats, if applicable.
func (*Prometheus) Counter ¶
func (p *Prometheus) Counter(name string, v int64, tags [][2]string)
Counter reports a counter value.
func (*Prometheus) Gauge ¶
func (p *Prometheus) Gauge(name string, v float64, tags [][2]string)
Gauge reports a gauge value.
func (*Prometheus) Handler ¶
func (p *Prometheus) Handler() http.Handler
Handler gets the prometheus HTTP handler.