nicolargo / glances

Glances an Eye on your system. A top/htop alternative for GNU/Linux, BSD, Mac OS and Windows operating systems.
http://nicolargo.github.io/glances/
Other
26.44k stars 1.5k forks source link

API: Network module is disabled but appears in endpoint "all" (Glances v4 regression) #2815

Closed wittypluck closed 3 months ago

wittypluck commented 3 months ago

Describe the bug In Glances v4, when the plugin network is Disabled in the configuration file, the endpoint all still sends an incomplete network section. This section should be empty. The returned information does not have the time_since_update field which breaks Home Assistant Glances integration: https://github.com/home-assistant/core/issues/118632#issuecomment-2145529233

To Reproduce Steps to reproduce the behavior:

  1. Start Glances with the following options [network] disable=True

  2. Call the all endpoint: curl http://localhost:61208/api/4/all

  3. See error:

    { .... , 
    "network":[{"bytes_sent":1327476,"bytes_recv":1327476,"speed":0,"key":"interface_name","interface_name":"lo","alias":null,"bytes_all":2654952},{"bytes_sent":29392344,"bytes_recv":455897677,"speed":1048576000,"key":"interface_name","interface_name":"eth0","alias":null,"bytes_all":485290021},{"bytes_sent":0,"bytes_recv":0,"speed":0,"key":"interface_name","interface_name":"wlan0","alias":null,"bytes_all":0},{"bytes_sent":2212666,"bytes_recv":9623150,"speed":10485760000,"key":"interface_name","interface_name":"docker0","alias":null,"bytes_all":11835816},{"bytes_sent":2604532,"bytes_recv":9794412,"speed":10485760000,"key":"interface_name","interface_name":"vetha148260","alias":null,"bytes_all":12398944}], 
    ....}

Expected behavior

The network section should be empty (similar to other modules and Glances v3):

{ .... , 
"network":{},
....}

Screenshots If applicable, add screenshots to help explain your problem.

Environement (please complete the following information)

Additional context Add any other context about the problem here.

$ curl http://localhost:61208/api/4/network
{"detail":"Unknown plugin network (available plugins: ['uptime', 'memswap', 'system', 'processcount', 'psutilversion', 'help', 'quicklook', 'sensors', 'mem', 'core', 'ports', 'load', 'folders', 'cpu', 'alert', 'cloud', 'version', 'now'])"}
$ curl http://localhost:61208/api/4/all
{"raid":{},"uptime":"21:01:15","memswap":{"total":104853504,"used":0,"free":104853504,"percent":0.0,"sin":0,"sout":0,"time_since_update":3715.211944103241},"system":{"os_name":"Linux","hostname":"xxxxxx","platform":"64bit","linux_distro":"Alpine Linux 3.19.1","os_version":"6.1.21-v8+","hr_name":"Alpine Linux 3.19.1 64bit / Linux 6.1.21-v8+"},"processcount":{"total":2,"running":0,"sleeping":2,"thread":15,"pid_max":0},"psutilversion":"5.9.8","help":null,"ip":{},"containers":{},"amps":[],"quicklook":{"cpu_name":"8","cpu_hz_current":600000000.0,"cpu_hz":1500000000.0,"cpu":0.1,"percpu":[{"key":"cpu_number","cpu_number":0,"total":0.1,"user":0.1,"system":0.0,"idle":99.9,"nice":0.0,"iowait":0.0,"irq":0.0,"softirq":0.0,"steal":0.0,"guest":0.0,"guest_nice":0.0},{"key":"cpu_number","cpu_number":1,"total":0.2,"user":0.1,"system":0.0,"idle":99.8,"nice":0.0,"iowait":0.1,"irq":0.0,"softirq":0.0,"steal":0.0,"guest":0.0,"guest_nice":0.0},{"key":"cpu_number","cpu_number":2,"total":0.2,"user":0.1,"system":0.1,"idle":99.8,"nice":0.0,"iowait":0.0,"irq":0.0,"softirq":0.0,"steal":0.0,"guest":0.0,"guest_nice":0.0},{"key":"cpu_number","cpu_number":3,"total":0.1,"user":0.1,"system":0.0,"idle":99.9,"nice":0.0,"iowait":0.0,"irq":0.0,"softirq":0.0,"steal":0.0,"guest":0.0,"guest_nice":0.0}],"mem":7.5,"swap":0.0,"cpu_log_core":4,"cpu_phys_core":4,"load":0.0},"fs":[],"sensors":[{"label":"cpu_thermal 0","unit":"C","value":48,"warning":110,"critical":110,"type":"temperature_core","key":"label"}],"mem":{"total":3978637312,"available":3678580736,"percent":7.5,"used":300056576,"free":3678580736,"active":746139648,"inactive":948842496,"buffers":125939712,"cached":1527926784,"shared":1302528},"network":[{"bytes_sent":1327476,"bytes_recv":1327476,"speed":0,"key":"interface_name","interface_name":"lo","alias":null,"bytes_all":2654952},{"bytes_sent":29392344,"bytes_recv":455897677,"speed":1048576000,"key":"interface_name","interface_name":"eth0","alias":null,"bytes_all":485290021},{"bytes_sent":0,"bytes_recv":0,"speed":0,"key":"interface_name","interface_name":"wlan0","alias":null,"bytes_all":0},{"bytes_sent":2212666,"bytes_recv":9623150,"speed":10485760000,"key":"interface_name","interface_name":"docker0","alias":null,"bytes_all":11835816},{"bytes_sent":2604532,"bytes_recv":9794412,"speed":10485760000,"key":"interface_name","interface_name":"vetha148260","alias":null,"bytes_all":12398944}],"connections":{"net_connections_enabled":true,"nf_conntrack_enabled":true},"core":{"phys":4,"log":4},"gpu":[],"ports":[],"smart":{},"load":{"min1":0.0,"min5":0.0,"min15":0.0,"cpucore":4},"irq":[],"folders":[],"cpu":{"total":0.1,"user":0.0,"nice":0.0,"system":0.0,"idle":0.0,"iowait":0.0,"irq":0.0,"steal":0.0,"guest":0.0,"ctx_switches":302271,"interrupts":213833,"soft_interrupts":84405,"syscalls":0,"cpucore":4,"time_since_update":3715.2347679138184,"ctx_switches_gauge":41681520,"ctx_switches_rate_per_sec":81.0,"interrupts_gauge":26325952,"interrupts_rate_per_sec":57.0,"soft_interrupts_gauge":6165405,"soft_interrupts_rate_per_sec":22.0,"syscalls_gauge":0,"syscalls_rate_per_sec":0.0},"alert":[],"percpu":[],"wifi":[],"diskio":[],"cloud":{},"processlist":[],"version":"4.0.7","now":{"iso":"2024-06-04T11:55:23+02:00","custom":"2024-06-04 11:55:23 CEST"}

You can also pastebin:

nicolargo commented 3 months ago

Analyze: the _api_all method called by /api/4/all route call stats.getAllAsDict(). Currently, this stat's method (only used in this case) do not get the "enable" plugin list but the full plugin list.

Proposal: change the stats.getAllAsDict() to optionally take into account enable plugin list.

nicolargo commented 3 months ago

Patch done in the develop branch.

Will be released in Glances 4.1.0.

Thanks for the issue report @wittypluck !

wittypluck commented 3 months ago

Thanks @nicolargo , I confirm the issue is fixed on dev tag.