prometheus

package
v2.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 10 Imported by: 2

Documentation

Overview

Package prometheus implements an prometheus stats client.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterCounter added in v2.2.0

func RegisterCounter(stats *statter.Statter, name string, lblNames []string, help string) bool

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

func RegisterGauge(stats *statter.Statter, name string, lblNames []string, help string) bool

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

func SetMetricBuckets(stats *statter.Statter, name string, buckets []float64)

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

func WithBuckets(buckets []float64) Option

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.

func (*Prometheus) Histogram

func (p *Prometheus) Histogram(name string, tags [][2]string) func(v float64)

Histogram reports a histogram value.

func (*Prometheus) Timing

func (p *Prometheus) Timing(name string, tags [][2]string) func(v time.Duration)

Timing reports a timing value as a histogram in seconds.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL