Skip to content

Metrics¤

Define and track training metrics.

See Also¤


datarax.monitoring.metrics ¤

Metrics collection and tracking utilities for Datarax.

This module provides classes for collecting, tracking, and aggregating metrics during pipeline operation. These utilities enable monitoring of pipeline performance, throughput, and resource usage.

logger module-attribute ¤

logger = getLogger(__name__)

MetricRecord dataclass ¤

MetricRecord(name: str, value: float, timestamp: float, component: str, metadata: dict[str, Any] | None = None)

A single metric measurement.

Attributes:

Name Type Description
name str

Name of the metric.

value float

Measured value.

timestamp float

Time when the metric was recorded.

component str

Component that generated the metric.

metadata dict[str, Any] | None

Optional additional metadata about the metric.

name instance-attribute ¤

name: str

value instance-attribute ¤

value: float

timestamp instance-attribute ¤

timestamp: float

component instance-attribute ¤

component: str

metadata class-attribute instance-attribute ¤

metadata: dict[str, Any] | None = None

MetricsCollector ¤

MetricsCollector(enabled: bool = True)

Collects and aggregates metrics during pipeline operations.

This class provides methods for tracking time-based metrics and recording arbitrary metrics during pipeline execution.

Attributes:

Name Type Description
enabled

Whether metrics collection is enabled.

Parameters:

Name Type Description Default
enabled bool

Whether metrics collection is enabled.

True

enabled instance-attribute ¤

enabled = enabled

start_timer ¤

start_timer(name: str, component: str = 'pipeline') -> None

Start timing an operation.

Parameters:

Name Type Description Default
name str

Name of the timer.

required
component str

Component being timed.

'pipeline'

stop_timer ¤

stop_timer(name: str, component: str = 'pipeline', metadata: dict[str, Any] | None = None) -> None

Stop timing and record elapsed time.

Parameters:

Name Type Description Default
name str

Name of the timer.

required
component str

Component being timed.

'pipeline'
metadata dict[str, Any] | None

Optional additional metadata about the timing.

None

record_metric ¤

record_metric(name: str, value: float, component: str = 'pipeline', metadata: dict[str, Any] | None = None) -> None

Record a metric value.

Parameters:

Name Type Description Default
name str

Name of the metric.

required
value float

Value to record.

required
component str

Component generating the metric.

'pipeline'
metadata dict[str, Any] | None

Optional additional metadata about the metric.

None

get_metrics ¤

get_metrics() -> list[MetricRecord]

Get all collected metrics.

Returns:

Type Description
list[MetricRecord]

List of collected metric records.

clear ¤

clear() -> None

Clear all metrics and timers.

AggregatedMetrics ¤

AggregatedMetrics()

Aggregates metrics over time.

This class provides methods for calculating aggregate statistics over collected metrics.

add_metrics ¤

add_metrics(metrics: list[MetricRecord]) -> None

Add metrics to the aggregator.

Parameters:

Name Type Description Default
metrics list[MetricRecord]

List of metric records to add.

required

get_average ¤

get_average(name: str, component: str = 'pipeline') -> float | None

Get the average value of a metric.

Parameters:

Name Type Description Default
name str

Name of the metric.

required
component str

Component that generated the metric.

'pipeline'

Returns:

Type Description
float | None

Average value, or None if no metrics were collected.

get_min ¤

get_min(name: str, component: str = 'pipeline') -> float | None

Get the minimum value of a metric.

Parameters:

Name Type Description Default
name str

Name of the metric.

required
component str

Component that generated the metric.

'pipeline'

Returns:

Type Description
float | None

Minimum value, or None if no metrics were collected.

get_max ¤

get_max(name: str, component: str = 'pipeline') -> float | None

Get the maximum value of a metric.

Parameters:

Name Type Description Default
name str

Name of the metric.

required
component str

Component that generated the metric.

'pipeline'

Returns:

Type Description
float | None

Maximum value, or None if no metrics were collected.

get_sum ¤

get_sum(name: str, component: str = 'pipeline') -> float | None

Get the sum of values for a metric.

Parameters:

Name Type Description Default
name str

Name of the metric.

required
component str

Component that generated the metric.

'pipeline'

Returns:

Type Description
float | None

Sum of values, or None if no metrics were collected.

get_count ¤

get_count(name: str, component: str = 'pipeline') -> int

Get the number of measurements for a metric.

Parameters:

Name Type Description Default
name str

Name of the metric.

required
component str

Component that generated the metric.

'pipeline'

Returns:

Type Description
int

Number of measurements.

get_rate ¤

get_rate(name: str, component: str = 'pipeline') -> float | None

Get the rate of a metric (count / time period).

Parameters:

Name Type Description Default
name str

Name of the metric.

required
component str

Component that generated the metric.

'pipeline'

Returns:

Type Description
float | None

Rate (occurrences per second), or None if less than two measurements

float | None

exist.

clear ¤

clear() -> None

Clear all aggregated metrics.