Skip to main content

Scope

A Scope represents a prefix in Prometheus. It is nestable, thus every metric that is published does not need to provide a prefix, but just the name of the metric. As long as the Scope is used to create a new instance of the metric The prefix (or scope) is automatically set.

Methods


NewGauge()

@classmethod
def NewGauge(
name: string,
description: string
) - > (prometheus.Gauge, error)

Creates a new prometheus.Gauge metric with the current scope as its prefix. This metric represents a single numerical value that can arbitrarily go up and down.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.

Returns

TypeDescription
(prometheus.Gauge, error)A Prometheus Gauge metric and an error if creation fails.

MustNewGauge()

@classmethod
def MustNewGauge(
name: string,
description: string
) - > prometheus.Gauge

Creates a new prometheus.Gauge metric with the current scope as its prefix. This method panics if the metric cannot be created.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.

Returns

TypeDescription
prometheus.GaugeA Prometheus Gauge metric.

NewGaugeVec()

@classmethod
def NewGaugeVec(
name: string,
description: string,
labelNames: string
) - > (*prometheus.GaugeVec, error)

Creates a new prometheus.GaugeVec metric with the current scope as its prefix. This metric is a vector of Gauges, each with a distinct set of label values.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.
labelNamesstringA list of label names that will distinguish the elements of the vector.

Returns

TypeDescription
(*prometheus.GaugeVec, error)A Prometheus GaugeVec metric and an error if creation fails.

MustNewGaugeVec()

@classmethod
def MustNewGaugeVec(
name: string,
description: string,
labelNames: string
) - > *prometheus.GaugeVec

Creates a new prometheus.GaugeVec metric with the current scope as its prefix. This method panics if the metric cannot be created.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.
labelNamesstringA list of label names that will distinguish the elements of the vector.

Returns

TypeDescription
*prometheus.GaugeVecA Prometheus GaugeVec metric.

NewSummary()

@classmethod
def NewSummary(
name: string,
description: string
) - > (prometheus.Summary, error)

Creates a new prometheus.Summary metric with the current scope as its prefix. This metric samples observations and calculates quantiles over a sliding time window.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.

Returns

TypeDescription
(prometheus.Summary, error)A Prometheus Summary metric and an error if creation fails.

MustNewSummary()

@classmethod
def MustNewSummary(
name: string,
description: string
) - > prometheus.Summary

Creates a new prometheus.Summary metric with the current scope as its prefix. This method panics if the metric cannot be created.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.

Returns

TypeDescription
prometheus.SummaryA Prometheus Summary metric.

NewSummaryWithOptions()

@classmethod
def NewSummaryWithOptions(
name: string,
description: string,
options: [SummaryOptions](summaryoptions.md?sid=flytestdlib_promutils_summaryoptions)
) - > (prometheus.Summary, error)

Creates a new prometheus.Summary metric with custom options, such as a custom set of objectives (i.e., target quantiles).

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.
options[SummaryOptions](summaryoptions.md?sid=flytestdlib_promutils_summaryoptions)Custom options for the Summary metric, such as objectives for quantile calculation.

Returns

TypeDescription
(prometheus.Summary, error)A Prometheus Summary metric and an error if creation fails.

MustNewSummaryWithOptions()

@classmethod
def MustNewSummaryWithOptions(
name: string,
description: string,
options: [SummaryOptions](summaryoptions.md?sid=flytestdlib_promutils_summaryoptions)
) - > prometheus.Summary

Creates a new prometheus.Summary metric with custom options, such as a custom set of objectives (i.e., target quantiles). This method panics if the metric cannot be created.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.
options[SummaryOptions](summaryoptions.md?sid=flytestdlib_promutils_summaryoptions)Custom options for the Summary metric, such as objectives for quantile calculation.

Returns

TypeDescription
prometheus.SummaryA Prometheus Summary metric.

NewSummaryVec()

@classmethod
def NewSummaryVec(
name: string,
description: string,
labelNames: string
) - > (*prometheus.SummaryVec, error)

Creates a new prometheus.SummaryVec metric with the current scope as its prefix. This metric is a vector of Summaries, each with a distinct set of label values.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.
labelNamesstringA list of label names that will distinguish the elements of the vector.

Returns

TypeDescription
(*prometheus.SummaryVec, error)A Prometheus SummaryVec metric and an error if creation fails.

