metrics

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultMetricsHandler = PrometheusHandler()
)

Functions

func Initialize

func Initialize(s string, buildInfo BuildInfo, option *Opts)

func NewWebService

func NewWebService(basePath string) *serviceBuilder

NewWebService returns new metrics web service builder

func PrometheusHandler

func PrometheusHandler() http.Handler

PrometheusHandler creates a new http.Handler that exposes Prometheus metrics over HTTP.

func RestfulFilter

func RestfulFilter() restful.FilterFunction

func ServePrometheus

func ServePrometheus(addr, endpoint string) error

ServePrometheus exposes Prometheus over HTTP on the given address and metrics endpoint. If you plan on exposing the metrics on an already existing HTTP server, use the PrometheusHandler instead.

func SetProvider

func SetProvider(p Provider)

SetProvider allow setting/replacing the default (Prometheus) metrics provider with a new one.

Types

type BuildInfo

type BuildInfo struct {
	RevisionID,
	BuildDate,
	Version,
	GitHash,
	RoleSeedingVersion string
}

type CounterMetric

type CounterMetric interface {
	Inc()
	Add(float64)
}

CounterMetric represents a counter metric.

func Counter

func Counter(name string, help string) CounterMetric

Counter creates a counter metric with default provider. Use this function, if the metric does not have any custom dynamic labels, which also gives the caller direct access to a CounterMetric.

type CounterVecMetric

type CounterVecMetric interface {
	With(labels map[string]string) CounterMetric
}

CounterVecMetric represents a vector counter metric containing a variation of the same metric under different labels.

func CounterVec

func CounterVec(name string, help string, labels []string) CounterVecMetric

CounterVec creates a counter vector metric with default provider. Use this function instead, if you plan on dynamically adding custom labels to the CounterMetric, which involves an extra step of calling .With(map[string]string{"label_name": "label_value"}), which then gives the caller access to a CounterMetric to work with.

type DBMetrics

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

func NewDBMetrics

func NewDBMetrics(metricsProvider Provider, dbName string, labels ...string) *DBMetrics

NewDBMetrics returns new DB metrics.

func (*DBMetrics) NewCall

func (d *DBMetrics) NewCall(action string) *dbCallMetrics

NewCall returns a new DB call metrics and start it.

type GaugeMetric

type GaugeMetric interface {
	Set(float64)
	Inc()
	Dec()
	Add(float64)
	Sub(float64)
	SetToCurrentTime()
}

GaugeMetric represents a single numerical value that can go up and down.

func Gauge

func Gauge(name string, help string) GaugeMetric

Gauge creates a gauge metric with default provider. Use this function, if the metric does not have any custom dynamic labels, which also gives the caller direct access to a GaugeMetric.

type GaugeVecMetric

type GaugeVecMetric interface {
	With(labels map[string]string) GaugeMetric
}

GaugeVecMetric represents a vector gauge metric containing a variation of the same metric under different labels.

func GaugeVec

func GaugeVec(name string, help string, labels []string) GaugeVecMetric

GaugeVec creates a gauge vector metric with default provider. Use this function instead, if you plan on dynamically adding custom labels to the GaugeMetric, which involves an extra step of calling .With(map[string]string{"label_name": "label_value"}), which then gives the caller access to a GaugeMetric to work with.

type ObserverMetric

type ObserverMetric interface {
	Observe(float64)
}

ObserverMetric represents a Histogram / Summary metric.

func Histogram

func Histogram(name string, help string) ObserverMetric

Histogram creates a histogram metric with default provider. Use this function, if the metric does not have any custom dynamic labels, which also gives the caller direct access to a ObserverMetric (histogram). This will use the default buckets for a histogram: []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}

func HistogramWithBuckets

func HistogramWithBuckets(name, help string, buckets []float64) ObserverMetric

HistogramWithBuckets creates a histogram metric with default provider. User this function if the metric does not have any custom dynamic labels, but you want to specify custom buckets other than the default.

func Summary

func Summary(name string, help string) ObserverMetric

Summary creates a summary metric with default provider. Use this function, if the metric does not have any custom dynamic labels, which also gives the caller direct access to a ObserverMetric (summary).

type ObserverVecMetric

type ObserverVecMetric interface {
	With(labels map[string]string) ObserverMetric
}

ObserverVecMetric represents a vector observer(histogram/summary) metric containing a variation of the same metric under different labels.

func HistogramVec

func HistogramVec(name string, help string, labels []string) ObserverVecMetric

HistogramVec creates a histogram vector metric with default provider. Use this function instead, if you plan on dynamically adding custom labels to the ObserverMetric (histogram), which involves an extra step of calling .With(map[string]string{"label_name": "label_value"}), which then gives the caller access to a ObserverMetric (histogram) to work with. This will use the default buckets for a histogram: []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}

func HistogramVecWithBuckets

func HistogramVecWithBuckets(name, help string, buckets []float64, labels []string) ObserverVecMetric

HistogramVecWithBuckets creates a histogram vector metric with default provider. Use this function to create a ObserverMetric (histogram) that with custom labels AND you want to specify custom buckets to overwrite the default. Similar to HistogramVec, you will need the extra step of calling the object with .With(map[string]string{"label_name": "label_value"})

func SummaryVec

func SummaryVec(name string, help string, labels []string) ObserverVecMetric

SummaryVec creates a summary vector metric with default provider. Use this function instead, if you plan on dynamically adding custom labels to the ObserverMetric (summary), which involves an extra step of calling .With(map[string]string{"label_name": "label_value"}), which then gives the caller access to a ObserverMetric (summary) to work with.

type Opts

type Opts struct {
	NamespacePath        string
	EnableRuntimeMetrics bool

	CustomHTTPMetrics *ObserverVecMetric
}

type PrometheusProvider

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

PrometheusProvider represents the implementation for Prometheus provider.

func NewPrometheusProvider

func NewPrometheusProvider(opts PrometheusProviderOpts) PrometheusProvider

NewPrometheusProvider creates a new Prometheus provider that implements Provider using Prometheus metrics.

func (PrometheusProvider) NewCounter

func (p PrometheusProvider) NewCounter(name, help string, labels ...string) CounterVecMetric

NewCounter creates a new Prometheus counter vector metric.

func (PrometheusProvider) NewGauge

func (p PrometheusProvider) NewGauge(name, help string, labels ...string) GaugeVecMetric

NewGauge creates a new Prometheus gauge vector metric.

func (PrometheusProvider) NewHistogram

func (p PrometheusProvider) NewHistogram(name, help string, buckets []float64, labels ...string) ObserverVecMetric

NewHistogram creates a new Prometheus histogram vector metric.

func (PrometheusProvider) NewSummary

func (p PrometheusProvider) NewSummary(name, help string, labels ...string) ObserverVecMetric

NewSummary creates a new Prometheus summary vector metric.

type PrometheusProviderOpts

type PrometheusProviderOpts struct {
	prometheus.Registerer
	prometheus.Gatherer
	DisableGoCollector      bool // default is false = go collector is enabled
	DisableProcessCollector bool // default is false = process collector is enabled
}

PrometheusProviderOpts represents the Prometheus metrics configuration options.

type Provider

type Provider interface {
	NewCounter(name, help string, labels ...string) CounterVecMetric
	NewGauge(name, help string, labels ...string) GaugeVecMetric
	NewHistogram(name, help string, buckets []float64, labels ...string) ObserverVecMetric
	NewSummary(name, help string, labels ...string) ObserverVecMetric
	// contains filtered or unexported methods
}

Provider represents a metric provider, i.e: Prometheus.

Jump to

Keyboard shortcuts

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