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-08-29 09:25:00.247118
cpu_cnt                                 8.0
cpu_pct                                16.0
disk_free_gb                         185.49
disk_total_gb                        494.38
disk_used_pct                         62.48
mem_free_gb                           10.33
mem_total_gb                          25.77
mem_used_pct                           59.9
net_recv_kbs                            0.0
net_sent_kbs                            0.0
Name: 0, dtype: object