Skip to content

Handle network speed in a more sophisticated manner #2

@ymode

Description

@ymode

Currently network speed is calculated in the following function, however there should be more sophisticated logic to handle the change to mb (and potentially GB) for example if the kb total is > 1024 it changes to returning MB etc....

Current Function:

def get_network_info():
    global last_bytes_sent, last_bytes_recv
    net_io = psutil.net_io_counters()
    
    # Calculate the difference in bytes sent/received since the last check
    bytes_sent_diff = net_io.bytes_sent - last_bytes_sent
    bytes_recv_diff = net_io.bytes_recv - last_bytes_recv
    
    # Update the last network IO counters
    last_bytes_sent = net_io.bytes_sent
    last_bytes_recv = net_io.bytes_recv
    
    # Convert to kilobytes for readability
    kb_sent_diff = bytes_sent_diff / 1024
    kb_recv_diff = bytes_recv_diff / 1024
    
    return ('Kbps', f"|↑{kb_sent_diff:.2f} KB|↓{kb_recv_diff:.2f} KB")

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions