pydistsim.metrics.MetricCollector
- class MetricCollector[source]
Bases:
NodeNetworkObserver,AlgorithmObserver,SimulationObserverMetricCollector is an observer that collects metrics from the simulation.
### Custom metrics Extend this class and implement the desired event methods to collect custom metrics. For registering events, call the _add_metric method. Add an instance of your custom collector to the simulation observers for it to work.
Even so, you can use the events attribute to register the events you want to listen to. This includes new custom events that you would trigger from an algorithm.
Example of implementing a custom metric collector:
class ExampleCustomMetricCollector(MetricCollector): events = ["example_custom_event"] class CustomMetricEventType(StrEnum): "Definition if this enum is optional. It helps to avoid typos in the event names." EXAMPLE_CUSTOM_EVENT_ZERO = "EXAMPLE_CUSTOM_EVENT_ZERO" ... def on_example_custom_event(self, a, b, c): self._add_metric( self.CustomMetricEventType.EXAMPLE_CUSTOM_EVENT_ZERO, {"a": a, "b": b, "c": c} )
Methods
__init__Returns a dictionary with the collected metrics.
notifyon_addedCalled when the observer is added to an observable object.
on_algorithm_finishedon_algorithm_startedon_message_deliveredon_message_senton_network_changedon_node_status_changedon_sim_state_changedon_state_changedon_step_doneAttributes
events