prometheus

package
v0.6.49 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const ObservationMaxAge = 10 * time.Minute

ObservationMaxAge defines the duration for which an observation stays relevant for the summary. Only applies to pre-calculated quantiles, does not apply to _sum and _count. Must be positive. The default value is DefMaxAge.

Variables

View Source
var (
	// DefaultPrometheusOpts is the default set of options used when creating a
	// Sink.
	DefaultPrometheusOpts = Opts{
		Expiration: 60 * time.Second,
		Name:       "default_prometheus_sink",
	}
)

Functions

This section is empty.

Types

type CounterDefinition

type CounterDefinition struct {
	Name      string
	ConstTags []metrics.Tag
	Help      string
}

CounterDefinition can be provided to PrometheusOpts to declare a constant counter that is not deleted on expiry.

type GaugeDefinition

type GaugeDefinition struct {
	Name      string
	ConstTags []metrics.Tag
	Help      string
}

GaugeDefinition can be provided to PrometheusOpts to declare a constant gauge that is not deleted on expiry.

type Opts

type Opts struct {
	// Expiration is the duration a metric is valid for, after which it will be
	// untracked. If the value is zero, a metric is never expired.
	Expiration time.Duration
	Registerer prometheus.Registerer

	// Gauges, Summaries, and Counters allow us to pre-declare metrics by giving
	// their Name, Help, and ConstLabels to the Sink when it is created.
	// Metrics declared in this way will be initialized at zero and will not be
	// deleted or altered when their expiry is reached.
	//
	// Ex: PrometheusOpts{
	//     Expiration: 10 * time.Second,
	//     Gauges: []GaugeDefinition{
	//         {
	//           Name: "application_component_measurement"},
	//           Help: "application_component_measurement provides an example of how to declare static metrics",
	//           ConstLabels: []metrics.Label{ { Name: "my_label", Value: "does_not_change" }, },
	//         },
	//     },
	// }
	GaugeDefinitions   []GaugeDefinition
	SummaryDefinitions []SummaryDefinition
	CounterDefinitions []CounterDefinition
	Name               string

	// Help of the metrics
	Help map[string]string
}

Opts is used to configure the Prometheus Sink

type PushSink

type PushSink struct {
	*Sink
	// contains filtered or unexported fields
}

PushSink wraps a normal prometheus sink and provides an address and facilities to export it to an address on an interval.

func NewPushSink

func NewPushSink(address string, pushInterval time.Duration, name string) (*PushSink, error)

NewPushSink creates a PrometheusPushSink by taking an address, interval, and destination name.

func (*PushSink) Shutdown

func (s *PushSink) Shutdown()

Shutdown tears down the PrometheusPushSink, and blocks while flushing metrics to the backend.

type Sink

type Sink struct {
	// contains filtered or unexported fields
}

Sink provides a MetricSink that can be used with a prometheus server.

func NewSink

func NewSink() (*Sink, error)

NewSink creates a new Sink using the default options.

func NewSinkFrom

func NewSinkFrom(opts Opts) (*Sink, error)

NewSinkFrom creates a new Sink using the passed options.

func (*Sink) AddSample

func (p *Sink) AddSample(parts string, val float64, labels []metrics.Tag)

AddSample is for timing information, where quantiles are used

func (*Sink) Collect

func (p *Sink) Collect(c chan<- prometheus.Metric)

Collect meets the collection interface and allows us to enforce our expiration logic to clean up ephemeral metrics if their value haven't been set for a duration exceeding our allowed expiration time.

func (*Sink) Describe

func (p *Sink) Describe(c chan<- *prometheus.Desc)

Describe sends a Collector.Describe value from the descriptor created around Sink.Name Note that we cannot describe all the metrics (gauges, counters, summaries) in the sink as metrics can be added at any point during the lifecycle of the sink, which does not respect the idempotency aspect of the Collector.Describe() interface

func (*Sink) IncrCounter

func (p *Sink) IncrCounter(parts string, val float64, labels []metrics.Tag)

IncrCounter should accumulate values

func (*Sink) SetGauge

func (p *Sink) SetGauge(parts string, val float64, labels []metrics.Tag)

SetGauge should retain the last value it is set to

type SummaryDefinition

type SummaryDefinition struct {
	Name      string
	ConstTags []metrics.Tag
	Help      string
}

SummaryDefinition can be provided to PrometheusOpts to declare a constant summary that is not deleted on expiry.

Jump to

Keyboard shortcuts

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