MustNewSummaryVec()

@classmethod
def MustNewSummaryVec(
name: string,
description: string,
labelNames: string
) - > *prometheus.SummaryVec

Creates a new prometheus.SummaryVec metric with the current scope as its prefix. This method panics if the metric cannot be created.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.
labelNamesstringA list of label names that will distinguish the elements of the vector.

Returns

TypeDescription
*prometheus.SummaryVecA Prometheus SummaryVec metric.

NewHistogram()

@classmethod
def NewHistogram(
name: string,
description: string
) - > (prometheus.Histogram, error)

Creates a new prometheus.Histogram metric with the current scope as its prefix. This metric samples observations and counts them into configurable buckets.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.

Returns

TypeDescription
(prometheus.Histogram, error)A Prometheus Histogram metric and an error if creation fails.

MustNewHistogram()

@classmethod
def MustNewHistogram(
name: string,
description: string
) - > prometheus.Histogram

Creates a new prometheus.Histogram metric with the current scope as its prefix. This method panics if the metric cannot be created.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.

Returns

TypeDescription
prometheus.HistogramA Prometheus Histogram metric.

NewHistogramVec()

@classmethod
def NewHistogramVec(
name: string,
description: string,
labelNames: string
) - > (*prometheus.HistogramVec, error)

Creates a new prometheus.HistogramVec metric with the current scope as its prefix. This metric is a vector of Histograms, each with a distinct set of label values.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.
labelNamesstringA list of label names that will distinguish the elements of the vector.

Returns

TypeDescription
(*prometheus.HistogramVec, error)A Prometheus HistogramVec metric and an error if creation fails.

MustNewHistogramVec()

@classmethod
def MustNewHistogramVec(
name: string,
description: string,
labelNames: string
) - > *prometheus.HistogramVec

Creates a new prometheus.HistogramVec metric with the current scope as its prefix. This method panics if the metric cannot be created.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.
labelNamesstringA list of label names that will distinguish the elements of the vector.

Returns

TypeDescription
*prometheus.HistogramVecA Prometheus HistogramVec metric.

NewHistogramVecWithOptions()

@classmethod
def NewHistogramVecWithOptions(
name: string,
description: string,
options: [HistogramOptions](histogramoptions.md?sid=flytestdlib_promutils_histogramoptions),
labelNames: string
) - > (*prometheus.HistogramVec, error)

Creates a new prometheus.HistogramVec metric with the current scope as its prefix and a custom set of options, such as specific buckets.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.
options[HistogramOptions](histogramoptions.md?sid=flytestdlib_promutils_histogramoptions)Custom options for the Histogram metric, such as bucket definitions.
labelNamesstringA list of label names that will distinguish the elements of the vector.

Returns

TypeDescription
(*prometheus.HistogramVec, error)A Prometheus HistogramVec metric and an error if creation fails.

MustNewHistogramVecWithOptions()

@classmethod
def MustNewHistogramVecWithOptions(
name: string,
description: string,
options: [HistogramOptions](histogramoptions.md?sid=flytestdlib_promutils_histogramoptions),
labelNames: string
) - > *prometheus.HistogramVec

Creates a new prometheus.HistogramVec metric with the current scope as its prefix and a custom set of options, such as specific buckets. This method panics if the metric cannot be created.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.
options[HistogramOptions](histogramoptions.md?sid=flytestdlib_promutils_histogramoptions)Custom options for the Histogram metric, such as bucket definitions.
labelNamesstringA list of label names that will distinguish the elements of the vector.

Returns

TypeDescription
*prometheus.HistogramVecA Prometheus HistogramVec metric.

NewCounter()

@classmethod
def NewCounter(
name: string,
description: string
) - > (prometheus.Counter, error)

Creates a new prometheus.Counter metric with the current scope as its prefix. This metric represents a single numerical value that only ever goes up.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose. Counters are ever-increasing and cumulative; use Summary/Histogram for bucketed observations.

Returns

TypeDescription
(prometheus.Counter, error)A Prometheus Counter metric and an error if creation fails.

MustNewCounter()

@classmethod
def MustNewCounter(
name: string,
description: string
) - > prometheus.Counter

Creates a new prometheus.Counter metric with the current scope as its prefix. This method panics if the metric cannot be created.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose. Counters are ever-increasing and cumulative; use Summary/Histogram for bucketed observations.

