metrics

package module
v0.0.0-...-eb1144b Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 11 Imported by: 30

README

go-metric-registry

GoDoc

This is a Golang library wrapping Prometheus.

If you have any questions, or want to get attention for a PR or issue please reach out on the #logging-and-metrics channel in the cloudfoundry slack

Usage

This repository should be imported as:

import metrics "code.cloudfoundry.org/go-metric-registry"

An example app can be referenced in the examples directory.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter interface {
	Add(float64)
}

A cumulative metric that represents a single monotonically increasing counter whose value can only increase or be reset to zero on restart

type Gauge

type Gauge interface {
	Add(float64)
	Set(float64)
}

A single numerical value that can arbitrarily go up and down.

type Histogram

type Histogram interface {
	Observe(float64)
}

A histogram counts observations into buckets.

type MetricOption

type MetricOption func(o *prometheus.Opts)

Options applied to metrics on creation

func WithMetricLabels

func WithMetricLabels(labels map[string]string) MetricOption

Add these tags to the metrics

type Registry

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

The Registry keeps track of registered counters and gauges. Optionally, it can provide a server on a Prometheus-formatted endpoint.

func NewRegistry

func NewRegistry(logger *log.Logger, opts ...RegistryOption) *Registry

Registry will register the metrics route with the default http mux but will not start an http server. This is intentional so that we can combine metrics with other things like pprof into one server. To start a server just for metrics, use the WithServer RegistryOption

func (*Registry) NewCounter

func (p *Registry) NewCounter(name, helpText string, opts ...MetricOption) Counter

Creates new counter. When a duplicate is registered, the Registry will return the previously created metric.

func (*Registry) NewGauge

func (p *Registry) NewGauge(name, helpText string, opts ...MetricOption) Gauge

Creates new gauge. When a duplicate is registered, the Registry will return the previously created metric.

func (*Registry) NewHistogram

func (p *Registry) NewHistogram(name, helpText string, buckets []float64, opts ...MetricOption) Histogram

Creates new histogram. When a duplicate is registered, the Registry will return the previously created metric.

func (*Registry) Port

func (p *Registry) Port() string

Get the port of the running metrics server

func (*Registry) RegisterDebugMetrics

func (p *Registry) RegisterDebugMetrics()

func (*Registry) RemoveCounter

func (p *Registry) RemoveCounter(c Counter)

func (*Registry) RemoveGauge

func (p *Registry) RemoveGauge(g Gauge)

func (*Registry) RemoveHistogram

func (p *Registry) RemoveHistogram(h Histogram)

type RegistryOption

type RegistryOption func(r *Registry)

Options for registry initialization

func WithPublicServer

func WithPublicServer(port int) RegistryOption

Starts an http server on the given port to host metrics.

func WithServer

func WithServer(port int) RegistryOption

Starts an http server on localhost at the given port to host metrics.

func WithTLSServer

func WithTLSServer(port int, certFile, keyFile, caFile string) RegistryOption

Starts an https server on localhost at the given port to host metrics.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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