# eXtremeDB Performance Monitor Python API

> The Performance Monitor Python API is implemented in the `exdb.Perfmon` class.

> To enable performance monitoring in Python, first initialize the eXtremeDB runtime with `UsePerfmon=True`:

>         exdb.init_runtime(disk=is_disk, tmgr=options.tmgr, shm=is_shm, debug=is_debug, UsePerfmon=True)

> Next, initialize the monitor by specifying the size of the in-memory database used to store metrics:

>         exdb.Perfmon.init(perfmon_db_size)

> Then open the eXtremeDB database you wish to monitor and attach it to the performance monitor:

>         exdb.Perfmon.attach(db_name)

> Perform the database operations for which you want to collect performance metrics. When monitoring is complete, detach the database and shut down the monitor:

>         exdb.Perfmon.detach()
>         exdb.Perfmon.close()

> At any time after initializing the monitor, you can configure its behavior using the following options:

> `enabled`
> Enables or disables performance monitoring. `0` = disabled, `1` = enabled (default: `1`).
> `monitor_interval_ms`
> Sampling interval for metric collection, in milliseconds (default: `1000` ms = 1 second).
> `store_interval_sec`
> Retention period for metrics in the perfmon database, in seconds (default: `3600` s). Older records are automatically purged to conserve space.

> To retrieve the current configuration, call `exdb.Perfmon.get_options()`, which returns an options structure. To update a setting, use `exdb.Perfmon.set_options(option_name, value)`.

> After attaching a database, you can obtain the name of the currently monitored database at any time by calling `exdb.Perfmon.getDbName()`.