Documentation ¶
Index ¶
- Constants
- Variables
- func AddGlobalLabel(name, value string) error
- func EnableMetricPersistence(key string) error
- func SetNamespace(namespace string) error
- func WriteMetrics(w io.Writer, permission api.Permission, expertiseLevel config.ExpertiseLevel)
- type Counter
- type Gauge
- type Histogram
- type Metric
- type Options
Constants ¶
const PrometheusFormatRequirement = "[a-zA-Z_][a-zA-Z0-9_]*"
PrometheusFormatRequirement is required format defined by prometheus for metric and label names.
Variables ¶
var ( // ErrAlreadyStarted is returned when an operation is only valid before the // first metric is registered, and is called after. ErrAlreadyStarted = errors.New("can only be changed before first metric is registered") // ErrAlreadyRegistered is returned when a metric with the same ID is // registered again. ErrAlreadyRegistered = errors.New("metric already registered") // ErrAlreadySet is returned when a value is already set and cannot be changed. ErrAlreadySet = errors.New("already set") )
var ( // ErrAlreadyInitialized is returned when trying to initialize an option // more than once. ErrAlreadyInitialized = errors.New("already initialized") )
Functions ¶
func AddGlobalLabel ¶
AddGlobalLabel adds a global label to all metrics. Global labels must be added before any metric is registered. Does not affect golang runtime metrics.
func EnableMetricPersistence ¶
EnableMetricPersistence enables metric persistence for metrics that opted for it. They given key is the database key where the metric data will be persisted. This call also directly loads the stored data from the database. The returned error is only about loading the metrics, not about enabling persistence. May only be called once.
func SetNamespace ¶
SetNamespace sets the namespace for all metrics. It is prefixed to all metric IDs. It must be set before any metric is registered. Does not affect golang runtime metrics.
func WriteMetrics ¶
func WriteMetrics(w io.Writer, permission api.Permission, expertiseLevel config.ExpertiseLevel)
WriteMetrics writes all metrics that match the given permission and expertiseLevel to the given writer.
Types ¶
type Counter ¶
Counter is a counter metric.
func NewCounter ¶
NewCounter registers a new counter metric.
func (Counter) LabeledID ¶
func (m Counter) LabeledID() string
LabeledID returns the Prometheus-compatible labeled ID of the metric.
func (Counter) Opts ¶
func (m Counter) Opts() *Options
Opts returns the metric options. They may not be modified.
func (Counter) WritePrometheus ¶
WritePrometheus writes the metric in the prometheus format to the given writer.
type Gauge ¶
Gauge is a gauge metric.
func NewGauge ¶
func NewGauge(id string, labels map[string]string, fn func() float64, opts *Options) (*Gauge, error)
NewGauge registers a new gauge metric.
func (Gauge) LabeledID ¶
func (m Gauge) LabeledID() string
LabeledID returns the Prometheus-compatible labeled ID of the metric.
func (Gauge) Opts ¶
func (m Gauge) Opts() *Options
Opts returns the metric options. They may not be modified.
func (Gauge) WritePrometheus ¶
WritePrometheus writes the metric in the prometheus format to the given writer.
type Histogram ¶
Histogram is a histogram metric.
func NewHistogram ¶
NewHistogram registers a new histogram metric.
func (Histogram) LabeledID ¶
func (m Histogram) LabeledID() string
LabeledID returns the Prometheus-compatible labeled ID of the metric.
func (Histogram) Opts ¶
func (m Histogram) Opts() *Options
Opts returns the metric options. They may not be modified.
func (Histogram) WritePrometheus ¶
WritePrometheus writes the metric in the prometheus format to the given writer.
type Metric ¶
type Metric interface { ID() string LabeledID() string Opts() *Options WritePrometheus(w io.Writer) }
Metric represents one or more metrics.
type Options ¶
type Options struct { // Name defines an optional human readable name for the metric. Name string // AlertLimit defines an upper limit that triggers an alert. AlertLimit float64 // AlertTimeframe defines an optional timeframe in seconds for which the // AlertLimit should be interpreted in. AlertTimeframe float64 // Permission defines the permission that is required to read the metric. Permission api.Permission // ExpertiseLevel defines the expertise level that the metric is meant for. ExpertiseLevel config.ExpertiseLevel // Persist enabled persisting the metric on shutdown and loading the previous // value at start. This is only supported for counters. Persist bool }
Options can be used to set advanced metric settings.