babylon.metrics
Metrics collection and analysis for Babylon/Babylon.
Metrics are the nervous system of the simulation. They provide feedback on the health of all subsystems.
- class babylon.metrics.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:
- clear()[source]
Clear all collected metrics.
Used primarily for testing or resetting between game sessions.
- Return type:
- get_metrics(name, limit=100)[source]
Get recent metric events.
- Parameters:
- Return type:
- Returns:
List of recent MetricEvent objects
- record_metric(name, value, context='', object_id=None, context_level=None)[source]
Record a named metric with context.
- class babylon.metrics.MetricsCollectorProtocol(*args, **kwargs)[source]
Bases:
ProtocolProtocol defining the contract for metrics collectors.
This protocol ensures both the real MetricsCollector and any test doubles (spies, mocks) implement the same interface.
The protocol follows the “Dumb Spy” pattern for test doubles: implementations should record what was called, not calculate statistics. Statistical analysis belongs in the production MetricsCollector only.
Example
def process_data(collector: MetricsCollectorProtocol) -> None: collector.increment("items_processed") with collector.time("processing_duration"): # ... do work ... pass
- __init__(*args, **kwargs)
- clear()[source]
Clear all recorded metrics.
Used primarily for testing or resetting between game sessions.
- Return type:
- gauge(name, value)[source]
Set a gauge value.
Gauges represent point-in-time values that can go up or down.
Modules
Metrics collection system for Babylon/Babylon. |
|
Metrics collector interfaces and protocols. |
|
SQLAlchemy models for metrics persistence. |