> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ns.rocks/llms.txt
> Use this file to discover all available pages before exploring further.

# Lifecycle And Monitor

> Python SDK object reference for lifecycle events, webhooks, and live monitor streams.

Use `Lifecycle` for durable event history and webhooks. Use `Monitor` for live
runtime observations while a client is connected.

## Lifecycle

| Method group                                               | Use                                  |
| ---------------------------------------------------------- | ------------------------------------ |
| `Lifecycle.list_events(...)`                               | List account-level lifecycle events. |
| `Lifecycle.list_machine_events(machine_id, ...)`           | List events for one machine.         |
| `Lifecycle.list_snapshot_events(snapshot_id, ...)`         | List events for one snapshot.        |
| `Lifecycle.stream(...)`                                    | Stream lifecycle transitions.        |
| `Lifecycle.create_webhook(...)`                            | Register a webhook endpoint.         |
| `Lifecycle.list_webhooks`, `get_webhook`, `delete_webhook` | Manage webhook registrations.        |
| `Lifecycle.list_webhook_deliveries(...)`                   | Inspect delivery attempts.           |

## Monitor

| Method                   | Use                                                                                 |
| ------------------------ | ----------------------------------------------------------------------------------- |
| `Monitor.subscribe(...)` | Subscribe to machine info, metrics, process, update, snapshot, and error callbacks. |
| `subscription.stop()`    | Stop a live subscription.                                                           |

```python theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
from nullspace import Monitor

def on_metrics(metrics):
    print(metrics.cpu_percent, metrics.memory_bytes)

subscription = Monitor(machine.id).subscribe(on_metrics=on_metrics)
try:
    machine.commands.run("sleep 5", shell=True)
finally:
    subscription.stop()
```

## Related

* [Lifecycle events](../../observability/lifecycle-events)
* [Webhooks](../../observability/webhooks)
* [Monitor stream](../../observability/monitor)
