babylon.metrics.collector
Metrics collection system for Babylon/Babylon.
The MetricsCollector observes the simulation without interfering. It is the Party’s Central Statistical Bureau - recording material conditions for analysis by the planning committee.
Classes
|
A single metric measurement. |
Centralized metrics collection and aggregation. |
|
|
Context manager for timing code blocks. |
- class babylon.metrics.collector.MetricEvent(**data)[source]
Bases:
BaseModelA single metric measurement.
Immutable record of a moment in the simulation’s history.
- Parameters:
- model_config: ClassVar[ConfigDict] = {'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str
- value: float
- timestamp: datetime
- tags: dict[str, str]
- metadata: dict[str, Any]
- class babylon.metrics.collector.MetricsCollector[source]
Bases:
objectCentralized metrics collection and aggregation.
This class implements the Singleton pattern to ensure a single source of truth for all metrics across the simulation.
The collector is thread-safe for concurrent metric recording.
Metrics Categories: - performance: Timing, throughput, latency - simulation: Game state metrics (P(S|A), P(S|R), Rent flow) - cache: Hit rates, evictions, memory usage - embedding: Generation times, batch sizes, errors
- Return type:
- time(name)[source]
Context manager for timing operations.
- Parameters:
name (
str) – Timer name- Return type:
- Returns:
TimerContext that records duration on exit
Example
- with collector.time(“embedding.generation”):
embeddings = generate_embeddings(texts)
- record_metric(name, value, context='', object_id=None, context_level=None)[source]
Record a named metric with context.
- get_metrics(name, limit=100)[source]
Get recent metric events.
- Parameters:
- Return type:
- Returns:
List of recent MetricEvent objects
- class babylon.metrics.collector.TimerContext(collector, name)[source]
Bases:
objectContext manager for timing code blocks.
- Parameters:
collector (MetricsCollector)
name (str)
- __init__(collector, name)[source]
- Parameters:
collector (MetricsCollector)
name (str)
- Return type:
None