namizun icon indicating copy to clipboard operation
namizun copied to clipboard

How to select the network interface?

Open Ali-Flt opened this issue 2 years ago • 1 comments

Namizun is showing my network usage inaccurately because I believe it is showing the usage of all network interfaces whereas a lot of it is related to the virtual network interfaces such as the ones created by docker.

Can you add a feature to select which interface I want to monitor the network usage of?

Ali-Flt avatar Aug 12 '23 16:08 Ali-Flt

I did this for a workaround. My network interface name is eno4. So I changed the network.py file to this:

from psutil import net_io_counters
from namizun_core import database

def _net_io_counters():
    return net_io_counters(pernic=True)['eno4']


def get_size(only_bytes):
    flag = ''
    if only_bytes < 0:
        flag = '-'
        only_bytes *= -1
    for unit in ['', 'K', 'M', 'G', 'T', 'P']:
        if only_bytes < 1024:
            return f"{flag}{only_bytes:.2f}{unit}B"
        only_bytes /= 1024


def get_network_io():
    io = _net_io_counters()
    return io.bytes_sent + database.get_parameter('upload_amount_synchronizer') \
        , io.bytes_recv + database.get_parameter('download_amount_synchronizer')


def get_system_network_io():
    io = _net_io_counters()
    return io.bytes_sent, io.bytes_recv


def get_system_upload():
    return _net_io_counters().bytes_sent


def get_system_download():
    return _net_io_counters().bytes_recv

Note that you may need to flush the redis DB afterwards.

Ali-Flt avatar Aug 12 '23 17:08 Ali-Flt