Documentation ¶
Overview ¶
Package promreg provides a front to Prometheus metric registry to help with creation of metrics in components as well as querying.
Index ¶
- func LaunchMetricListener(address string, gatherer prometheus.Gatherer, enablePprof bool) *http.Server
- type CompositeMetricQuerier
- type MetricCreator
- type MetricFactory
- func (creator *MetricFactory) AddOrGetCounter(name string, help string, labelNames []string, labelValues []string) promext.RWCounter
- func (creator *MetricFactory) AddOrGetCounterVec(name string, help string, labelNames []string, leftmostLabelValues []string) *promext.RWCounterVec
- func (creator *MetricFactory) AddOrGetGauge(name string, help string, labelNames []string, labelValues []string) promext.RWGauge
- func (creator *MetricFactory) AddOrGetGaugeVec(name string, help string, labelNames []string, leftmostLabelValues []string) *promext.RWGaugeVec
- func (creator *MetricFactory) AddOrGetLazyCounter(name string, help string, labelNames []string, labelValues []string) promext.LazyRWCounter
- func (creator *MetricFactory) AddOrGetLazyCounterVec(name string, help string, labelNames []string, leftmostLabelValues []string) *promext.LazyRWCounterVec
- func (creator *MetricFactory) AddOrGetPrefix(prefix string, labelNames []string, labelValues []string) MetricCreator
- func (factory *MetricFactory) Collect(output chan<- prometheus.Metric)
- func (factory *MetricFactory) Describe(output chan<- *prometheus.Desc)
- func (factory *MetricFactory) Gather() ([]*dto.MetricFamily, error)
- func (factory *MetricFactory) LookupMetricFamily(name string) prometheus.Collector
- func (creator *MetricFactory) String() string
- type MetricQuerier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LaunchMetricListener ¶
func LaunchMetricListener(address string, gatherer prometheus.Gatherer, enablePprof bool) *http.Server
LaunchMetricListener starts a HTTP server for Prometheus metrics and optionally /debug/pprof
If the address contains unspecified port (":0"), a random port is assigned and set to server.Addr
Types ¶
type CompositeMetricQuerier ¶
type CompositeMetricQuerier []MetricQuerier
CompositeMetricQuerier combines multiple MetricQuerier(s)
func (CompositeMetricQuerier) Collect ¶
func (c CompositeMetricQuerier) Collect(output chan<- prometheus.Metric)
Collect implements prometheus.Collector's Collect function, storing metrics in the output channel
func (CompositeMetricQuerier) Describe ¶
func (c CompositeMetricQuerier) Describe(output chan<- *prometheus.Desc)
Describe implements prometheus.Collector's Describe function, storing metric descriptions in the output channel
func (CompositeMetricQuerier) LookupMetricFamily ¶
func (c CompositeMetricQuerier) LookupMetricFamily(name string) prometheus.Collector
LookupMetricFamily implements MetricQuerier's LookupMetricFamily function, finding a metric family (vector) by name
type MetricCreator ¶
type MetricCreator interface { // AddOrGetPrefix creates a sub-creator which inherits the parent's prefix and fixed labels, // with more prefix and fixed labels added to all metrics created from this new sub-factory AddOrGetPrefix(prefix string, labelNames []string, labelValues []string) MetricCreator // AddOrGetCounter adds or gets a counter AddOrGetCounter(name string, help string, labelNames []string, labelValues []string) promext.RWCounter // AddOrGetCounterVec adds or gets a counter-vec with leftmost label values AddOrGetCounterVec(name string, help string, labelNames []string, leftmostLabelValues []string) *promext.RWCounterVec // AddOrGetGauge adds or gets a gauge // // Gauges must be updated by Add/Sub not Set, because there could be multiple updaters AddOrGetGauge(name string, help string, labelNames []string, labelValues []string) promext.RWGauge // AddOrGetGaugeVec adds or gets a gauge-vec with leftmost label values // // Gauges must be updated by Add/Sub not Set, because there could be multiple updaters AddOrGetGaugeVec(name string, help string, labelNames []string, leftmostLabelValues []string) *promext.RWGaugeVec // AddOrGetLazyCounter adds or gets a lazy counter // // Lazy counters are not listed in output if the value is zero AddOrGetLazyCounter(name string, help string, labelNames []string, labelValues []string) promext.LazyRWCounter // AddOrGetLazyCounterVec adds or gets a lazy counter-vec with leftmost label values // // Lazy counters are not listed in output if the value is zero AddOrGetLazyCounterVec(name string, help string, labelNames []string, leftmostLabelValues []string) *promext.LazyRWCounterVec fmt.Stringer }
MetricCreator is a front to facilitate creation of Prometheus metrics
Each MetricCreator carries a predefined prefix, labels and label values that are added to every metrics created from it.
A MetricCreator can create child creators with additional prefix, labels and label values. The parent's prefix, labels or label values can never be removed or overridden.
The MetricCreator doesn't provide any lookup functionality even though it's certainly doable, because metric families created from a sub-creator could contain labels and values from siblings, e.g.:
- sub-creator TCP: metric connection_total[prot=tcp]
- sub-creator UDP: metric connection_total[prot=udp]
The AddOrGet* in both sub-facrories and any lookup function if implemented would report the same metric family "connection_total", which contains both metrics regardless from which sub-creator the call is made. This would cause duplications and inconsistency in resulting data if they're combined.
type MetricFactory ¶
type MetricFactory struct {
// contains filtered or unexported fields
}
MetricFactory is the root implementation of MetricCreator, a front to facilitate creation of Prometheus metrics
MetricFactory is also a promethues.Collector and a prometheus.Gatherer itself ¶
Different MetricFactory(s) MUST NOT contain the same metric families.
func NewMetricFactory ¶
func NewMetricFactory(prefix string, labelNames []string, labelValues []string) *MetricFactory
NewMetricFactory creates a factory with prefix for metrics names and fixed labels for all metrics created from this new factory
func (*MetricFactory) AddOrGetCounter ¶
func (creator *MetricFactory) AddOrGetCounter(name string, help string, labelNames []string, labelValues []string) promext.RWCounter
AddOrGetCounter adds or gets a counter
func (*MetricFactory) AddOrGetCounterVec ¶
func (creator *MetricFactory) AddOrGetCounterVec(name string, help string, labelNames []string, leftmostLabelValues []string) *promext.RWCounterVec
AddOrGetCounterVec adds or gets a counter-vec with leftmost label values
func (*MetricFactory) AddOrGetGauge ¶
func (creator *MetricFactory) AddOrGetGauge(name string, help string, labelNames []string, labelValues []string) promext.RWGauge
AddOrGetGauge adds or gets a gauge
Gauges must be updated by Add/Sub not Set, because there could be multiple updaters
func (*MetricFactory) AddOrGetGaugeVec ¶
func (creator *MetricFactory) AddOrGetGaugeVec(name string, help string, labelNames []string, leftmostLabelValues []string) *promext.RWGaugeVec
AddOrGetGaugeVec adds or gets a gauge-vec with leftmost label values
Gauges must be updated by Add/Sub not Set, because there could be multiple updaters
func (*MetricFactory) AddOrGetLazyCounter ¶
func (creator *MetricFactory) AddOrGetLazyCounter(name string, help string, labelNames []string, labelValues []string) promext.LazyRWCounter
AddOrGetCounter adds or gets a counter
func (*MetricFactory) AddOrGetLazyCounterVec ¶
func (creator *MetricFactory) AddOrGetLazyCounterVec(name string, help string, labelNames []string, leftmostLabelValues []string) *promext.LazyRWCounterVec
AddOrGetCounterVec adds or gets a counter-vec with leftmost label values
func (*MetricFactory) AddOrGetPrefix ¶
func (creator *MetricFactory) AddOrGetPrefix(prefix string, labelNames []string, labelValues []string) MetricCreator
AddOrGetPrefix creates a sub-creator which inherits the parent's prefix and fixed labels, with more prefix and fixed labels added to all metrics created from this new sub-creator
func (*MetricFactory) Collect ¶
func (factory *MetricFactory) Collect(output chan<- prometheus.Metric)
Collect implements prometheus.Collector's Collect function, storing metrics in the output channel
func (*MetricFactory) Describe ¶
func (factory *MetricFactory) Describe(output chan<- *prometheus.Desc)
Describe implements prometheus.Collector's Describe function, storing metric descriptions in the output channel
func (*MetricFactory) Gather ¶
func (factory *MetricFactory) Gather() ([]*dto.MetricFamily, error)
Gather implements prometheus.Gatherer's Gather function, collecting all metric families
func (*MetricFactory) LookupMetricFamily ¶
func (factory *MetricFactory) LookupMetricFamily(name string) prometheus.Collector
LookupMetricFamily implements MetricQuerier's LookupMetricFamily function, finding a metric family (vector) by its name without this factory's prefix
type MetricQuerier ¶
type MetricQuerier interface { prometheus.Collector // LookupMetricFamily looks up a metric family (vector) by its name // // The name is not a full name but a local name without prefix of this querier itself LookupMetricFamily(name string) prometheus.Collector }
MetricQuerier is prometheus metric Collector plus lookup functions