sandbox/utils.py
def usage_io_network() -> Tuple[dict, dict]:
    """Return current partitions I/O and network usage.
    
    Returned value is a tuple containing :
    
    - A dictionary corresponding to the io with the following keys : read_iops, read_bps, write_iops
    and write_bps. Each value are a dictionary mapping partitions to the corresponding statistics.
    
    - A dictionary corresponding to the io with the following keys : received_packets,
    received_bytes, sent_packets, and sent_bytes."""
    sleep_time = 2
    
    disks = {d[0].split('/')[-1]: d[0] for d in psutil.disk_partitions()}
    raw_io1 = {disks[k]: v for k, v in psutil.disk_io_counters(True).items() if k in disks}
    raw_network1 = psutil.net_io_counters()
    time.sleep(sleep_time)
    raw_io2 = {disks[k]: v for k, v in psutil.disk_io_counters(True).items() if k in disks}
    raw_network2 = psutil.net_io_counters()
    
    network_usage = {
        "sent_bytes":       (raw_network2[0] - raw_network1[0]) // sleep_time,
        "received_bytes":   (raw_network2[1] - raw_network1[1]) // sleep_time,
        "sent_packets":     (raw_network2[2] - raw_network1[2]) // sleep_time,
        "received_packets": (raw_network2[3] - raw_network1[3]) // sleep_time,
    }
    io_usage = {
        "read_iops":  dict(),
        "read_bps":   dict(),
        "write_iops": dict(),
        "write_bps":  dict(),
    }
    for p in raw_io1.keys():
        io_usage["read_iops"][p] = (raw_io2[p][0] - raw_io1[p][0]) // sleep_time
        io_usage["write_iops"][p] = (raw_io2[p][1] - raw_io1[p][1]) // sleep_time
        io_usage["read_bps"][p] = (raw_io2[p][2] - raw_io1[p][2]) // sleep_time
        io_usage["write_bps"][p] = (raw_io2[p][3] - raw_io1[p][3]) // sleep_time
    
    return io_usage, network_usage
Return current partitions I/O and network usage.
    
    Returned value is a tuple containing :
    
    - A dictionary corresponding to the io with the following keys : read_iops, read_bps, write_iops
    and write_bps. Each value are a dictionary mapping partitions to the corresponding statistics.
    
    - A dictionary corresponding to the io with the following keys : received_packets,
    received_bytes, sent_packets, and sent_bytes.
Return current partitions I/O and network usage.
Returned value is a tuple containing .

A dictionary corresponding to the io with the following keys : read_iops, read_bps, write_iops
and write_bps. Each value are a dictionary mapping partitions to the corresponding statistics.

A dictionary corresponding to the io with the following keys : received_packets,
received_bytes, sent_packets, and sent_bytes.
Return current partitions I / O and network usage . Returned value is a tuple containing . A dictionary corresponding to the io with the following keys : read_iops read_bps write_iops and write_bps . Each value are a dictionary mapping partitions to the corresponding statistics . A dictionary corresponding to the io with the following keys : received_packets received_bytes sent_packets and sent_bytes .
def usage_io_network() -> Tuple[dict, dict]:
    sleep_time = 2
    disks = {d[0].split('/')[-1]: d[0] for d in psutil.disk_partitions()}
    raw_io1 = {disks[k]: v for k, v in psutil.disk_io_counters(True).items() if k in disks}
    raw_network1 = psutil.net_io_counters()
    time.sleep(sleep_time)
    raw_io2 = {disks[k]: v for k, v in psutil.disk_io_counters(True).items() if k in disks}
    raw_network2 = psutil.net_io_counters()
    network_usage = {
        "sent_bytes":       (raw_network2[0] - raw_network1[0]) // sleep_time,
        "received_bytes":   (raw_network2[1] - raw_network1[1]) // sleep_time,
        "sent_packets":     (raw_network2[2] - raw_network1[2]) // sleep_time,
        "received_packets": (raw_network2[3] - raw_network1[3]) // sleep_time,
    }
    io_usage = {
        "read_iops":  dict(),
        "read_bps":   dict(),
        "write_iops": dict(),
        "write_bps":  dict(),
    }
    for p in raw_io1.keys():
        io_usage["read_iops"][p] = (raw_io2[p][0] - raw_io1[p][0]) // sleep_time
        io_usage["write_iops"][p] = (raw_io2[p][1] - raw_io1[p][1]) // sleep_time
        io_usage["read_bps"][p] = (raw_io2[p][2] - raw_io1[p][2]) // sleep_time
        io_usage["write_bps"][p] = (raw_io2[p][3] - raw_io1[p][3]) // sleep_time
    return io_usage, network_usage
def usage_io_network ( ) -> Tuple [ dict , dict ] : sleep_time = 2 disks = { d [ 0 ] . split ( '/' ) [ - 1 ] : d [ 0 ] for d in psutil . disk_partitions ( ) } raw_io1 = { disks [ k ] : v for k , v in psutil . disk_io_counters ( True ) . items ( ) if k in disks } raw_network1 = psutil . net_io_counters ( ) time . sleep ( sleep_time ) raw_io2 = { disks [ k ] : v for k , v in psutil . disk_io_counters ( True ) . items ( ) if k in disks } raw_network2 = psutil . net_io_counters ( ) network_usage = { "sent_bytes" : ( raw_network2 [ 0 ] - raw_network1 [ 0 ] ) // sleep_time , "received_bytes" : ( raw_network2 [ 1 ] - raw_network1 [ 1 ] ) // sleep_time , "sent_packets" : ( raw_network2 [ 2 ] - raw_network1 [ 2 ] ) // sleep_time , "received_packets" : ( raw_network2 [ 3 ] - raw_network1 [ 3 ] ) // sleep_time , } io_usage = { "read_iops" : dict ( ) , "read_bps" : dict ( ) , "write_iops" : dict ( ) , "write_bps" : dict ( ) , } for p in raw_io1 . keys ( ) : io_usage [ "read_iops" ] [ p ] = ( raw_io2 [ p ] [ 0 ] - raw_io1 [ p ] [ 0 ] ) // sleep_time io_usage [ "write_iops" ] [ p ] = ( raw_io2 [ p ] [ 1 ] - raw_io1 [ p ] [ 1 ] ) // sleep_time io_usage [ "read_bps" ] [ p ] = ( raw_io2 [ p ] [ 2 ] - raw_io1 [ p ] [ 2 ] ) // sleep_time io_usage [ "write_bps" ] [ p ] = ( raw_io2 [ p ] [ 3 ] - raw_io1 [ p ] [ 3 ] ) // sleep_time return io_usage , network_usage
Return current partitions I/O and network usage.
Return current partitions I / O and network usage .
"""Return current partitions I/O and network usage.
    
    Returned value is a tuple containing :
    
    - A dictionary corresponding to the io with the following keys : read_iops, read_bps, write_iops
    and write_bps. Each value are a dictionary mapping partitions to the corresponding statistics.
    
    - A dictionary corresponding to the io with the following keys : received_packets,
    received_bytes, sent_packets, and sent_bytes."""