Documentation ¶
Overview ¶
Package metricslite implements a lightweight, testable metrics interface focused on Prometheus metrics.
Index ¶
- type Counter
- type Gauge
- type Interface
- type Memory
- func (m *Memory) ConstCounter(name, help string, labelNames ...string)
- func (m *Memory) ConstGauge(name, help string, labelNames ...string)
- func (m *Memory) Counter(name, help string, labelNames ...string) Counter
- func (m *Memory) Gauge(name, help string, labelNames ...string) Gauge
- func (m *Memory) OnConstScrape(scrape ScrapeFunc)
- func (m *Memory) Series() map[string]Series
- type ScrapeError
- type ScrapeFunc
- type Series
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Counter ¶
A Counter is a function which increments a metric's value by value when invoked. Value must be zero or positive or the Counter will panic. Labels enable optional partitioning of a Counter into multiple dimensions.
Counters must be safe for concurrent use. The number of label values passed when the Counter is invoked must match the number of label names defined when the Counter was created, or the Counter will panic.
type Gauge ¶
A Gauge is a function which sets a metric's value when invoked. Labels enable optional partitioning of a Gauge into multiple dimensions.
Gauges must be safe for concurrent use. The number of label values passed when the Gauge is invoked must match the number of label names defined when the Gauge was created, or the Gauge will panic.
type Interface ¶
type Interface interface { // Const metrics are used primarily when implementing Prometheus exporters // or copying metrics from an external monitoring system. Most applications // should use the non-const Counter, Gauge, etc. instead. // // OnConstScrape invokes the input ScrapeFunc on-demand when the metrics are // gathered. OnConstScrape must be called with a ScrapeFunc if const metrics // are in use, or the Interface will panic. ConstCounter(name, help string, labelNames ...string) ConstGauge(name, help string, labelNames ...string) OnConstScrape(scrape ScrapeFunc) // Non-const (or direct instrumentation) metrics are used to instrument // normal Go applications. Their values are only updated when requested // by the caller: not on-demand when metrics are gathered. Counter(name, help string, labelNames ...string) Counter Gauge(name, help string, labelNames ...string) Gauge }
An Interface is a type which can produce metrics functions. An Interface implementation must be safe for concurrent use.
If any Interface methods are used to create a metric with the same name as a previously created metric, those methods should panic. Callers are expected to create non-const metrics once and pass them through their program as needed.
func Discard ¶
func Discard() Interface
Discard creates an Interface which creates no-op metrics that discard their data.
func NewPrometheus ¶
func NewPrometheus(reg *prometheus.Registry) Interface
NewPrometheus creates an Interface which will register all of its metrics to the specified Prometheus registry. The registry must not be nil.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory implements Interface by storing timeseries and samples in memory. This type is primarily useful for tests.
func (*Memory) ConstCounter ¶
ConstCounter implements Interface.
func (*Memory) ConstGauge ¶
ConstGauge implements Interface.
func (*Memory) OnConstScrape ¶
func (m *Memory) OnConstScrape(scrape ScrapeFunc)
OnConstScrape implements Interface.
type ScrapeError ¶
A ScrapeError allows a ScrapeFunc to report a specific metric as the cause of a failed metrics scrape.
type ScrapeFunc ¶
A ScrapeFunc is a function which is invoked on demand to collect metric labels and values for each const metric present in the map key for metrics. The user should invoke the collect function for any values they wish to export as metrics. If an error of type *ScrapeError is returned, the error will be reported to the metrics system.
A ScrapeFunc must be safe for concurrent use. The number of label values passed when collect is invoked must match the number of label names defined when the const metric was created, or collect will panic.