Returns

TypeDescription
prometheus.CounterA Prometheus Counter metric.

NewCounterVec()

@classmethod
def NewCounterVec(
name: string,
description: string,
labelNames: string
) - > (*prometheus.CounterVec, error)

Creates a new prometheus.CounterVec metric with the current scope as its prefix. This metric is a vector of Counters, each with a distinct set of label values.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.
labelNamesstringA list of label names that will distinguish the elements of the vector.

Returns

TypeDescription
(*prometheus.CounterVec, error)A Prometheus CounterVec metric and an error if creation fails.

MustNewCounterVec()

@classmethod
def MustNewCounterVec(
name: string,
description: string,
labelNames: string
) - > *prometheus.CounterVec

Creates a new prometheus.CounterVec metric with the current scope as its prefix. This method panics if the metric cannot be created.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.
labelNamesstringA list of label names that will distinguish the elements of the vector.

Returns

TypeDescription
*prometheus.CounterVecA Prometheus CounterVec metric.

NewStopWatch()

@classmethod
def NewStopWatch(
name: string,
description: string,
scale: time.Duration
) - > ([StopWatch](labeled/stopwatch.md?sid=flytestdlib_promutils_labeled_stopwatch), error)

Creates a new StopWatch object within the current scope. This custom wrapper provides timing functionality.

Parameters

NameTypeDescription
namestringThe name of the StopWatch metric. The metric name will be auto-suffixed with the appropriate scale.
descriptionstringA brief explanation of the StopWatch's purpose.
scaletime.DurationThe scale of the timer (e.g., time.Millisecond for milliseconds). Refer to https://golang.org/pkg/time/#Duration for more information.

Returns

TypeDescription
([StopWatch](labeled/stopwatch.md?sid=flytestdlib_promutils_labeled_stopwatch), error)A StopWatch object and an error if creation fails.

MustNewStopWatch()

@classmethod
def MustNewStopWatch(
name: string,
description: string,
scale: time.Duration
) - > [StopWatch](labeled/stopwatch.md?sid=flytestdlib_promutils_labeled_stopwatch)

Creates a new StopWatch object within the current scope. This method panics if the StopWatch cannot be created.

Parameters

NameTypeDescription
namestringThe name of the StopWatch metric. The metric name will be auto-suffixed with the appropriate scale.
descriptionstringA brief explanation of the StopWatch's purpose.
scaletime.DurationThe scale of the timer (e.g., time.Millisecond for milliseconds). Refer to https://golang.org/pkg/time/#Duration for more information.

Returns

TypeDescription
[StopWatch](labeled/stopwatch.md?sid=flytestdlib_promutils_labeled_stopwatch)A StopWatch object.

NewStopWatchVec()

@classmethod
def NewStopWatchVec(
name: string,
description: string,
scale: time.Duration,
labelNames: string
) - > (*StopWatchVec, error)

Creates a new StopWatchVec object within the current scope. This custom wrapper provides timing functionality for a vector of StopWatches.

Parameters

NameTypeDescription
namestringThe name of the StopWatchVec metric. The metric name will be auto-suffixed with the appropriate scale.
descriptionstringA brief explanation of the StopWatchVec's purpose.
scaletime.DurationThe scale of the timer (e.g., time.Millisecond for milliseconds). Refer to https://golang.org/pkg/time/#Duration for more information.
labelNamesstringA list of label names that will distinguish the elements of the vector.

Returns

TypeDescription
(*StopWatchVec, error)A StopWatchVec object and an error if creation fails.

MustNewStopWatchVec()

@classmethod
def MustNewStopWatchVec(
name: string,
description: string,
scale: time.Duration,
labelNames: string
) - > *StopWatchVec

Creates a new StopWatchVec object within the current scope. This method panics if the StopWatchVec cannot be created.

Parameters

NameTypeDescription
namestringThe name of the StopWatchVec metric. The metric name will be auto-suffixed with the appropriate scale.
descriptionstringA brief explanation of the StopWatchVec's purpose.
scaletime.DurationThe scale of the timer (e.g., time.Millisecond for milliseconds). Refer to https://golang.org/pkg/time/#Duration for more information.
labelNamesstringA list of label names that will distinguish the elements of the vector.

