labeled

package
v1.0.25 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0 Imports: 9 Imported by: 24

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var EmitUnlabeledMetric = EmitUnlabeledMetricOption{}

Functions

func GetUnlabeledMetricName

func GetUnlabeledMetricName(metricName string) string

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 added in v0.2.11

func UnsetMetricKeys()

Warning: This function is not thread safe and should be used for testing only outside of this package.

Types

type AdditionalLabelsOption added in v0.3.12

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.

func (Counter) Add

func (c Counter) Add(ctx context.Context, v float64)

Add adds the given value to the counter. It panics if the value is < 0.. The data point will be labeled with values from context. See labeled.SetMetricsKeys for information about how to configure that.

func (Counter) Inc

func (c Counter) Inc(ctx context.Context)

Inc increments the counter by 1. Use Add to increment it by arbitrary non-negative values. The data point will be labeled with values from context. See labeled.SetMetricsKeys for information about how 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 added in v0.3.12

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 added in v0.3.12

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 added in v0.3.12

func (g Gauge) Add(ctx context.Context, v float64)

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 added in v0.3.12

func (g Gauge) Dec(ctx context.Context)

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 added in v0.3.12

func (g Gauge) Inc(ctx context.Context)

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 added in v0.3.12

func (g Gauge) Set(ctx context.Context, v float64)

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 added in v0.3.12

func (g Gauge) SetToCurrentTime(ctx context.Context)

SetToCurrentTime sets the Gauge to the current Unix time in seconds.

func (Gauge) Sub added in v0.3.12

func (g Gauge) Sub(ctx context.Context, v float64)

Sub adds the given value to the Gauge. The value can be negative, resulting in an increase of the Gauge. The data point will be labeled with values from context. See labeled.SetMetricsKeys for information about how to configure that.

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

func (c StopWatch) Observe(ctx context.Context, start, end time.Time)

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

func (c StopWatch) Start(ctx context.Context) Timer

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:

func (StopWatch) Time

func (c StopWatch) Time(ctx context.Context, f func())

Time observes the elapsed duration since the creation of the timer. The timer is created using a StopWatch. The data point will be labeled with values from context. See labeled.SetMetricsKeys for information about to configure that.

type Summary added in v0.4.10

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 added in v0.4.10

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.

func (Summary) Observe added in v0.4.10

func (s Summary) Observe(ctx context.Context, v float64)

Observe adds a single observation to the summary.

type Timer

type Timer interface {
	// Stops the timer and reports observation.
	Stop() float64
}

Defines a common interface for timers.

Jump to

Keyboard shortcuts

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