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, allowing the same metric to be broken down by different label dimensions.

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 differentiate the elements of the metric 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 differentiate the elements of the metric 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 configurable 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
) - > (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.
optionsSummaryOptionsCustom 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
) - > 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.
optionsSummaryOptionsCustom 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, allowing the same metric to be broken down by different label dimensions.

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 differentiate the elements of the metric 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 differentiate the elements of the metric 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, providing a histogram of observed values.

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, allowing the same metric to be broken down by different label dimensions.

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 differentiate the elements of the metric 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 differentiate the elements of the metric vector.

Returns

TypeDescription
*prometheus.HistogramVecA Prometheus HistogramVec metric.

NewHistogramVecWithOptions()

@classmethod
def NewHistogramVecWithOptions(
name: string,
description: string,
options: 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 for value distribution.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose.
optionsHistogramOptionsCustom options for the Histogram metric, such as bucket definitions.
labelNamesstringA list of label names that differentiate the elements of the metric 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,
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 for value distribution. 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.
optionsHistogramOptionsCustom options for the Histogram metric, such as bucket definitions.
labelNamesstringA list of label names that differentiate the elements of the metric 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 is a cumulative metric that represents a single monotonically increasing counter whose value can only increase or be reset to zero on restart.

Parameters

NameTypeDescription
namestringThe name of the metric, following Prometheus conventions (mostly [_a-z]).
descriptionstringA brief explanation of the metric's purpose. Note that 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. Note that 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, allowing the same metric to be broken down by different label dimensions.

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 differentiate the elements of the metric 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 differentiate the elements of the metric 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, with the metric name automatically suffixed to indicate the specified time scale.

Parameters

NameTypeDescription
namestringThe base name of the StopWatch metric.
descriptionstringA brief explanation of what the StopWatch is measuring.
scaletime.DurationThe time unit for the StopWatch (e.g., time.Millisecond). The metric name will be auto-suffixed based on this scale.

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 base name of the StopWatch metric.
descriptionstringA brief explanation of what the StopWatch is measuring.
scaletime.DurationThe time unit for the StopWatch (e.g., time.Millisecond). The metric name will be auto-suffixed based on this scale.

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, with the metric name automatically suffixed to indicate the specified time scale.

Parameters

NameTypeDescription
namestringThe base name of the StopWatchVec metric.
descriptionstringA brief explanation of what the StopWatchVec is measuring.
scaletime.DurationThe time unit for the StopWatchVec (e.g., time.Millisecond). The metric name will be auto-suffixed based on this scale.
labelNamesstringA list of label names that differentiate the elements of the metric 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 base name of the StopWatchVec metric.
descriptionstringA brief explanation of what the StopWatchVec is measuring.
scaletime.DurationThe time unit for the StopWatchVec (e.g., time.Millisecond). The metric name will be auto-suffixed based on this scale.
labelNamesstringA list of label names that differentiate the elements of the metric vector.

Returns

TypeDescription
*StopWatchVecA StopWatchVec object.

NewHistogramStopWatch()

@classmethod
def NewHistogramStopWatch(
name: string,
description: string
) - > (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. The scale is assumed to be seconds with buckets spanning 0.005s to 10s.

Parameters

NameTypeDescription
namestringThe base name of the HistogramStopWatch metric.
descriptionstringA brief explanation of what the HistogramStopWatch is measuring.

Returns

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

MustNewHistogramStopWatch()

@classmethod
def MustNewHistogramStopWatch(
name: string,
description: string
) - > HistogramStopWatch

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

Parameters

NameTypeDescription
namestringThe base name of the HistogramStopWatch metric.
descriptionstringA brief explanation of what the HistogramStopWatch is measuring.

Returns

TypeDescription
HistogramStopWatchA 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, allowing aggregation across instances with server-side quantile computation. The scale is assumed to be seconds with buckets spanning 0.005s to 10s.

Parameters

NameTypeDescription
namestringThe base name of the HistogramStopWatchVec metric.
descriptionstringA brief explanation of what the HistogramStopWatchVec is measuring.
labelNamesstringA list of label names that differentiate the elements of the metric 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 base name of the HistogramStopWatchVec metric.
descriptionstringA brief explanation of what the HistogramStopWatchVec is measuring.
labelNamesstringA list of label names that differentiate the elements of the metric 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 naming. 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 object representing the sub-scope.

CurrentScope()

@classmethod
def CurrentScope() - > string

Returns the name of the current scope. This can be used when manually constructing metric names.

Returns

TypeDescription
stringThe name of the current scope.

NewScopedMetricName()

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

Provides a metric name prefixed with the current scope. This is useful for directly creating custom metrics that adhere to the current scoping convention.

Parameters

NameTypeDescription
namestringThe base name of the metric.

Returns

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