nat.runtime.metrics#

Per-user workflow resource usage monitoring models and collector.

Attributes#

Classes#

PerUserSessionMetrics

Session lifecycle metrics for a per-user workflow.

PerUserRequestMetrics

Request-level metrics for a per-user workflow.

PerUserMemoryMetrics

Memory/resource count metrics for a per-user workflow.

PerUserResourceUsage

Combined resource usage metrics for a single per-user workflow.

PerUserMonitorResponse

Response model for the /monitor/users endpoint.

PerUserMetricsCollector

Collector for per-user workflow metrics.

Module Contents#

logger#
class PerUserSessionMetrics(/, **data: Any)#

Bases: pydantic.BaseModel

Session lifecycle metrics for a per-user workflow.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

created_at: datetime.datetime = None#
last_activity: datetime.datetime = None#
ref_count: int = None#
is_active: bool = None#
class PerUserRequestMetrics(/, **data: Any)#

Bases: pydantic.BaseModel

Request-level metrics for a per-user workflow.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

total_requests: int = None#
active_requests: int = None#
avg_latency_ms: float = None#
error_count: int = None#
class PerUserMemoryMetrics(/, **data: Any)#

Bases: pydantic.BaseModel

Memory/resource count metrics for a per-user workflow.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

per_user_functions_count: int = None#
per_user_function_groups_count: int = None#
exit_stack_size: int = None#
class PerUserResourceUsage(/, **data: Any)#

Bases: pydantic.BaseModel

Combined resource usage metrics for a single per-user workflow.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

user_id: str = None#
session: PerUserSessionMetrics = None#
requests: PerUserRequestMetrics = None#
memory: PerUserMemoryMetrics = None#
class PerUserMonitorResponse(/, **data: Any)#

Bases: pydantic.BaseModel

Response model for the /monitor/users endpoint.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

timestamp: datetime.datetime = None#
total_active_users: int = None#
users: list[PerUserResourceUsage] = None#
class PerUserMetricsCollector(
session_manager: nat.runtime.session.SessionManager,
)#

Collector for per-user workflow metrics.

This class aggregates metrics from SessionManager’s per-user builders and provides methods to collect metrics for individual users or all users.

Initialize the collector with a SessionManager reference.

Args:

session_manager: The SessionManager instance to collect metrics from

_session_manager#
async collect_user_metrics(user_id: str) PerUserResourceUsage | None#

Collect metrics for a specific user.

Args:

user_id: The user identifier to collect metrics for

Returns:

PerUserResourceUsage if user exists, None otherwise

async collect_all_metrics() PerUserMonitorResponse#

Collect metrics for all active per-user workflows.

Returns:

PerUserMonitorResponse with all user metrics

_build_user_metrics(
user_id: str,
builder_info,
) PerUserResourceUsage#

Build metrics for a single user from builder info.

Args:

user_id: The user identifier builder_info: The PerUserBuilderInfo instance

Returns:

PerUserResourceUsage with all metrics