Skip to content

System monitor#

You can monitor the CPU, memory, disk, and network usage during the execution of experiments. The tracking is done transparently in a thread, adding the stats to the run field sysmon.

The monitor operates at the run level and also works in distributed environments.

Tip

The statistics are streamed if data streaming is enabled.

Example: Monitoring the system#

Monitoring the system

from mltraq import create_experiment, options
from mltraq.steps.sleep import sleep

# Activate the system monitor, specifying the frequency to sample the stats
with options().ctx({"sysmon.disable": False, "sysmon.interval": 0.1}):

    # Create a new experiment
    experiment = create_experiment()

    # Wait enough time to track a few timestamps, and report the first row
    print(
        experiment.execute(sleep(0.3))
        .runs.first()
        .fields.sysmon.df()
        .iloc[0]
    )
Output
idx                                       0
timestamp        2024-10-24 12:48:43.674660
cpu_cnt                                 8.0
cpu_pct                                13.0
disk_free_gb                         181.59
disk_total_gb                        494.38
disk_used_pct                         63.27
mem_free_gb                            7.73
mem_total_gb                          25.77
mem_used_pct                           70.0
net_recv_kbs                          10.24
net_sent_kbs                            0.0
Name: 0, dtype: object