Skip to main content

Subscribe

from nullspace import Monitor

monitor = Monitor()
subscription = monitor.subscribe(
    interval_ms=1_000,
    include_processes=True,
    on_metrics=lambda event: print(event.metrics),
    on_processes=lambda event: print(event.processes),
    on_error=lambda event: print(event.message),
)

# Keep your application alive while the background reader receives events.
subscription.stop()
The monitor WebSocket accepts a monitor_subscribe message with an optional interval_ms and include_processes flag. Server-side intervals are clamped to the supported range: 500 ms to 10,000 ms.

Metrics endpoint

metrics = sandbox.get_metrics()
for sample in metrics:
    print(sample)

Event classes

Monitor streams can emit snapshot, update, metrics, processes, and error events. Use callback parameters for only the event types your application needs.
CallbackMessage type
on_snapshotInitial snapshot of observed sandbox state.
on_updateState update after the snapshot.
on_metricsCPU, memory, and runtime metrics.
on_processesProcess list updates when include_processes=True.
on_errorSubscription or stream errors.