Returns

TypeDescription
*StopWatchVecA StopWatchVec object.

NewHistogramStopWatch()

@classmethod
def NewHistogramStopWatch(
name: string,
description: string
) - > ([HistogramStopWatch](labeled/histogramstopwatch.md?sid=flytestdlib_promutils_labeled_histogramstopwatch), error)

Creates a new HistogramStopWatch object within the current scope. This custom wrapper provides timing functionality that can be aggregated across instances, with quantiles computed server-side.

Parameters

NameTypeDescription
namestringThe name of the HistogramStopWatch metric.
descriptionstringA brief explanation of the HistogramStopWatch's purpose. Scale is assumed to be seconds with buckets spanning 0.005s to 10s.

Returns

TypeDescription
([HistogramStopWatch](labeled/histogramstopwatch.md?sid=flytestdlib_promutils_labeled_histogramstopwatch), error)A HistogramStopWatch object and an error if creation fails.

MustNewHistogramStopWatch()

@classmethod
def MustNewHistogramStopWatch(
name: string,
description: string
) - > [HistogramStopWatch](labeled/histogramstopwatch.md?sid=flytestdlib_promutils_labeled_histogramstopwatch)

Creates a new HistogramStopWatch object within the current scope. This method panics if the HistogramStopWatch cannot be created.

Parameters

NameTypeDescription
namestringThe name of the HistogramStopWatch metric.
descriptionstringA brief explanation of the HistogramStopWatch's purpose. Scale is assumed to be seconds with buckets spanning 0.005s to 10s.

Returns

TypeDescription
[HistogramStopWatch](labeled/histogramstopwatch.md?sid=flytestdlib_promutils_labeled_histogramstopwatch)A HistogramStopWatch object.

NewHistogramStopWatchVec()

@classmethod
def NewHistogramStopWatchVec(
name: string,
description: string,
labelNames: string
) - > (*HistogramStopWatchVec, error)

Creates a new HistogramStopWatchVec object within the current scope. This custom wrapper provides timing functionality for a vector of HistogramStopWatches that can be aggregated across instances, with quantiles computed server-side.

Parameters

NameTypeDescription
namestringThe name of the HistogramStopWatchVec metric.
descriptionstringA brief explanation of the HistogramStopWatchVec's purpose. Scale is assumed to be seconds with buckets spanning 0.005s to 10s.
labelNamesstringA list of label names that will distinguish the elements of the vector.

Returns

TypeDescription
(*HistogramStopWatchVec, error)A HistogramStopWatchVec object and an error if creation fails.

MustNewHistogramStopWatchVec()

@classmethod
def MustNewHistogramStopWatchVec(
name: string,
description: string,
labelNames: string
) - > *HistogramStopWatchVec

Creates a new HistogramStopWatchVec object within the current scope. This method panics if the HistogramStopWatchVec cannot be created.

Parameters

NameTypeDescription
namestringThe name of the HistogramStopWatchVec metric.
descriptionstringA brief explanation of the HistogramStopWatchVec's purpose. Scale is assumed to be seconds with buckets spanning 0.005s to 10s.
labelNamesstringA list of label names that will distinguish the elements of the vector.

Returns

TypeDescription
*HistogramStopWatchVecA HistogramStopWatchVec object.

NewSubScope()

@classmethod
def NewSubScope(
name: string
) - > [Scope](scope.md?sid=flytestdlib_promutils_scope)

Creates a new sub-scope, allowing for nested metric prefixes. This is useful for organizing metrics hierarchically.

Parameters

NameTypeDescription
namestringThe name of the sub-scope to create.

Returns

TypeDescription
[Scope](scope.md?sid=flytestdlib_promutils_scope)A new Scope instance representing the sub-scope.

CurrentScope()

@classmethod
def CurrentScope() - > string

Retrieves the name of the current scope. This can be used when manually creating metrics to ensure they adhere to the current prefix.

Returns

TypeDescription
stringThe name of the current scope.

NewScopedMetricName()

@classmethod
def NewScopedMetricName(
name: string
) - > string

Generates a metric name prefixed with the current scope. This is useful for directly creating metrics while maintaining the scope's naming convention.

Parameters

NameTypeDescription
namestringThe base name of the metric.

Returns

TypeDescription
stringA string representing the metric name with the current scope prefix.