Documentation ¶
Index ¶
- Variables
- func FieldValueToString(vI interface{}) string
- type Count
- type CounterVec
- type Fields
- type Gauge
- type GaugeVec
- type IntGauge
- type Metrics
- func (m *Metrics) Count(key string) types.Count
- func (m *Metrics) CountFields(key string, addFields field.AbstractFields) types.Count
- func (*Metrics) Flush()
- func (m *Metrics) ForEachCount(callback func(types.Count) bool) bool
- func (m *Metrics) ForEachGauge(callback func(types.Gauge) bool) bool
- func (m *Metrics) ForEachIntGauge(callback func(types.IntGauge) bool) bool
- func (m *Metrics) Gatherer() prometheus.Gatherer
- func (m *Metrics) Gauge(key string) types.Gauge
- func (m *Metrics) GaugeFields(key string, addFields field.AbstractFields) types.Gauge
- func (m *Metrics) IntGauge(key string) types.IntGauge
- func (m *Metrics) IntGaugeFields(key string, addFields field.AbstractFields) types.IntGauge
- func (m *Metrics) List() []prometheus.Collector
- func (m *Metrics) Registerer() prometheus.Registerer
- func (m *Metrics) WithContextFields(allFields *field.FieldsChain, newFieldsCount int) belt.Tool
- func (m *Metrics) WithTraceIDs(traceIDs belt.TraceIDs, newTraceIDsCount int) belt.Tool
- type Option
- type OptionDisableLabels
Constants ¶
This section is empty.
Variables ¶
var Default = func() metrics.Metrics { registry, ok := prometheus.DefaultRegisterer.(*prometheus.Registry) if !ok { alternativeDefaultRegistryOnce.Do(func() { alternativeDefaultRegistry = prometheus.NewRegistry() }) registry = alternativeDefaultRegistry } return New(registry) }
Default returns metrics.Metrics with the default configuration.
Functions ¶
func FieldValueToString ¶
func FieldValueToString(vI interface{}) string
FieldValueToString converts any value to a string, which could be used as label value in prometheus.
Types ¶
type Count ¶
type Count struct { sync.Mutex *Metrics Key string *CounterVec io_prometheus_client.Metric prometheus.Counter }
Count is an implementation of metrics.Count.
func (*Count) WithResetFields ¶
func (metric *Count) WithResetFields(fields field.AbstractFields) types.Count
WithResetFields implements metrics.Count
type CounterVec ¶
type CounterVec struct { *prometheus.CounterVec Key string PossibleLabels []string }
CounterVec is a family of Count metrics.
func (*CounterVec) AddPossibleLabels ¶
func (v *CounterVec) AddPossibleLabels(newLabels []string)
AddPossibleLabels adds prometheus labels to the list of expected labels of a Metric of this family.
func (*CounterVec) GetMetricWith ¶
func (v *CounterVec) GetMetricWith(labels prometheus.Labels) (prometheus.Counter, error)
GetMetricWith returns a Metric with the values of labels as provided.
type Gauge ¶
type Gauge struct { sync.Mutex *Metrics Key string *GaugeVec io_prometheus_client.Metric prometheus.Gauge }
Gauge is an implementation of metrics.Gauge.
func (*Gauge) WithResetFields ¶
func (metric *Gauge) WithResetFields(fields field.AbstractFields) types.Gauge
WithResetFields implements metrics.Gauge.
type GaugeVec ¶
type GaugeVec struct { *prometheus.GaugeVec Key string PossibleLabels []string }
GaugeVec is a family of Gauge metrics.
func (*GaugeVec) AddPossibleLabels ¶
AddPossibleLabels adds prometheus labels to the list of expected labels of a Metric of this family.
func (*GaugeVec) GetMetricWith ¶
func (v *GaugeVec) GetMetricWith(labels prometheus.Labels) (prometheus.Gauge, error)
GetMetricWith returns a Metric with the values of labels as provided.
type IntGauge ¶
type IntGauge struct { sync.Mutex *Metrics Key string *GaugeVec io_prometheus_client.Metric prometheus.Gauge }
IntGauge is an implementation of metrics.IntGauge.
func (*IntGauge) WithResetFields ¶
func (metric *IntGauge) WithResetFields(fields field.AbstractFields) types.IntGauge
WithResetFields implements metrics.IntGauge
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics implements a wrapper of prometheus metrics to implement metrics.Metrics.
Pretty slow and naive implementation. Could be improved by on-need basis. If you need a faster implementation, then try `tsmetrics`.
Warning! This implementation does not remove automatically metrics, thus if a metric was created once, it will be kept in memory forever. If you need a version of metrics which automatically removes metrics non-used for a long time, then try `tsmetrics`.
Warning! Prometheus does not support changing amount of labels for a metric, therefore we delete and create a metric from scratch if it is required to extend the set of labels. This procedure leads to a reset of the metric value. If you need a version of metrics which does not have such flaw, then try `tsmetrics` or `simplemetrics`.
func New ¶
func New(registry *prometheus.Registry, opts ...Option) *Metrics
New returns a new instance of Metrics
func (*Metrics) CountFields ¶
CountFields returns Count metric given key and additional field values (on top of already defined).
func (*Metrics) Flush ¶
func (*Metrics) Flush()
Flush implements metrics.Metrics (or more specifically belt.Tool).
func (*Metrics) ForEachCount ¶
ForEachCount iterates over each Count metric. Stops on first `false` returned by the callback.
func (*Metrics) ForEachGauge ¶
ForEachGauge iterates over each Gauge metric. Stops on first `false` returned by the callback.
func (*Metrics) ForEachIntGauge ¶
ForEachIntGauge iterates over each IntGauge metric. Stops on first `false` returned by the callback.
func (*Metrics) Gatherer ¶
func (m *Metrics) Gatherer() prometheus.Gatherer
Gatherer returns prometheus.Gatherer of this Metrics.
func (*Metrics) GaugeFields ¶
GaugeFields returns Gauge metric given key and additional field values (on top of already defined).
func (*Metrics) IntGauge ¶
IntGauge implements context.Metrics (see the description in the interface).
func (*Metrics) IntGaugeFields ¶
IntGaugeFields returns IntGauge metric given key and additional field values (on top of already defined).
func (*Metrics) List ¶
func (m *Metrics) List() []prometheus.Collector
List returns all the metrics. It could be used for a custom exporter.
func (*Metrics) Registerer ¶
func (m *Metrics) Registerer() prometheus.Registerer
Registerer returns prometheus.Registerer of this Metrics.
func (*Metrics) WithContextFields ¶
func (m *Metrics) WithContextFields(allFields *field.FieldsChain, newFieldsCount int) belt.Tool
WithContextFields implements metrics.Metrics.
func (*Metrics) WithTraceIDs ¶
WithTraceIDs implements metrics.Metrics.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is an optional argument to function New, that changes the behavior of the metrics handler.
type OptionDisableLabels ¶
type OptionDisableLabels bool
OptionDisableLabels disables the labels (tags) and makes all the metrics flat. Attempts to get a metrics with the same key but different tags will result into getting the same metric. And all the metrics will be registered without labels.