pygx.instrument.monitoring¶
Pluggable metric systems for monitoring.
monitoring
¶
Pluggable metric systems for monitoring.
This module allows PyGX to plug in metric systems to monitor the execution of programs. There are three common kinds of metrics:
-
Counters track the number of times an event occurs. Their values increase monotonically over time.
-
Scalars track a single value at a given time, for example, available memory size. They do not accumulate over time like counters.
-
Distributions track the distribution of a numerical value. For example, the latency of an operation.
Metric
¶
Metric(
namespace: str,
name: str,
description: str,
parameter_definitions: dict[str, type[int | str | bool]],
**additional_flags: Any
)
Bases: Generic[MetricValueType]
Base class for metrics.
Initializes the metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
str
|
The namespace of the metric. |
required |
name
|
str
|
The name of the metric. |
required |
description
|
str
|
The description of the metric. |
required |
parameter_definitions
|
dict[str, type[int | str | bool]]
|
The definitions of the parameters for the metric. |
required |
**additional_flags
|
Any
|
Additional flags for the metric. |
{}
|
Source code in pygx/instrument/_monitoring.py
parameter_definitions
property
¶
Returns the parameter definitions of the metric.
value
abstractmethod
¶
Returns the value of the metric for the given parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**parameters
|
Any
|
Parameters for parameterized counters. |
{}
|
Returns:
| Type | Description |
|---|---|
MetricValueType
|
The value of the metric. |
Source code in pygx/instrument/_monitoring.py
Counter
¶
Counter(
namespace: str,
name: str,
description: str,
parameter_definitions: dict[str, type[int | str | bool]],
**additional_flags: Any
)
Bases: Metric[int]
Base class for counters.
Counters are metrics that track the number of times an event occurs. Their values increase monotonically over time.
Source code in pygx/instrument/_monitoring.py
increment
abstractmethod
¶
Increments the counter by delta and returns the new value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delta
|
int
|
The amount to increment the counter by. |
1
|
**parameters
|
Any
|
Parameters for parameterized counters. |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
The new value of the counter. |
Source code in pygx/instrument/_monitoring.py
Scalar
¶
Scalar(
namespace: str,
name: str,
description: str,
parameter_definitions: dict[str, type[int | str | bool]],
**additional_flags: Any
)
Bases: Metric[MetricValueType]
Base class for scalar values.
Scalar values are metrics that track a single value at a given time, for example, available memory size. They do not accumulate over time like counters.
Source code in pygx/instrument/_monitoring.py
set
abstractmethod
¶
Sets the value of the scalar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
MetricValueType
|
The value to record. |
required |
**parameters
|
Any
|
Parameters for parameterized scalars. |
{}
|
increment
abstractmethod
¶
Increments the scalar by delta and returns the new value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delta
|
MetricValueType
|
The amount to increment the scalar by. |
1
|
**parameters
|
Any
|
Parameters for parameterized scalars. |
{}
|
Returns:
| Type | Description |
|---|---|
MetricValueType
|
The new value of the scalar. |
Source code in pygx/instrument/_monitoring.py
DistributionValue
¶
Base for distribution value.
percentile
abstractmethod
¶
Returns the n-th percentile of the distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
float
|
The percentile to return. Should be in the range [0, 100]. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The n-th percentile of the distribution. |
Source code in pygx/instrument/_monitoring.py
fraction_less_than
abstractmethod
¶
Distribution
¶
Distribution(
namespace: str,
name: str,
description: str,
parameter_definitions: dict[str, type[int | str | bool]],
**additional_flags: Any
)
Bases: Metric[DistributionValue]
Base class for distributional metrics.
Distributions are metrics that track the distribution of a numerical value. For example, the latency of an operation.
Source code in pygx/instrument/_monitoring.py
record
abstractmethod
¶
Records a value to the distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The value to record. |
required |
**parameters
|
Any
|
Parameters for parameterized distributions. |
{}
|
record_duration
¶
record_duration(
*, scale: int = 1000, error_parameter: str = "error", **parameters: Any
) -> Iterator[None]
Context manager that records the duration of a code block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
int
|
Multiplier applied to the elapsed seconds before recording (e.g. the default 1000 records milliseconds). |
1000
|
error_parameter
|
str
|
The parameter name for recording the error. If the name is not defined as a parameter for the distribution, the error tag will not be recorded. |
'error'
|
**parameters
|
Any
|
Parameters for parameterized distributions. |
{}
|
Source code in pygx/instrument/_monitoring.py
MetricCollection
¶
MetricCollection(
namespace: str,
default_parameters: None | dict[str, type[int | str | bool]] = None,
)
Base class for metric collections.
A metric collection creates and caches metrics (counters, scalars and
distributions) under a shared namespace; get_* methods return the
existing metric when one with the same name was already created.
Initializes the metric collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
str
|
The namespace of the metric collection. |
required |
default_parameters
|
None | dict[str, type[int | str | bool]]
|
The default parameters used to create metrics if not specified. |
None
|
Source code in pygx/instrument/_monitoring.py
get_counter
¶
get_counter(
name: str,
description: str,
parameters: dict[str, type[int | str | bool]] | None = None,
**additional_flags: Any
) -> Counter
Gets or creates a counter with the given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the counter. |
required |
description
|
str
|
The description of the counter. |
required |
parameters
|
dict[str, type[int | str | bool]] | None
|
The definitions of the parameters for the counter.
|
None
|
**additional_flags
|
Any
|
Additional arguments for creating the counter. Subclasses can use these arguments to provide additional information for creating the counter. |
{}
|
Returns:
| Type | Description |
|---|---|
Counter
|
The counter with the given name. |
Source code in pygx/instrument/_monitoring.py
get_scalar
¶
get_scalar(
name: str,
description: str,
parameters: dict[str, type[int | str | bool]] | None = None,
value_type: type[int | float] = int,
**additional_flags: Any
) -> Scalar
Gets or creates a scalar with the given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the scalar. |
required |
description
|
str
|
The description of the scalar. |
required |
parameters
|
dict[str, type[int | str | bool]] | None
|
The definitions of the parameters for the scalar.
|
None
|
value_type
|
type[int | float]
|
The type of the value for the scalar. |
int
|
**additional_flags
|
Any
|
Additional arguments for creating the scalar. |
{}
|
Returns:
| Type | Description |
|---|---|
Scalar
|
The scalar with the given name. |
Source code in pygx/instrument/_monitoring.py
get_distribution
¶
get_distribution(
name: str,
description: str,
parameters: dict[str, type[int | str | bool]] | None = None,
**additional_flags: Any
) -> Distribution
Gets or creates a distribution with the given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the distribution. |
required |
description
|
str
|
The description of the distribution. |
required |
parameters
|
dict[str, type[int | str | bool]] | None
|
The definitions of the parameters for the distribution.
|
None
|
**additional_flags
|
Any
|
Additional arguments for creating the distribution. |
{}
|
Returns:
| Type | Description |
|---|---|
Distribution
|
The distribution with the given name. |
Source code in pygx/instrument/_monitoring.py
InMemoryMetricCollection
¶
InMemoryMetricCollection(
namespace: str,
default_parameters: None | dict[str, type[int | str | bool]] = None,
)
Bases: MetricCollection
In-memory metric collection.
Source code in pygx/instrument/_monitoring.py
metric_collection
¶
metric_collection(namespace: str, **kwargs) -> MetricCollection
Creates a metric collection using the default collection class.
set_default_metric_collection_cls
¶
set_default_metric_collection_cls(cls: type[MetricCollection]) -> None
Sets the default metric collection class.
default_metric_collection_cls
¶
default_metric_collection_cls() -> type[MetricCollection]
options: show_root_heading: false show_root_toc_entry: false members_order: source heading_level: 2