Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrAlreadySet = fmt.Errorf("cannot set metric keys more than once") ErrEmpty = fmt.Errorf("cannot set metric keys to an empty set") ErrNeverSet = fmt.Errorf("must call SetMetricKeys prior to using labeled package") )
var EmitUnlabeledMetric = EmitUnlabeledMetricOption{}
Functions ¶
func GetUnlabeledMetricName ¶
func SetMetricKeys ¶
func SetMetricKeys(keys ...contextutils.Key)
Sets keys to use with labeled metrics. The values of these keys will be pulled from context at runtime.
func UnsetMetricKeys ¶
func UnsetMetricKeys()
Warning: This function is not thread safe and should be used for testing only outside of this package.
Types ¶
type AdditionalLabelsOption ¶
type AdditionalLabelsOption struct { // A collection of labels to look for in the passed context. Labels []string }
AdditionalLabelsOption instructs the labeled metric to expect additional labels scoped for this just this metric in the context passed.
type Counter ¶
type Counter struct { *prometheus.CounterVec prometheus.Counter // contains filtered or unexported fields }
Counter represents a counter labeled with values from the context. See labeled.SetMetricsKeys for information about to configure that.
func NewCounter ¶
func NewCounter(name, description string, scope promutils.Scope, opts ...MetricOption) Counter
NewCounter creates a new labeled counter. Label keys must be set before instantiating a counter. See labeled.SetMetricsKeys for information about to configure that.
type EmitUnlabeledMetricOption ¶
type EmitUnlabeledMetricOption struct { }
Instructs the metric to emit unlabeled metric (besides the labeled one). This is useful to get overall system performance.
type Gauge ¶
type Gauge struct { *prometheus.GaugeVec prometheus.Gauge // contains filtered or unexported fields }
Gauge represents a gauge labeled with values from the context. See labeled.SetMetricsKeys for more information
func NewGauge ¶
func NewGauge(name, description string, scope promutils.Scope, opts ...MetricOption) Gauge
NewGauge creates a new labeled gauge. Label keys must be set before instantiating. If the unlabeled option is given, this object will also instantiate and emit another gauge with the given name with an _unlabeled suffix. See labeled.SetMetricsKeys for information about how to configure that.
func (Gauge) Add ¶
Add adds the given value to the Gauge. (The value can be negative, resulting in a decrease of the Gauge.) The data point will be labeled with values from context. See labeled.SetMetricsKeys for information about how to configure that.
func (Gauge) Dec ¶
Dec decrements the level by 1. Use Sub to decrement by arbitrary values. The data point will be labeled with values from context. See labeled.SetMetricsKeys for information about how to configure that.
func (Gauge) Inc ¶
Inc increments the gauge by 1. Use Add to increment by arbitrary values. The data point will be labeled with values from context. See labeled.SetMetricsKeys for information about how to configure that.
func (Gauge) Set ¶
Set sets the Gauge to an arbitrary value. The data point will be labeled with values from context. See labeled.SetMetricsKeys for information about how to configure that.
func (Gauge) SetToCurrentTime ¶
SetToCurrentTime sets the Gauge to the current Unix time in seconds.
type MetricOption ¶
type MetricOption interface {
// contains filtered or unexported methods
}
Defines extra set of options to customize the emitted metric.
type StopWatch ¶
type StopWatch struct { *promutils.StopWatchVec // We use SummaryVec for emitting StopWatchVec, this computes percentiles per metric tags combination on the client- // side. This makes it impossible to aggregate percentiles across tags (e.g. to have system-wide view). When enabled // through a flag in the constructor, we initialize this additional untagged stopwatch to compute percentiles // across tags. promutils.StopWatch // contains filtered or unexported fields }
func NewStopWatch ¶
func NewStopWatch(name, description string, scale time.Duration, scope promutils.Scope, opts ...MetricOption) StopWatch
NewStopWatch creates a new labeled stopwatch. Label keys must be set before instantiating a counter. See labeled.SetMetricsKeys for information about how to configure that.
func (StopWatch) Observe ¶
Observe observes specified duration between the start and end time. The data point will be labeled with values from context. See labeled.SetMetricsKeys for information about how to configure that.
func (StopWatch) Start ¶
Start creates a new Instance of the StopWatch called a Timer that is closeable/stoppable.
Example ¶
ctx := context.Background() stopWatch := NewStopWatch("test", "this is an example stopwatch", time.Millisecond, promutils.NewTestScope()) { timer := stopWatch.Start(ctx) defer timer.Stop() // An operation you want to measure the time for. time.Sleep(time.Second) }
Output:
type Summary ¶
type Summary struct { *prometheus.SummaryVec prometheus.Summary // contains filtered or unexported fields }
Summary represents a summary labeled with values from the context. See labeled.SetMetricsKeys for information about how to configure that.
func NewSummary ¶
func NewSummary(name, description string, scope promutils.Scope, opts ...MetricOption) Summary
NewSummary creates a new labeled summary. Label keys must be set before instantiating. If the unlabeled option is given, this object will also instantiate and emit another summary with the given name with an _unlabeled suffix. See labeled.SetMetricsKeys for information about how to configure that.