From 326c2fef517471394437be36088a6847403129d5 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sat, 3 Jan 2026 15:12:53 +0100 Subject: [PATCH] Remove Netifaces dependency and use a pure Python to get Default Gateway. Ip address and Net mask are now retreived thanks to PSutil. --- README-pypi.rst | 1 - docs/api/python.rst | 370 +++++++++++++++--------------- docs/api/restful.rst | 387 ++++++++++++++++---------------- docs/faq.rst | 2 + glances/globals.py | 60 +++++ glances/plugins/ip/__init__.py | 50 +---- glances/ports_list.py | 17 +- glances/servers_list_dynamic.py | 40 +--- pyproject.toml | 3 - 9 files changed, 449 insertions(+), 481 deletions(-) diff --git a/README-pypi.rst b/README-pypi.rst index f2c75833..ed0db131 100644 --- a/README-pypi.rst +++ b/README-pypi.rst @@ -330,7 +330,6 @@ Extra dependencies: - ``influxdb`` (for the InfluxDB version 1 export module) - ``influxdb-client`` (for the InfluxDB version 2 export module) - ``kafka-python`` (for the Kafka export module) -- ``netifaces2`` (for the IP plugin) - ``nvidia-ml-py`` (for the GPU plugin) - ``pycouchdb`` (for the CouchDB export module) - ``pika`` (for the RabbitMQ/ActiveMQ export module) diff --git a/docs/api/python.rst b/docs/api/python.rst index 7c696504..1c84ec94 100644 --- a/docs/api/python.rst +++ b/docs/api/python.rst @@ -22,25 +22,25 @@ use the following code: >>> gl = api.GlancesAPI() >>> gl.cpu {'cpucore': 16, - 'ctx_switches': 424379607, + 'ctx_switches': 472872341, 'guest': 0.0, - 'idle': 92.0, - 'interrupts': 372289580, - 'iowait': 0.4, + 'idle': 93.5, + 'interrupts': 410386146, + 'iowait': 0.3, 'irq': 0.0, 'nice': 0.0, - 'soft_interrupts': 157664933, + 'soft_interrupts': 174928185, 'steal': 0.0, 'syscalls': 0, - 'system': 4.6, - 'total': 6.2, - 'user': 2.9} + 'system': 4.4, + 'total': 7.2, + 'user': 1.7} >>> gl.cpu.get("total") - 6.2 + 7.2 >>> gl.mem.get("used") - 12146165784 + 12810799128 >>> gl.auto_unit(gl.mem.get("used")) - 11.3G + 11.9G If the stats return a list of items (like network interfaces or processes), you can access them by their name: @@ -51,19 +51,19 @@ access them by their name: ['wlp0s20f3'] >>> gl.network["wlp0s20f3"] {'alias': None, - 'bytes_all': 931, - 'bytes_all_gauge': 14895804253, - 'bytes_all_rate_per_sec': 2574.0, - 'bytes_recv': 587, - 'bytes_recv_gauge': 13855313231, - 'bytes_recv_rate_per_sec': 1623.0, - 'bytes_sent': 344, - 'bytes_sent_gauge': 1040491022, - 'bytes_sent_rate_per_sec': 951.0, + 'bytes_all': 214, + 'bytes_all_gauge': 15142743463, + 'bytes_all_rate_per_sec': 606.0, + 'bytes_recv': 128, + 'bytes_recv_gauge': 13975900109, + 'bytes_recv_rate_per_sec': 362.0, + 'bytes_sent': 86, + 'bytes_sent_gauge': 1166843354, + 'bytes_sent_rate_per_sec': 243.0, 'interface_name': 'wlp0s20f3', 'key': 'interface_name', 'speed': 0, - 'time_since_update': 0.36159610748291016} + 'time_since_update': 0.3526580333709717} Init Glances Python API ----------------------- @@ -95,30 +95,30 @@ Alert stats: >>> type(gl.alert) >>> gl.alert - [{'avg': 90.53210309229192, - 'begin': 1767426673, + [{'avg': 99.96957776029373, + 'begin': 1767449522, 'count': 2, 'desc': '', 'end': -1, 'global_msg': 'High swap (paging) usage', - 'max': 90.53210309229192, - 'min': 90.53210309229192, + 'max': 99.96957776029373, + 'min': 99.96957776029373, 'sort': 'memory_percent', 'state': 'CRITICAL', - 'sum': 181.06420618458384, - 'top': ['code', 'code', 'firefox'], + 'sum': 199.93915552058746, + 'top': ['code', 'code', 'code'], 'type': 'MEMSWAP'}, - {'avg': 73.95270073392017, - 'begin': 1767426673, + {'avg': 77.95894443790266, + 'begin': 1767449522, 'count': 2, 'desc': '', 'end': -1, 'global_msg': 'High swap (paging) usage', - 'max': 73.9590481920313, - 'min': 73.94635327580903, + 'max': 78.00605779103407, + 'min': 77.91183108477124, 'sort': 'memory_percent', 'state': 'WARNING', - 'sum': 147.90540146784033, + 'sum': 155.91788887580532, 'top': [], 'type': 'MEM'}] @@ -156,12 +156,12 @@ Ports stats: >>> gl.ports [{'description': 'DefaultGateway', - 'host': '10.62.208.245', + 'host': '192.168.1.1', 'indice': 'port_0', 'port': 0, 'refresh': 30, 'rtt_warning': None, - 'status': 0.067668, + 'status': 0.008168, 'timeout': 3}] Ports fields description: @@ -202,14 +202,14 @@ Diskio stats: >>> gl.diskio.get("nvme0n1") {'disk_name': 'nvme0n1', 'key': 'disk_name', - 'read_bytes': 27877023232, - 'read_count': 1107469, + 'read_bytes': 29268151808, + 'read_count': 1162807, 'read_latency': 0, - 'read_time': 280806, - 'write_bytes': 41955222528, - 'write_count': 2861119, + 'read_time': 313717, + 'write_bytes': 44187964416, + 'write_count': 3047678, 'write_latency': 0, - 'write_time': 2271011} + 'write_time': 2442776} Diskio fields description: @@ -294,11 +294,11 @@ Processcount stats: >>> type(gl.processcount) >>> gl.processcount - {'pid_max': 0, 'running': 1, 'sleeping': 439, 'thread': 2375, 'total': 591} + {'pid_max': 0, 'running': 1, 'sleeping': 442, 'thread': 2444, 'total': 597} >>> gl.processcount.keys() ['total', 'running', 'sleeping', 'thread', 'pid_max'] >>> gl.processcount.get("total") - 591 + 597 Processcount fields description: @@ -379,7 +379,7 @@ Percpu stats: 'nice': 0.0, 'softirq': 0.0, 'steal': 0.0, - 'system': 9.0, + 'system': 10.0, 'total': 56.0, 'user': 0.0} @@ -471,18 +471,18 @@ Network stats: >>> gl.network.get("wlp0s20f3") {'alias': None, 'bytes_all': 0, - 'bytes_all_gauge': 14895804253, + 'bytes_all_gauge': 15142743463, 'bytes_all_rate_per_sec': 0.0, 'bytes_recv': 0, - 'bytes_recv_gauge': 13855313231, + 'bytes_recv_gauge': 13975900109, 'bytes_recv_rate_per_sec': 0.0, 'bytes_sent': 0, - 'bytes_sent_gauge': 1040491022, + 'bytes_sent_gauge': 1166843354, 'bytes_sent_rate_per_sec': 0.0, 'interface_name': 'wlp0s20f3', 'key': 'interface_name', 'speed': 0, - 'time_since_update': 0.002863645553588867} + 'time_since_update': 0.00287628173828125} Network fields description: @@ -523,23 +523,23 @@ Cpu stats: >>> gl.cpu {'cpucore': 16, - 'ctx_switches': 424379607, + 'ctx_switches': 472872341, 'guest': 0.0, - 'idle': 92.0, - 'interrupts': 372289580, - 'iowait': 0.4, + 'idle': 93.5, + 'interrupts': 410386146, + 'iowait': 0.3, 'irq': 0.0, 'nice': 0.0, - 'soft_interrupts': 157664933, + 'soft_interrupts': 174928185, 'steal': 0.0, 'syscalls': 0, - 'system': 4.6, - 'total': 6.2, - 'user': 2.9} + 'system': 4.4, + 'total': 7.2, + 'user': 1.7} >>> gl.cpu.keys() ['total', 'user', 'nice', 'system', 'idle', 'iowait', 'irq', 'steal', 'guest', 'ctx_switches', 'interrupts', 'soft_interrupts', 'syscalls', 'cpucore'] >>> gl.cpu.get("total") - 6.2 + 7.2 Cpu fields description: @@ -611,7 +611,7 @@ Amps stats: 'refresh': 3.0, 'regex': True, 'result': None, - 'timer': 0.323228120803833} + 'timer': 0.31592440605163574} Amps fields description: @@ -642,32 +642,32 @@ Processlist stats: >>> gl.processlist Return a dict of dict with key= >>> gl.processlist.keys() - [1, 2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 53, 54, 55, 56, 57, 59, 60, 61, 62, 63, 65, 66, 67, 68, 69, 71, 72, 73, 74, 75, 77, 78, 79, 80, 81, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 95, 96, 97, 98, 99, 101, 102, 103, 104, 105, 107, 108, 109, 110, 111, 113, 114, 115, 116, 117, 118, 121, 122, 123, 124, 125, 126, 127, 128, 133, 135, 136, 137, 138, 139, 140, 142, 143, 144, 145, 146, 147, 148, 150, 154, 156, 157, 158, 166, 179, 188, 189, 218, 219, 239, 240, 258, 267, 268, 269, 270, 271, 273, 279, 280, 364, 367, 369, 370, 371, 372, 373, 450, 452, 613, 618, 619, 620, 627, 659, 660, 726, 757, 758, 787, 795, 970, 971, 986, 1037, 1040, 1042, 1043, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1056, 1058, 1059, 1064, 1065, 1218, 1219, 1223, 1275, 1277, 1278, 1279, 1320, 1327, 1534, 1537, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 2007, 2008, 2009, 2010, 2011, 2013, 2014, 2016, 2017, 2018, 2019, 2020, 2021, 2023, 2052, 2053, 2054, 2055, 2056, 2057, 2058, 2059, 2060, 2061, 2062, 2063, 2064, 2065, 2066, 2067, 2068, 2069, 2070, 2071, 2072, 2073, 2074, 2075, 2078, 2079, 2080, 2081, 2082, 2083, 2084, 2085, 2086, 2087, 2088, 2089, 2090, 2091, 2092, 2093, 2094, 2095, 2096, 2097, 2098, 2099, 2100, 2101, 2102, 2103, 2104, 2105, 2117, 2122, 2123, 2124, 2125, 2126, 2127, 2128, 2129, 2130, 2133, 2134, 2135, 2136, 2137, 2138, 2139, 2140, 2141, 2142, 2143, 2144, 2145, 2149, 2603, 2604, 2605, 2606, 2613, 2615, 2744, 2745, 2746, 2750, 2751, 2755, 2762, 2774, 2781, 2788, 2791, 2796, 2799, 2802, 2813, 2820, 2823, 2887, 2904, 2905, 2916, 3031, 3038, 3081, 3181, 3182, 3186, 3191, 3192, 3240, 3382, 3383, 3670, 3671, 3695, 3698, 3807, 3817, 3818, 3822, 3827, 3828, 3846, 3853, 3874, 3901, 3902, 3903, 3904, 3905, 3906, 3907, 3908, 3982, 4194, 4596, 5146, 5166, 5172, 5179, 5189, 5190, 5193, 5195, 5197, 5207, 5263, 5267, 5274, 5318, 5333, 5421, 5425, 5441, 5453, 5457, 5492, 5505, 5509, 5593, 5612, 5620, 5621, 5634, 5657, 5658, 5661, 5664, 5665, 5667, 5669, 5672, 5675, 5678, 5680, 5685, 5687, 5693, 5695, 5700, 5708, 5726, 5734, 5829, 5832, 5833, 5844, 5861, 5871, 5914, 5921, 5931, 5941, 5954, 5957, 6017, 6063, 6087, 6093, 6094, 6123, 6154, 6206, 6244, 6475, 6505, 6552, 6559, 6562, 7227, 8412, 8526, 9631, 9649, 9661, 9731, 9734, 11010, 12121, 12123, 12124, 12138, 12192, 12239, 12278, 12321, 12335, 12336, 12417, 12686, 12726, 12735, 12929, 12931, 12933, 12934, 13048, 13115, 13536, 13665, 36430, 40117, 53755, 53764, 62488, 62637, 72064, 72065, 72120, 72139, 102070, 340569, 388396, 413445, 444052, 444061, 471623, 471714, 471892, 471899, 471919, 471929, 471954, 472557, 472566, 472570, 472785, 472854, 472861, 473314, 481055, 513901, 514243, 524431, 524432, 524447, 524457, 524551, 532126, 546233, 546254, 547205, 547220, 547714, 547732, 548091, 548102, 548622, 561234, 564559, 567573, 574078, 598539, 604653, 607301, 611703, 614410, 618951, 619505, 622299, 624217, 626612, 639936, 648416, 652689, 652881, 653438, 654061, 654062, 654065, 654075, 654078, 654079, 654084, 654088, 654089, 654092, 654094, 654095, 654097, 654101, 654102, 654261, 654791, 658059, 658444, 660200, 660866, 661443, 661802, 661966, 662309, 662533, 662902, 662943, 662984, 664170, 664744, 664861, 665130, 666402, 666436, 666721, 667135, 667477, 667735, 668262, 668263, 669291, 669326, 669609, 669978, 670115, 670295, 670361, 670362, 670452, 670570, 670626, 671131, 671134, 671135, 671138, 671164, 671165] + [1, 2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 53, 54, 55, 56, 57, 59, 60, 61, 62, 63, 65, 66, 67, 68, 69, 71, 72, 73, 74, 75, 77, 78, 79, 80, 81, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 95, 96, 97, 98, 99, 101, 102, 103, 104, 105, 107, 108, 109, 110, 111, 113, 114, 115, 116, 117, 118, 121, 122, 123, 124, 125, 126, 127, 128, 133, 135, 136, 137, 138, 139, 140, 142, 143, 144, 145, 146, 147, 148, 150, 154, 156, 157, 158, 166, 179, 188, 189, 218, 219, 239, 240, 258, 267, 268, 269, 270, 271, 273, 279, 280, 364, 367, 369, 370, 371, 372, 373, 450, 452, 613, 618, 619, 620, 627, 659, 660, 726, 757, 758, 787, 795, 970, 971, 986, 1037, 1040, 1042, 1043, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1056, 1058, 1059, 1064, 1065, 1218, 1219, 1223, 1275, 1277, 1278, 1279, 1320, 1327, 1534, 1537, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 2007, 2008, 2009, 2010, 2011, 2013, 2014, 2016, 2017, 2018, 2019, 2020, 2021, 2023, 2052, 2053, 2054, 2055, 2056, 2057, 2058, 2059, 2060, 2061, 2062, 2063, 2064, 2065, 2066, 2067, 2068, 2069, 2070, 2071, 2072, 2073, 2074, 2075, 2078, 2079, 2080, 2081, 2082, 2083, 2084, 2085, 2086, 2087, 2088, 2089, 2090, 2091, 2092, 2093, 2094, 2095, 2096, 2097, 2098, 2099, 2100, 2101, 2102, 2103, 2104, 2105, 2117, 2122, 2123, 2124, 2125, 2126, 2127, 2128, 2129, 2130, 2133, 2134, 2135, 2136, 2137, 2138, 2139, 2140, 2141, 2142, 2143, 2144, 2145, 2149, 2603, 2604, 2605, 2606, 2613, 2615, 2744, 2745, 2746, 2750, 2751, 2755, 2762, 2774, 2781, 2788, 2791, 2796, 2799, 2802, 2813, 2820, 2823, 2887, 2904, 2905, 2916, 3031, 3038, 3081, 3181, 3182, 3186, 3191, 3192, 3240, 3382, 3383, 3670, 3671, 3695, 3698, 3807, 3817, 3818, 3822, 3827, 3828, 3846, 3853, 3874, 3901, 3902, 3903, 3904, 3905, 3906, 3907, 3908, 3982, 4194, 4596, 5146, 5166, 5172, 5179, 5189, 5190, 5193, 5195, 5197, 5207, 5263, 5267, 5274, 5318, 5333, 5421, 5425, 5441, 5453, 5457, 5492, 5505, 5509, 5593, 5612, 5620, 5621, 5634, 5657, 5658, 5661, 5664, 5665, 5667, 5669, 5672, 5675, 5678, 5680, 5685, 5687, 5693, 5695, 5700, 5708, 5726, 5734, 5829, 5832, 5833, 5844, 5861, 5871, 5914, 5921, 5931, 5941, 5954, 5957, 6017, 6063, 6087, 6093, 6094, 6123, 6154, 6206, 6244, 6475, 6505, 6552, 6559, 6562, 7227, 8412, 8526, 9631, 9649, 9661, 9731, 9734, 11010, 12121, 12123, 12124, 12138, 12192, 12239, 12278, 12321, 12335, 12336, 12417, 12686, 12726, 12735, 12929, 12931, 12933, 12934, 13048, 13115, 13536, 13665, 36430, 40117, 53755, 53764, 62488, 62637, 72064, 72065, 72120, 72139, 102070, 340569, 388396, 413445, 444052, 444061, 471623, 471714, 471892, 471899, 471919, 471929, 471954, 472557, 472566, 472570, 472785, 472854, 472861, 473314, 481055, 513901, 514243, 524431, 524432, 524447, 524457, 524551, 546233, 546254, 547205, 547220, 547714, 547732, 548091, 548102, 548622, 561234, 564559, 567573, 654061, 661802, 671732, 683980, 686191, 695926, 701770, 705018, 705167, 707900, 708398, 709364, 709585, 710008, 710952, 714751, 714947, 721023, 721204, 726507, 728005, 728006, 728008, 728465, 730137, 731844, 732902, 733166, 733167, 733841, 733865, 734183, 735109, 735551, 736180, 736316, 736396, 736607, 737036, 737183, 737369, 737866, 738311, 738732, 739425, 739889, 740008, 740325, 740438, 741044, 741346, 741856, 742102, 742589, 742967, 743001, 743292, 743314, 743466, 743467, 743468, 743469, 743470, 743471, 743554, 743752, 743753, 743869, 743926, 743942, 744023, 744188, 744189, 744276, 744281, 745624, 745766, 745875, 745878, 745879, 745882] >>> gl.processlist.get("1") {'cmdline': ['/sbin/init', 'splash'], 'cpu_percent': 0.0, - 'cpu_times': {'children_system': 290.46, - 'children_user': 5148.19, + 'cpu_times': {'children_system': 292.72, + 'children_user': 5149.74, 'iowait': 0.0, - 'system': 8.42, - 'user': 11.63}, + 'system': 9.16, + 'user': 13.08}, 'gids': {'effective': 0, 'real': 0, 'saved': 0}, 'io_counters': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'key': 'pid', 'memory_info': {'data': 7282688, 'dirty': 0, 'lib': 0, - 'rss': 14610432, - 'shared': 8159232, + 'rss': 14585856, + 'shared': 8134656, 'text': 45056, 'vms': 26632192}, - 'memory_percent': 0.0889641771412196, + 'memory_percent': 0.0888145317633538, 'name': 'systemd', 'nice': 0, 'num_threads': 1, 'pid': 1, 'status': 'S', - 'time_since_update': 0.6753289699554443, + 'time_since_update': 0.6452903747558594, 'username': 'root'} Processlist fields description: @@ -752,13 +752,13 @@ Load stats: >>> gl.load {'cpucore': 16, - 'min1': 1.50830078125, - 'min15': 0.97412109375, - 'min5': 1.22705078125} + 'min1': 0.869140625, + 'min15': 1.04248046875, + 'min5': 1.04052734375} >>> gl.load.keys() ['min1', 'min5', 'min15', 'cpucore'] >>> gl.load.get("min1") - 1.50830078125 + 0.869140625 Load fields description: @@ -797,7 +797,7 @@ Sensors stats: 'label': 'Ambient', 'type': 'temperature_core', 'unit': 'C', - 'value': 28, + 'value': 34, 'warning': 0} Sensors fields description: @@ -835,7 +835,7 @@ Uptime stats: >>> type(gl.uptime) >>> gl.uptime - '6 days, 16:25:30' + '6 days, 22:46:17' Uptime limits: @@ -854,11 +854,11 @@ Now stats: >>> type(gl.now) >>> gl.now - {'custom': '2026-01-03 08:51:14 CET', 'iso': '2026-01-03T08:51:14+01:00'} + {'custom': '2026-01-03 15:12:02 CET', 'iso': '2026-01-03T15:12:02+01:00'} >>> gl.now.keys() ['iso', 'custom'] >>> gl.now.get("iso") - '2026-01-03T08:51:14+01:00' + '2026-01-03T15:12:02+01:00' Now fields description: @@ -886,16 +886,15 @@ Fs stats: >>> gl.fs.keys() ['/', '/zsfpool'] >>> gl.fs.get("/") - {'alias': 'Root', - 'device_name': '/dev/mapper/ubuntu--vg-ubuntu--lv', - 'free': 582306385920, + {'device_name': '/dev/mapper/ubuntu--vg-ubuntu--lv', + 'free': 582918623232, 'fs_type': 'ext4', 'key': 'mnt_point', 'mnt_point': '/', 'options': 'rw,relatime', - 'percent': 38.9, + 'percent': 38.8, 'size': 1003736440832, - 'used': 370367549440} + 'used': 369755312128} Fs fields description: @@ -913,8 +912,7 @@ Fs limits: .. code-block:: python >>> gl.fs.limits - {'fs_alias': ['/:Root', '/zfspool:ZFS'], - 'fs_careful': 50.0, + {'fs_careful': 50.0, 'fs_critical': 90.0, 'fs_disable': ['False'], 'fs_hide': ['/boot.*', '.*/snap.*'], @@ -936,8 +934,8 @@ Wifi stats: ['wlp0s20f3'] >>> gl.wifi.get("wlp0s20f3") {'key': 'ssid', - 'quality_level': -44.0, - 'quality_link': 66.0, + 'quality_level': -60.0, + 'quality_link': 50.0, 'ssid': 'wlp0s20f3'} Wifi limits: @@ -961,7 +959,7 @@ Ip stats: >>> type(gl.ip) >>> gl.ip - {'address': '10.62.208.39', + {'address': '192.168.1.26', 'mask': '255.255.255.0', 'mask_cidr': 24, 'public_address': '', @@ -969,7 +967,7 @@ Ip stats: >>> gl.ip.keys() ['address', 'mask', 'mask_cidr', 'public_address', 'public_info_human'] >>> gl.ip.get("address") - '10.62.208.39' + '192.168.1.26' Ip fields description: @@ -1069,16 +1067,16 @@ Mem stats: >>> type(gl.mem) >>> gl.mem - {'active': 4547899392, - 'available': 4276660200, - 'buffers': 186654720, - 'cached': 3829238632, - 'free': 998457344, - 'inactive': 8566132736, - 'percent': 74.0, - 'shared': 783462400, + {'active': 5529219072, + 'available': 3612026856, + 'buffers': 130482176, + 'cached': 3568499560, + 'free': 1333854208, + 'inactive': 7177965568, + 'percent': 78.0, + 'shared': 840089600, 'total': 16422825984, - 'used': 12146165784} + 'used': 12810799128} >>> gl.mem.keys() ['total', 'available', 'percent', 'used', 'free', 'active', 'inactive', 'buffers', 'cached', 'shared'] >>> gl.mem.get("total") @@ -1148,14 +1146,14 @@ Quicklook stats: >>> type(gl.quicklook) >>> gl.quicklook - {'cpu': 6.2, + {'cpu': 7.2, 'cpu_hz': 4475000000.0, - 'cpu_hz_current': 1252763375.0000002, + 'cpu_hz_current': 608909250.0, 'cpu_log_core': 16, 'cpu_name': '13th Gen Intel(R) Core(TM) i7-13620H', 'cpu_phys_core': 10, - 'load': 6.1, - 'mem': 74.0, + 'load': 6.5, + 'mem': 78.0, 'percpu': [{'cpu_number': 0, 'dpc': None, 'guest': 0.0, @@ -1168,7 +1166,7 @@ Quicklook stats: 'nice': 0.0, 'softirq': 0.0, 'steal': 0.0, - 'system': 9.0, + 'system': 10.0, 'total': 56.0, 'user': 0.0}, {'cpu_number': 1, @@ -1198,70 +1196,10 @@ Quicklook stats: 'nice': 0.0, 'softirq': 0.0, 'steal': 0.0, - 'system': 0.0, + 'system': 1.0, 'total': 45.0, - 'user': 0.0}, - {'cpu_number': 3, - 'dpc': None, - 'guest': 0.0, - 'guest_nice': 0.0, - 'idle': 56.0, - 'interrupt': None, - 'iowait': 0.0, - 'irq': 0.0, - 'key': 'cpu_number', - 'nice': 0.0, - 'softirq': 0.0, - 'steal': 0.0, - 'system': 0.0, - 'total': 44.0, - 'user': 0.0}, - {'cpu_number': 4, - 'dpc': None, - 'guest': 0.0, - 'guest_nice': 0.0, - 'idle': 44.0, - 'interrupt': None, - 'iowait': 0.0, - 'irq': 0.0, - 'key': 'cpu_number', - 'nice': 0.0, - 'softirq': 0.0, - 'steal': 0.0, - 'system': 10.0, - 'total': 56.0, 'user': 1.0}, - {'cpu_number': 5, - 'dpc': None, - 'guest': 0.0, - 'guest_nice': 0.0, - 'idle': 46.0, - 'interrupt': None, - 'iowait': 0.0, - 'irq': 0.0, - 'key': 'cpu_number', - 'nice': 0.0, - 'softirq': 0.0, - 'steal': 0.0, - 'system': 6.0, - 'total': 54.0, - 'user': 0.0}, - {'cpu_number': 6, - 'dpc': None, - 'guest': 0.0, - 'guest_nice': 0.0, - 'idle': 34.0, - 'interrupt': None, - 'iowait': 0.0, - 'irq': 0.0, - 'key': 'cpu_number', - 'nice': 0.0, - 'softirq': 0.0, - 'steal': 0.0, - 'system': 9.0, - 'total': 66.0, - 'user': 12.0}, - {'cpu_number': 7, + {'cpu_number': 3, 'dpc': None, 'guest': 0.0, 'guest_nice': 0.0, @@ -1276,11 +1214,26 @@ Quicklook stats: 'system': 0.0, 'total': 45.0, 'user': 0.0}, - {'cpu_number': 8, + {'cpu_number': 4, 'dpc': None, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 54.0, + 'idle': 51.0, + 'interrupt': None, + 'iowait': 0.0, + 'irq': 0.0, + 'key': 'cpu_number', + 'nice': 0.0, + 'softirq': 0.0, + 'steal': 0.0, + 'system': 3.0, + 'total': 49.0, + 'user': 1.0}, + {'cpu_number': 5, + 'dpc': None, + 'guest': 0.0, + 'guest_nice': 0.0, + 'idle': 55.0, 'interrupt': None, 'iowait': 0.0, 'irq': 0.0, @@ -1289,13 +1242,58 @@ Quicklook stats: 'softirq': 0.0, 'steal': 0.0, 'system': 0.0, - 'total': 46.0, + 'total': 45.0, + 'user': 0.0}, + {'cpu_number': 6, + 'dpc': None, + 'guest': 0.0, + 'guest_nice': 0.0, + 'idle': 45.0, + 'interrupt': None, + 'iowait': 0.0, + 'irq': 0.0, + 'key': 'cpu_number', + 'nice': 0.0, + 'softirq': 0.0, + 'steal': 0.0, + 'system': 8.0, + 'total': 55.0, + 'user': 3.0}, + {'cpu_number': 7, + 'dpc': None, + 'guest': 0.0, + 'guest_nice': 0.0, + 'idle': 28.0, + 'interrupt': None, + 'iowait': 1.0, + 'irq': 0.0, + 'key': 'cpu_number', + 'nice': 0.0, + 'softirq': 0.0, + 'steal': 0.0, + 'system': 15.0, + 'total': 72.0, + 'user': 11.0}, + {'cpu_number': 8, + 'dpc': None, + 'guest': 0.0, + 'guest_nice': 0.0, + 'idle': 52.0, + 'interrupt': None, + 'iowait': 2.0, + 'irq': 0.0, + 'key': 'cpu_number', + 'nice': 0.0, + 'softirq': 0.0, + 'steal': 0.0, + 'system': 1.0, + 'total': 48.0, 'user': 1.0}, {'cpu_number': 9, 'dpc': None, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 56.0, + 'idle': 55.0, 'interrupt': None, 'iowait': 0.0, 'irq': 0.0, @@ -1303,8 +1301,8 @@ Quicklook stats: 'nice': 0.0, 'softirq': 0.0, 'steal': 0.0, - 'system': 0.0, - 'total': 44.0, + 'system': 1.0, + 'total': 45.0, 'user': 0.0}, {'cpu_number': 10, 'dpc': None, @@ -1318,9 +1316,9 @@ Quicklook stats: 'nice': 0.0, 'softirq': 0.0, 'steal': 0.0, - 'system': 0.0, + 'system': 1.0, 'total': 46.0, - 'user': 0.0}, + 'user': 1.0}, {'cpu_number': 11, 'dpc': None, 'guest': 0.0, @@ -1346,11 +1344,11 @@ Quicklook stats: 'irq': 0.0, 'key': 'cpu_number', 'nice': 0.0, - 'softirq': 1.0, + 'softirq': 0.0, 'steal': 0.0, 'system': 0.0, 'total': 45.0, - 'user': 1.0}, + 'user': 0.0}, {'cpu_number': 13, 'dpc': None, 'guest': 0.0, @@ -1378,9 +1376,9 @@ Quicklook stats: 'nice': 0.0, 'softirq': 0.0, 'steal': 0.0, - 'system': 0.0, + 'system': 1.0, 'total': 45.0, - 'user': 1.0}, + 'user': 0.0}, {'cpu_number': 15, 'dpc': None, 'guest': 0.0, @@ -1393,10 +1391,10 @@ Quicklook stats: 'nice': 0.0, 'softirq': 0.0, 'steal': 0.0, - 'system': 0.0, + 'system': 1.0, 'total': 45.0, - 'user': 0.0}], - 'swap': 90.5} + 'user': 1.0}], + 'swap': 100.0} >>> gl.quicklook.keys() ['cpu_name', 'cpu_hz_current', 'cpu_hz', 'cpu', 'percpu', 'mem', 'swap', 'cpu_log_core', 'cpu_phys_core', 'load'] >>> gl.quicklook.get("cpu_name") @@ -1446,13 +1444,13 @@ Memswap stats: >>> type(gl.memswap) >>> gl.memswap - {'free': 406642688, - 'percent': 90.5, - 'sin': 2149658624, - 'sout': 7170572288, - 'time_since_update': 0.7601914405822754, + {'free': 1306624, + 'percent': 100.0, + 'sin': 2306797568, + 'sout': 7715819520, + 'time_since_update': 0.7321233749389648, 'total': 4294963200, - 'used': 3888320512} + 'used': 4293656576} >>> gl.memswap.keys() ['total', 'used', 'free', 'percent', 'sin', 'sout', 'time_since_update'] >>> gl.memswap.get("total") @@ -1487,10 +1485,10 @@ Use auto_unit() function to generate a human-readable string with the unit: .. code-block:: python >>> gl.mem.get("used") - 12146165784 + 12810799128 >>> gl.auto_unit(gl.mem.get("used")) - 11.3G + 11.9G Args: @@ -1516,7 +1514,7 @@ Use bar() function to generate a bar: .. code-block:: python >>> gl.bar(gl.mem["percent"]) - ■■■■■■■■■■■■■□□□□□ + ■■■■■■■■■■■■■■□□□□ Args: @@ -1546,7 +1544,7 @@ Use top_process() function to generate a list of top processes sorted by CPU or .. code-block:: python >>> gl.top_process() - [{'num_threads': 25, 'name': 'code', 'memory_percent': 4.193961360066981, 'status': 'S', 'io_counters': [148809728, 1732608, 148809728, 1732608, 1], 'memory_info': {'rss': 688766976, 'vms': 1517470724096, 'shared': 85463040, 'text': 148733952, 'lib': 0, 'data': 1770684416, 'dirty': 0}, 'cpu_percent': 12.5, 'cpu_times': {'user': 3545.45, 'system': 274.61, 'children_user': 0.0, 'children_system': 0.0, 'iowait': 0.0}, 'gids': {'real': 1000, 'effective': 1000, 'saved': 1000}, 'pid': 12239, 'nice': 0, 'key': 'pid', 'time_since_update': 0.6753289699554443, 'cmdline': ['/snap/code/211/usr/share/code/code', '--type=zygote', '--no-sandbox'], 'username': 'nicolargo'}, {'num_threads': 22, 'name': 'code', 'memory_percent': 5.9650892297976865, 'status': 'S', 'io_counters': [1488760832, 484003840, 1488760832, 484003840, 1], 'memory_info': {'rss': 979636224, 'vms': 1499914432512, 'shared': 35229696, 'text': 148733952, 'lib': 0, 'data': 2720628736, 'dirty': 0}, 'cpu_percent': 1.6, 'cpu_times': {'user': 1337.69, 'system': 623.58, 'children_user': 805.37, 'children_system': 784.59, 'iowait': 0.0}, 'gids': {'real': 1000, 'effective': 1000, 'saved': 1000}, 'pid': 12321, 'nice': 0, 'key': 'pid', 'time_since_update': 0.6753289699554443, 'cmdline': ['/proc/self/exe', '--type=utility', '--utility-sub-type=node.mojom.NodeService', '--lang=en-US', '--service-sandbox-type=none', '--no-sandbox', '--dns-result-order=ipv4first', '--experimental-network-inspection', '--inspect-port=0', '--crashpad-handler-pid=12138', '--enable-crash-reporter=864d4bb7-dd20-4851-830f-29e81dd93517,no_channel', '--user-data-dir=/home/nicolargo/.config/Code', '--standard-schemes=vscode-webview,vscode-file', '--secure-schemes=vscode-webview,vscode-file', '--cors-schemes=vscode-webview,vscode-file', '--fetch-schemes=vscode-webview,vscode-file', '--service-worker-schemes=vscode-webview', '--code-cache-schemes=vscode-webview,vscode-file', '--shared-files=v8_context_snapshot_data:100', '--field-trial-handle=3,i,768474601394521582,1148810169323883902,262144', '--enable-features=DocumentPolicyIncludeJSCallStacksInCrashReports,EarlyEstablishGpuChannel,EstablishGpuChannelAsync', '--disable-features=CalculateNativeWinOcclusion,FontationsLinuxSystemFonts,ScreenAIOCREnabled,SpareRendererForSitePerProcess', '--variations-seed-version'], 'username': 'nicolargo'}, {'num_threads': 15, 'name': 'claude', 'memory_percent': 2.186618261375106, 'status': 'S', 'io_counters': [118784, 21598208, 118784, 21598208, 1], 'memory_info': {'rss': 359104512, 'vms': 76524011520, 'shared': 10592256, 'text': 61407232, 'lib': 0, 'data': 73645785088, 'dirty': 0}, 'cpu_percent': 1.6, 'cpu_times': {'user': 8.47, 'system': 3.6, 'children_user': 1.1, 'children_system': 0.59, 'iowait': 0.0}, 'gids': {'real': 1000, 'effective': 1000, 'saved': 1000}, 'pid': 547714, 'nice': 0, 'key': 'pid', 'time_since_update': 0.6753289699554443, 'cmdline': ['/home/nicolargo/.vscode/extensions/anthropic.claude-code-2.0.75-linux-x64/resources/native-binary/claude', '--output-format', 'stream-json', '--verbose', '--input-format', 'stream-json', '--max-thinking-tokens', '0', '--model', 'default', '--permission-prompt-tool', 'stdio', '--setting-sources', 'user,project,local', '--permission-mode', 'default', '--include-partial-messages', '--debug', '--debug-to-stderr', '--enable-auth-status'], 'username': 'nicolargo'}] + [{'status': 'S', 'memory_info': {'rss': 833155072, 'vms': 1499914432512, 'shared': 37560320, 'text': 148733952, 'lib': 0, 'data': 2573008896, 'dirty': 0}, 'name': 'code', 'nice': 0, 'memory_percent': 5.073152895924881, 'gids': {'real': 1000, 'effective': 1000, 'saved': 1000}, 'num_threads': 22, 'io_counters': [1554405376, 611483648, 1554405376, 611483648, 1], 'pid': 12321, 'cpu_percent': 1.6, 'cpu_times': {'user': 1797.6, 'system': 767.31, 'children_user': 1013.92, 'children_system': 950.58, 'iowait': 0.0}, 'key': 'pid', 'time_since_update': 0.6452903747558594, 'cmdline': ['/proc/self/exe', '--type=utility', '--utility-sub-type=node.mojom.NodeService', '--lang=en-US', '--service-sandbox-type=none', '--no-sandbox', '--dns-result-order=ipv4first', '--experimental-network-inspection', '--inspect-port=0', '--crashpad-handler-pid=12138', '--enable-crash-reporter=864d4bb7-dd20-4851-830f-29e81dd93517,no_channel', '--user-data-dir=/home/nicolargo/.config/Code', '--standard-schemes=vscode-webview,vscode-file', '--secure-schemes=vscode-webview,vscode-file', '--cors-schemes=vscode-webview,vscode-file', '--fetch-schemes=vscode-webview,vscode-file', '--service-worker-schemes=vscode-webview', '--code-cache-schemes=vscode-webview,vscode-file', '--shared-files=v8_context_snapshot_data:100', '--field-trial-handle=3,i,768474601394521582,1148810169323883902,262144', '--enable-features=DocumentPolicyIncludeJSCallStacksInCrashReports,EarlyEstablishGpuChannel,EstablishGpuChannelAsync', '--disable-features=CalculateNativeWinOcclusion,FontationsLinuxSystemFonts,ScreenAIOCREnabled,SpareRendererForSitePerProcess', '--variations-seed-version'], 'username': 'nicolargo'}, {'status': 'S', 'memory_info': {'rss': 610873344, 'vms': 31620141056, 'shared': 180371456, 'text': 708608, 'lib': 0, 'data': 1298669568, 'dirty': 0}, 'name': 'firefox', 'nice': 0, 'memory_percent': 3.71966033492132, 'gids': {'real': 1000, 'effective': 1000, 'saved': 1000}, 'num_threads': 157, 'io_counters': [1705658368, 4228337664, 1705658368, 4228337664, 1], 'pid': 471623, 'cpu_percent': 1.6, 'cpu_times': {'user': 2637.37, 'system': 751.51, 'children_user': 0.13, 'children_system': 1.18, 'iowait': 0.0}, 'key': 'pid', 'time_since_update': 0.6452903747558594, 'cmdline': ['/snap/firefox/7559/usr/lib/firefox/firefox'], 'username': 'nicolargo'}, {'status': 'S', 'memory_info': {'rss': 478920704, 'vms': 4367515648, 'shared': 76931072, 'text': 708608, 'lib': 0, 'data': 692023296, 'dirty': 0}, 'name': 'Isolated Web Co', 'nice': 0, 'memory_percent': 2.9161893602635156, 'gids': {'real': 1000, 'effective': 1000, 'saved': 1000}, 'num_threads': 33, 'io_counters': [38509568, 0, 38509568, 0, 1], 'pid': 472861, 'cpu_percent': 1.6, 'cpu_times': {'user': 925.58, 'system': 94.68, 'children_user': 0.0, 'children_system': 0.0, 'iowait': 0.0}, 'key': 'pid', 'time_since_update': 0.6452903747558594, 'cmdline': ['/snap/firefox/7559/usr/lib/firefox/firefox', '-contentproc', '-isForBrowser', '-prefsHandle', '0:45904', '-prefMapHandle', '1:280269', '-jsInitHandle', '2:223356', '-parentBuildID', '20251217233610', '-sandboxReporter', '3', '-chrootClient', '4', '-ipcHandle', '5', '-initialChannelId', '{b750b1b5-b51f-4cbd-8493-9c918fb23a11}', '-parentPid', '471623', '-crashReporter', '6', '-crashHelper', '7', '-greomni', '/snap/firefox/7559/usr/lib/firefox/omni.ja', '-appomni', '/snap/firefox/7559/usr/lib/firefox/browser/omni.ja', '-appDir', '/snap/firefox/7559/usr/lib/firefox/browser', '11', 'tab'], 'username': 'nicolargo'}] Args: diff --git a/docs/api/restful.rst b/docs/api/restful.rst index 9ecbb702..e9446b72 100644 --- a/docs/api/restful.rst +++ b/docs/api/restful.rst @@ -160,7 +160,7 @@ Get plugin stats:: "refresh": 3.0, "regex": True, "result": None, - "timer": 0.5697028636932373}, + "timer": 0.5492854118347168}, {"count": 0, "countmax": 20.0, "countmin": None, @@ -169,7 +169,7 @@ Get plugin stats:: "refresh": 3.0, "regex": True, "result": None, - "timer": 0.5693261623382568}] + "timer": 0.5491828918457031}] Fields descriptions: @@ -197,7 +197,7 @@ Get a specific item when field matches the given value:: "refresh": 3.0, "regex": True, "result": None, - "timer": 0.5697028636932373}]} + "timer": 0.5492854118347168}]} GET cloud --------- @@ -287,19 +287,19 @@ Get plugin stats:: # curl http://localhost:61208/api/4/cpu {"cpucore": 16, - "ctx_switches": 424397936, + "ctx_switches": 472895569, "guest": 0.0, - "idle": 93.6, - "interrupts": 372305428, - "iowait": 0.1, + "idle": 93.1, + "interrupts": 410401982, + "iowait": 0.3, "irq": 0.0, "nice": 0.0, - "soft_interrupts": 157673564, + "soft_interrupts": 174937132, "steal": 0.0, "syscalls": 0, - "system": 3.0, - "total": 6.1, - "user": 3.4} + "system": 2.9, + "total": 6.6, + "user": 3.7} Fields descriptions: @@ -332,7 +332,7 @@ Fields descriptions: Get a specific field:: # curl http://localhost:61208/api/4/cpu/total - {"total": 6.1} + {"total": 6.6} GET diskio ---------- @@ -342,14 +342,14 @@ Get plugin stats:: # curl http://localhost:61208/api/4/diskio [{"disk_name": "nvme0n1", "key": "disk_name", - "read_bytes": 27877469696, - "read_count": 1107482, + "read_bytes": 29274824192, + "read_count": 1163128, "read_latency": 0, - "read_time": 280819, - "write_bytes": 41955394560, - "write_count": 2861124, + "read_time": 313808, + "write_bytes": 44188152832, + "write_count": 3047685, "write_latency": 0, - "write_time": 2271036}, + "write_time": 2442820}, {"disk_name": "nvme0n1p1", "key": "disk_name", "read_bytes": 14747648, @@ -401,14 +401,14 @@ Get a specific item when field matches the given value:: # curl http://localhost:61208/api/4/diskio/disk_name/value/nvme0n1 {"nvme0n1": [{"disk_name": "nvme0n1", "key": "disk_name", - "read_bytes": 27877469696, - "read_count": 1107482, + "read_bytes": 29274824192, + "read_count": 1163128, "read_latency": 0, - "read_time": 280819, - "write_bytes": 41955394560, - "write_count": 2861124, + "read_time": 313808, + "write_bytes": 44188152832, + "write_count": 3047685, "write_latency": 0, - "write_time": 2271036}]} + "write_time": 2442820}]} GET folders ----------- @@ -434,16 +434,15 @@ GET fs Get plugin stats:: # curl http://localhost:61208/api/4/fs - [{"alias": "Root", - "device_name": "/dev/mapper/ubuntu--vg-ubuntu--lv", - "free": 582306398208, + [{"device_name": "/dev/mapper/ubuntu--vg-ubuntu--lv", + "free": 582918635520, "fs_type": "ext4", "key": "mnt_point", "mnt_point": "/", "options": "rw,relatime", - "percent": 38.9, + "percent": 38.8, "size": 1003736440832, - "used": 370367537152}, + "used": 369755299840}, {"device_name": "zsfpool", "free": 41680896, "fs_type": "zfs", @@ -473,16 +472,15 @@ Get a specific field:: Get a specific item when field matches the given value:: # curl http://localhost:61208/api/4/fs/mnt_point/value// - {"/": [{"alias": "Root", - "device_name": "/dev/mapper/ubuntu--vg-ubuntu--lv", - "free": 582306398208, + {"/": [{"device_name": "/dev/mapper/ubuntu--vg-ubuntu--lv", + "free": 582918635520, "fs_type": "ext4", "key": "mnt_point", "mnt_point": "/", "options": "rw,relatime", - "percent": 38.9, + "percent": 38.8, "size": 1003736440832, - "used": 370367537152}]} + "used": 369755299840}]} GET gpu ------- @@ -515,7 +513,7 @@ GET ip Get plugin stats:: # curl http://localhost:61208/api/4/ip - {"address": "10.62.208.39", + {"address": "192.168.1.26", "mask": "255.255.255.0", "mask_cidr": 24, "public_address": "", @@ -533,7 +531,7 @@ Fields descriptions: Get a specific field:: # curl http://localhost:61208/api/4/ip/address - {"address": "10.62.208.39"} + {"address": "192.168.1.26"} GET irq ------- @@ -555,9 +553,9 @@ Get plugin stats:: # curl http://localhost:61208/api/4/load {"cpucore": 16, - "min1": 1.46728515625, - "min15": 0.974609375, - "min5": 1.22314453125} + "min1": 0.79931640625, + "min15": 1.03662109375, + "min5": 1.02294921875} Fields descriptions: @@ -569,7 +567,7 @@ Fields descriptions: Get a specific field:: # curl http://localhost:61208/api/4/load/min1 - {"min1": 1.46728515625} + {"min1": 0.79931640625} GET mem ------- @@ -577,16 +575,16 @@ GET mem Get plugin stats:: # curl http://localhost:61208/api/4/mem - {"active": 4544765952, - "available": 4291725288, - "buffers": 186662912, - "cached": 3842374504, - "free": 1012998144, - "inactive": 8566657024, - "percent": 73.9, - "shared": 796164096, + {"active": 5510766592, + "available": 3639285736, + "buffers": 130744320, + "cached": 3574328168, + "free": 1352519680, + "inactive": 7184216064, + "percent": 77.8, + "shared": 839827456, "total": 16422825984, - "used": 12131100696} + "used": 12783540248} Fields descriptions: @@ -613,13 +611,13 @@ GET memswap Get plugin stats:: # curl http://localhost:61208/api/4/memswap - {"free": 406642688, - "percent": 90.5, - "sin": 2149658624, - "sout": 7170572288, + {"free": 1576960, + "percent": 100.0, + "sin": 2307080192, + "sout": 7715819520, "time_since_update": 1, "total": 4294963200, - "used": 3888320512} + "used": 4293386240} Fields descriptions: @@ -644,18 +642,18 @@ Get plugin stats:: # curl http://localhost:61208/api/4/network [{"alias": None, "bytes_all": 0, - "bytes_all_gauge": 14895811367, + "bytes_all_gauge": 15142749821, "bytes_all_rate_per_sec": 0, "bytes_recv": 0, - "bytes_recv_gauge": 13855316236, + "bytes_recv_gauge": 13975902890, "bytes_recv_rate_per_sec": 0, "bytes_sent": 0, - "bytes_sent_gauge": 1040495131, + "bytes_sent_gauge": 1166846931, "bytes_sent_rate_per_sec": 0, "interface_name": "wlp0s20f3", "key": "interface_name", "speed": 0, - "time_since_update": 0.5848021507263184}] + "time_since_update": 0.5604753494262695}] Fields descriptions: @@ -684,18 +682,18 @@ Get a specific item when field matches the given value:: # curl http://localhost:61208/api/4/network/interface_name/value/wlp0s20f3 {"wlp0s20f3": [{"alias": None, "bytes_all": 0, - "bytes_all_gauge": 14895811367, + "bytes_all_gauge": 15142749821, "bytes_all_rate_per_sec": 0, "bytes_recv": 0, - "bytes_recv_gauge": 13855316236, + "bytes_recv_gauge": 13975902890, "bytes_recv_rate_per_sec": 0, "bytes_sent": 0, - "bytes_sent_gauge": 1040495131, + "bytes_sent_gauge": 1166846931, "bytes_sent_rate_per_sec": 0, "interface_name": "wlp0s20f3", "key": "interface_name", "speed": 0, - "time_since_update": 0.5848021507263184}]} + "time_since_update": 0.5604753494262695}]} GET now ------- @@ -703,7 +701,7 @@ GET now Get plugin stats:: # curl http://localhost:61208/api/4/now - {"custom": "2026-01-03 08:51:19 CET", "iso": "2026-01-03T08:51:19+01:00"} + {"custom": "2026-01-03 15:12:07 CET", "iso": "2026-01-03T15:12:07+01:00"} Fields descriptions: @@ -713,7 +711,7 @@ Fields descriptions: Get a specific field:: # curl http://localhost:61208/api/4/now/iso - {"iso": "2026-01-03T08:51:19+01:00"} + {"iso": "2026-01-03T15:12:07+01:00"} GET percpu ---------- @@ -725,7 +723,7 @@ Get plugin stats:: "dpc": None, "guest": 0.0, "guest_nice": 0.0, - "idle": 44.0, + "idle": 43.0, "interrupt": None, "iowait": 0.0, "irq": 0.0, @@ -734,13 +732,13 @@ Get plugin stats:: "softirq": 0.0, "steal": 0.0, "system": 11.0, - "total": 56.0, - "user": 1.0}, + "total": 57.0, + "user": 0.0}, {"cpu_number": 1, "dpc": None, "guest": 0.0, "guest_nice": 0.0, - "idle": 57.0, + "idle": 54.0, "interrupt": None, "iowait": 0.0, "irq": 0.0, @@ -749,7 +747,7 @@ Get plugin stats:: "softirq": 0.0, "steal": 0.0, "system": 0.0, - "total": 43.0, + "total": 46.0, "user": 0.0}] Fields descriptions: @@ -781,12 +779,12 @@ Get plugin stats:: # curl http://localhost:61208/api/4/ports [{"description": "DefaultGateway", - "host": "10.62.208.245", + "host": "192.168.1.1", "indice": "port_0", "port": 0, "refresh": 30, "rtt_warning": None, - "status": 0.007788, + "status": 0.007946, "timeout": 3}] Fields descriptions: @@ -803,19 +801,19 @@ Fields descriptions: Get a specific field:: # curl http://localhost:61208/api/4/ports/host - {"host": ["10.62.208.245"]} + {"host": ["192.168.1.1"]} Get a specific item when field matches the given value:: - # curl http://localhost:61208/api/4/ports/host/value/10.62.208.245 - {"10.62.208.245": [{"description": "DefaultGateway", - "host": "10.62.208.245", - "indice": "port_0", - "port": 0, - "refresh": 30, - "rtt_warning": None, - "status": 0.007788, - "timeout": 3}]} + # curl http://localhost:61208/api/4/ports/host/value/192.168.1.1 + {"192.168.1.1": [{"description": "DefaultGateway", + "host": "192.168.1.1", + "indice": "port_0", + "port": 0, + "refresh": 30, + "rtt_warning": None, + "status": 0.007946, + "timeout": 3}]} GET processcount ---------------- @@ -823,7 +821,7 @@ GET processcount Get plugin stats:: # curl http://localhost:61208/api/4/processcount - {"pid_max": 0, "running": 1, "sleeping": 441, "thread": 2369, "total": 592} + {"pid_max": 0, "running": 1, "sleeping": 442, "thread": 2426, "total": 597} Fields descriptions: @@ -836,7 +834,7 @@ Fields descriptions: Get a specific field:: # curl http://localhost:61208/api/4/processcount/total - {"total": 592} + {"total": 597} GET processlist --------------- @@ -846,22 +844,22 @@ Get plugin stats:: # curl http://localhost:61208/api/4/processlist [{"cmdline": ["/sbin/init", "splash"], "cpu_percent": 0.0, - "cpu_times": {"children_system": 290.46, - "children_user": 5148.19, + "cpu_times": {"children_system": 292.72, + "children_user": 5149.74, "iowait": 0.0, - "system": 8.42, - "user": 11.63}, + "system": 9.16, + "user": 13.08}, "gids": {"effective": 0, "real": 0, "saved": 0}, "io_counters": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "key": "pid", "memory_info": {"data": 7282688, "dirty": 0, "lib": 0, - "rss": 14610432, - "shared": 8159232, + "rss": 14585856, + "shared": 8134656, "text": 45056, "vms": 26632192}, - "memory_percent": 0.0889641771412196, + "memory_percent": 0.0888145317633538, "name": "systemd", "nice": 0, "num_threads": 1, @@ -874,7 +872,7 @@ Get plugin stats:: "cpu_times": {"children_system": 0.0, "children_user": 0.0, "iowait": 0.0, - "system": 0.2, + "system": 0.22, "user": 0.0}, "gids": {"effective": 0, "real": 0, "saved": 0}, "io_counters": [0, 0, 0, 0, 0], @@ -920,17 +918,17 @@ Get plugin stats:: [{"childrens": [1, 5172], "cmdline": ["systemd"], "cpu_percent": 0, - "cpu_times": {"children_system": 1579.83, - "children_user": 15259.060000000001, - "system": 11.56, - "user": 31.009999999999998}, + "cpu_times": {"children_system": 1588.9, + "children_user": 15264.5, + "system": 12.5, + "user": 33.54}, "io_counters": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "memory_info": {"data": 10764288, - "rss": 26279936, - "shared": 16666624, + "rss": 26198016, + "shared": 16584704, "text": 90112, "vms": 49463296}, - "memory_percent": 0.16002079073116482, + "memory_percent": 0.15952197280494548, "name": "systemd", "nice": 0, "nprocs": 2, @@ -945,7 +943,7 @@ Get plugin stats:: "cpu_times": {"children_system": 0.0, "children_user": 0.0, "iowait": 0.0, - "system": 0.2, + "system": 0.22, "user": 0.0}, "io_counters": [0, 0, 0, 0, 0], "memory_info": {"data": 0, @@ -995,19 +993,19 @@ GET quicklook Get plugin stats:: # curl http://localhost:61208/api/4/quicklook - {"cpu": 6.1, + {"cpu": 6.6, "cpu_hz": 4475000000.0, - "cpu_hz_current": 740159562.5, + "cpu_hz_current": 654981687.4999999, "cpu_log_core": 16, "cpu_name": "13th Gen Intel(R) Core(TM) i7-13620H", "cpu_phys_core": 10, - "load": 6.1, - "mem": 73.9, + "load": 6.5, + "mem": 77.8, "percpu": [{"cpu_number": 0, "dpc": None, "guest": 0.0, "guest_nice": 0.0, - "idle": 44.0, + "idle": 43.0, "interrupt": None, "iowait": 0.0, "irq": 0.0, @@ -1016,13 +1014,13 @@ Get plugin stats:: "softirq": 0.0, "steal": 0.0, "system": 11.0, - "total": 56.0, - "user": 1.0}, + "total": 57.0, + "user": 0.0}, {"cpu_number": 1, "dpc": None, "guest": 0.0, "guest_nice": 0.0, - "idle": 57.0, + "idle": 54.0, "interrupt": None, "iowait": 0.0, "irq": 0.0, @@ -1031,9 +1029,24 @@ Get plugin stats:: "softirq": 0.0, "steal": 0.0, "system": 0.0, - "total": 43.0, + "total": 46.0, "user": 0.0}, {"cpu_number": 2, + "dpc": None, + "guest": 0.0, + "guest_nice": 0.0, + "idle": 53.0, + "interrupt": None, + "iowait": 0.0, + "irq": 0.0, + "key": "cpu_number", + "nice": 0.0, + "softirq": 0.0, + "steal": 0.0, + "system": 0.0, + "total": 47.0, + "user": 0.0}, + {"cpu_number": 3, "dpc": None, "guest": 0.0, "guest_nice": 0.0, @@ -1045,29 +1058,14 @@ Get plugin stats:: "nice": 0.0, "softirq": 0.0, "steal": 0.0, - "system": 1.0, - "total": 45.0, - "user": 0.0}, - {"cpu_number": 3, - "dpc": None, - "guest": 0.0, - "guest_nice": 0.0, - "idle": 57.0, - "interrupt": None, - "iowait": 0.0, - "irq": 0.0, - "key": "cpu_number", - "nice": 0.0, - "softirq": 0.0, - "steal": 0.0, "system": 0.0, - "total": 43.0, + "total": 45.0, "user": 0.0}, {"cpu_number": 4, "dpc": None, "guest": 0.0, "guest_nice": 0.0, - "idle": 35.0, + "idle": 25.0, "interrupt": None, "iowait": 0.0, "irq": 0.0, @@ -1075,14 +1073,14 @@ Get plugin stats:: "nice": 0.0, "softirq": 0.0, "steal": 0.0, - "system": 17.0, - "total": 65.0, - "user": 2.0}, + "system": 18.0, + "total": 75.0, + "user": 10.0}, {"cpu_number": 5, "dpc": None, "guest": 0.0, "guest_nice": 0.0, - "idle": 57.0, + "idle": 54.0, "interrupt": None, "iowait": 0.0, "irq": 0.0, @@ -1091,13 +1089,13 @@ Get plugin stats:: "softirq": 0.0, "steal": 0.0, "system": 0.0, - "total": 43.0, + "total": 46.0, "user": 0.0}, {"cpu_number": 6, "dpc": None, "guest": 0.0, "guest_nice": 0.0, - "idle": 39.0, + "idle": 41.0, "interrupt": None, "iowait": 2.0, "irq": 0.0, @@ -1105,14 +1103,14 @@ Get plugin stats:: "nice": 0.0, "softirq": 0.0, "steal": 0.0, - "system": 6.0, - "total": 61.0, - "user": 10.0}, + "system": 4.0, + "total": 59.0, + "user": 7.0}, {"cpu_number": 7, "dpc": None, "guest": 0.0, "guest_nice": 0.0, - "idle": 56.0, + "idle": 55.0, "interrupt": None, "iowait": 0.0, "irq": 0.0, @@ -1121,13 +1119,13 @@ Get plugin stats:: "softirq": 0.0, "steal": 0.0, "system": 0.0, - "total": 44.0, + "total": 45.0, "user": 1.0}, {"cpu_number": 8, "dpc": None, "guest": 0.0, "guest_nice": 0.0, - "idle": 55.0, + "idle": 50.0, "interrupt": None, "iowait": 0.0, "irq": 0.0, @@ -1135,14 +1133,14 @@ Get plugin stats:: "nice": 0.0, "softirq": 0.0, "steal": 0.0, - "system": 0.0, - "total": 45.0, + "system": 2.0, + "total": 50.0, "user": 0.0}, {"cpu_number": 9, "dpc": None, "guest": 0.0, "guest_nice": 0.0, - "idle": 57.0, + "idle": 54.0, "interrupt": None, "iowait": 0.0, "irq": 0.0, @@ -1151,9 +1149,24 @@ Get plugin stats:: "softirq": 0.0, "steal": 0.0, "system": 0.0, - "total": 43.0, - "user": 0.0}, + "total": 46.0, + "user": 1.0}, {"cpu_number": 10, + "dpc": None, + "guest": 0.0, + "guest_nice": 0.0, + "idle": 54.0, + "interrupt": None, + "iowait": 0.0, + "irq": 0.0, + "key": "cpu_number", + "nice": 0.0, + "softirq": 0.0, + "steal": 0.0, + "system": 0.0, + "total": 46.0, + "user": 1.0}, + {"cpu_number": 11, "dpc": None, "guest": 0.0, "guest_nice": 0.0, @@ -1167,27 +1180,12 @@ Get plugin stats:: "steal": 0.0, "system": 0.0, "total": 45.0, - "user": 1.0}, - {"cpu_number": 11, - "dpc": None, - "guest": 0.0, - "guest_nice": 0.0, - "idle": 57.0, - "interrupt": None, - "iowait": 0.0, - "irq": 0.0, - "key": "cpu_number", - "nice": 0.0, - "softirq": 0.0, - "steal": 0.0, - "system": 0.0, - "total": 43.0, "user": 0.0}, {"cpu_number": 12, "dpc": None, "guest": 0.0, "guest_nice": 0.0, - "idle": 56.0, + "idle": 54.0, "interrupt": None, "iowait": 0.0, "irq": 0.0, @@ -1196,28 +1194,28 @@ Get plugin stats:: "softirq": 0.0, "steal": 0.0, "system": 0.0, - "total": 44.0, - "user": 1.0}, + "total": 46.0, + "user": 0.0}, {"cpu_number": 13, "dpc": None, "guest": 0.0, "guest_nice": 0.0, - "idle": 56.0, + "idle": 53.0, "interrupt": None, - "iowait": 0.0, + "iowait": 1.0, "irq": 0.0, "key": "cpu_number", "nice": 0.0, "softirq": 0.0, "steal": 0.0, - "system": 1.0, - "total": 44.0, + "system": 0.0, + "total": 47.0, "user": 1.0}, {"cpu_number": 14, "dpc": None, "guest": 0.0, "guest_nice": 0.0, - "idle": 56.0, + "idle": 54.0, "interrupt": None, "iowait": 0.0, "irq": 0.0, @@ -1226,13 +1224,13 @@ Get plugin stats:: "softirq": 0.0, "steal": 0.0, "system": 0.0, - "total": 44.0, + "total": 46.0, "user": 1.0}, {"cpu_number": 15, "dpc": None, "guest": 0.0, "guest_nice": 0.0, - "idle": 57.0, + "idle": 54.0, "interrupt": None, "iowait": 0.0, "irq": 0.0, @@ -1241,9 +1239,9 @@ Get plugin stats:: "softirq": 0.0, "steal": 0.0, "system": 0.0, - "total": 43.0, + "total": 46.0, "user": 1.0}], - "swap": 90.5} + "swap": 100.0} Fields descriptions: @@ -1281,14 +1279,14 @@ Get plugin stats:: "label": "Ambient", "type": "temperature_core", "unit": "C", - "value": 28, + "value": 34, "warning": 0}, {"critical": None, "key": "label", "label": "Ambient 3", "type": "temperature_core", "unit": "C", - "value": 24, + "value": 29, "warning": 0}] Fields descriptions: @@ -1351,7 +1349,7 @@ Get a specific item when field matches the given value:: "label": "Ambient", "type": "temperature_core", "unit": "C", - "value": 28, + "value": 34, "warning": 0}]} GET smart @@ -1395,7 +1393,7 @@ GET uptime Get plugin stats:: # curl http://localhost:61208/api/4/uptime - "6 days, 16:25:35" + "6 days, 22:46:22" GET version ----------- @@ -1440,8 +1438,8 @@ Get plugin stats:: # curl http://localhost:61208/api/4/wifi [{"key": "ssid", - "quality_level": -45.0, - "quality_link": 65.0, + "quality_level": -62.0, + "quality_link": 48.0, "ssid": "wlp0s20f3"}] Get a specific field:: @@ -1453,8 +1451,8 @@ Get a specific item when field matches the given value:: # curl http://localhost:61208/api/4/wifi/ssid/value/wlp0s20f3 {"wlp0s20f3": [{"key": "ssid", - "quality_level": -45.0, - "quality_link": 65.0, + "quality_level": -62.0, + "quality_link": 48.0, "ssid": "wlp0s20f3"}]} GET all stats @@ -1518,34 +1516,34 @@ GET stats history History of a plugin:: # curl http://localhost:61208/api/4/cpu/history - {"system": [["2026-01-03T07:51:20.098856+00:00", 3.0], - ["2026-01-03T07:51:21.202435+00:00", 1.0], - ["2026-01-03T07:51:22.255718+00:00", 1.0]], - "user": [["2026-01-03T07:51:20.098853+00:00", 3.4], - ["2026-01-03T07:51:21.202432+00:00", 1.1], - ["2026-01-03T07:51:22.255716+00:00", 1.1]]} + {"system": [["2026-01-03T14:12:08.389170+00:00", 2.9], + ["2026-01-03T14:12:09.494051+00:00", 1.1], + ["2026-01-03T14:12:10.540637+00:00", 1.1]], + "user": [["2026-01-03T14:12:08.389165+00:00", 3.7], + ["2026-01-03T14:12:09.494048+00:00", 1.3], + ["2026-01-03T14:12:10.540632+00:00", 1.3]]} Limit history to last 2 values:: # curl http://localhost:61208/api/4/cpu/history/2 - {"system": [["2026-01-03T07:51:21.202435+00:00", 1.0], - ["2026-01-03T07:51:22.255718+00:00", 1.0]], - "user": [["2026-01-03T07:51:21.202432+00:00", 1.1], - ["2026-01-03T07:51:22.255716+00:00", 1.1]]} + {"system": [["2026-01-03T14:12:09.494051+00:00", 1.1], + ["2026-01-03T14:12:10.540637+00:00", 1.1]], + "user": [["2026-01-03T14:12:09.494048+00:00", 1.3], + ["2026-01-03T14:12:10.540632+00:00", 1.3]]} History for a specific field:: # curl http://localhost:61208/api/4/cpu/system/history - {"system": [["2026-01-03T07:51:18.831780+00:00", 3.0], - ["2026-01-03T07:51:20.098856+00:00", 3.0], - ["2026-01-03T07:51:21.202435+00:00", 1.0], - ["2026-01-03T07:51:22.255718+00:00", 1.0]]} + {"system": [["2026-01-03T14:12:07.138062+00:00", 2.9], + ["2026-01-03T14:12:08.389170+00:00", 2.9], + ["2026-01-03T14:12:09.494051+00:00", 1.1], + ["2026-01-03T14:12:10.540637+00:00", 1.1]]} Limit history for a specific field to last 2 values:: # curl http://localhost:61208/api/4/cpu/system/history - {"system": [["2026-01-03T07:51:21.202435+00:00", 1.0], - ["2026-01-03T07:51:22.255718+00:00", 1.0]]} + {"system": [["2026-01-03T14:12:09.494051+00:00", 1.1], + ["2026-01-03T14:12:10.540637+00:00", 1.1]]} GET limits (used for thresholds) -------------------------------- @@ -1595,8 +1593,7 @@ All limits/thresholds:: "diskio_tx_latency_warning": 20.0, "history_size": 1200.0}, "folders": {"folders_disable": ["False"], "history_size": 1200.0}, - "fs": {"fs_alias": ["/:Root", "/zfspool:ZFS"], - "fs_careful": 50.0, + "fs": {"fs_careful": 50.0, "fs_critical": 90.0, "fs_disable": ["False"], "fs_hide": ["/boot.*", ".*/snap.*"], diff --git a/docs/faq.rst b/docs/faq.rst index 69e287ad..69f7deaf 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -28,6 +28,8 @@ Now, Glances uses Netifaces2. Please uninstall Netifaces and install Netifaces2 instead. +Extra note: Glances 4.5 or higher do not use Netifaces/Netifaces2 anymore. + On Debian/Ubuntu Operating Systems, Webserver display a blank screen ? ---------------------------------------------------------------------- diff --git a/glances/globals.py b/glances/globals.py index 4befb953..d29e8b19 100644 --- a/glances/globals.py +++ b/glances/globals.py @@ -22,6 +22,7 @@ import os import platform import queue import re +import socket import subprocess import sys import weakref @@ -35,6 +36,8 @@ from urllib.error import HTTPError, URLError from urllib.parse import urlparse from urllib.request import Request, urlopen +import psutil + # Prefer faster libs for JSON (de)serialization # Preference Order: orjson > ujson > json (builtin) try: @@ -712,3 +715,60 @@ def split_esc(input_string, sep=None, maxsplit=-1, esc='\\'): ret = [sub for sub in ret if len(sub) > 0] return ret + + +def get_ip_address(ipv6=False): + """Get current IP address and netmask as a tuple.""" + family = socket.AF_INET6 if ipv6 else socket.AF_INET + + # Get IP address + stats = psutil.net_if_stats() + addrs = psutil.net_if_addrs() + + ip_address = None + ip_netmask = None + for interface, stat in stats.items(): + if stat.isup and interface != 'lo': + if interface in addrs: + for addr in addrs[interface]: + if addr.family == family: + ip_address = addr.address + ip_netmask = addr.netmask + break + + return ip_address, ip_netmask + + +def get_default_gateway(ipv6=False): + """Get the default gateway IP address.""" + + def convert_ipv4(gateway_hex): + """Convert IPv4 hex (little-endian) to dotted notation.""" + return '.'.join(str(int(gateway_hex[i : i + 2], 16)) for i in range(6, -1, -2)) + + def convert_ipv6(gateway_hex): + """Convert IPv6 hex to colon notation.""" + return ':'.join(gateway_hex[i : i + 4] for i in range(0, 32, 4)) + + if ipv6: + route_file = '/proc/net/ipv6_route' + default_dest = '00000000000000000000000000000000' + dest_field = 0 + gateway_field = 4 + converter = convert_ipv6 + else: + route_file = '/proc/net/route' + default_dest = '00000000' + dest_field = 1 + gateway_field = 2 + converter = convert_ipv4 + + try: + with open(route_file) as f: + for line in f: + fields = line.strip().split() + if fields[dest_field] == default_dest: + return converter(fields[gateway_field]) + except (FileNotFoundError, IndexError, ValueError): + return None + return None diff --git a/glances/plugins/ip/__init__.py b/glances/plugins/ip/__init__.py index 746d8463..05ba67e6 100644 --- a/glances/plugins/ip/__init__.py +++ b/glances/plugins/ip/__init__.py @@ -10,29 +10,11 @@ import threading -from glances.globals import json_loads, queue, urlopen_auth +from glances.globals import get_ip_address, json_loads, queue, urlopen_auth from glances.logger import logger from glances.plugins.plugin.model import GlancesPluginModel from glances.timer import Timer, getTimeSinceLastUpdate -# Import plugin specific dependency -try: - import netifaces -except ImportError as e: - netifaces_tag = True - logger.warning(f"Missing Python Lib ({e}), IP plugin is disabled") -else: - netifaces_tag = False - -try: - netifaces.default_gateway() -except Exception: - netifaces_tag = True - logger.warning("Netifaces2 should be installed in your Python environment, IP plugin is disabled") -else: - netifaces_tag = False - - # Fields description # description: human readable description # short_name: shortname to use un UI @@ -94,31 +76,9 @@ class IpPlugin(GlancesPluginModel): "public_refresh_interval", default=self._default_public_refresh_interval ) - def get_default_gateway(self): - # Get the default gateway thanks to the netifaces lib - # Return a tupple with: ('192.168.1.1', 'wlp0s20f3') - try: - default_gw = netifaces.default_gateway()[netifaces.AF_INET] - except (KeyError, AttributeError) as e: - logger.debug(f"Cannot grab default gateway IP address ({e})") - return None - return default_gw - def get_first_ip(self, stats): - default_gateway = self.get_default_gateway() - try: - if not default_gateway: - default_interface = netifaces.interfaces_by_index()[netifaces.AF_INET] - else: - default_interface = default_gateway[1] - address = netifaces.ifaddresses(default_interface)[netifaces.AF_INET][0]['addr'] - mask = netifaces.ifaddresses(default_interface)[netifaces.AF_INET][0]['mask'] - except (KeyError, AttributeError) as e: - logger.debug(f"Cannot grab private IP address ({e})") - else: - stats['address'] = address - stats['mask'] = mask - stats['mask_cidr'] = self.ip_to_cidr(mask) + stats['address'], stats['mask'] = get_ip_address() + stats['mask_cidr'] = self.ip_to_cidr(stats['mask']) return stats @@ -150,7 +110,7 @@ class IpPlugin(GlancesPluginModel): # Init new stats stats = self.get_init_value() - if self.input_method == 'local' and not netifaces_tag: + if self.input_method == 'local': stats = self.get_stats_for_local_input(stats) elif self.input_method == 'snmp': @@ -178,7 +138,7 @@ class IpPlugin(GlancesPluginModel): ret = [] # Only process if stats exist and display plugin enable... - if not self.stats or self.is_disabled() or netifaces_tag: + if not self.stats or self.is_disabled(): return ret # Start with the private IP information diff --git a/glances/ports_list.py b/glances/ports_list.py index 8a92224c..c4d20964 100644 --- a/glances/ports_list.py +++ b/glances/ports_list.py @@ -8,17 +8,9 @@ """Manage the Glances ports list (Ports plugin).""" +from glances.globals import get_default_gateway from glances.logger import logger -try: - import netifaces - - netifaces.default_gateway() - netifaces_tag = True -except (ImportError, NameError): - logger.warning("Ports plugin - Can not init Netifaces2 lib, port_default_gateway feature is disabled") - netifaces_tag = False - class GlancesPortsList: """Manage the ports list for the ports plugin.""" @@ -49,13 +41,10 @@ class GlancesPortsList: # Add default gateway on top of the ports_list lists default_gateway = config.get_value(self._section, 'port_default_gateway', default='False') - if default_gateway.lower().startswith('true') and netifaces_tag: + if default_gateway.lower().startswith('true'): new_port = {} - try: - new_port['host'] = netifaces.default_gateway()[netifaces.AF_INET][0] - except (KeyError, NameError): - new_port['host'] = None # ICMP + new_port['host'] = get_default_gateway() new_port['port'] = 0 new_port['description'] = 'DefaultGateway' new_port['refresh'] = refresh diff --git a/glances/servers_list_dynamic.py b/glances/servers_list_dynamic.py index e7619696..63a83dc5 100644 --- a/glances/servers_list_dynamic.py +++ b/glances/servers_list_dynamic.py @@ -11,26 +11,9 @@ import socket import sys -from glances.globals import BSD +from glances.globals import get_ip_address from glances.logger import logger -try: - import netifaces - - netifaces_tag = True -except ImportError: - logger.warning("Servers list - Netifaces2 lib not found, active IP address not possible") - netifaces_tag = False - -try: - netifaces.gateways() -except Exception: - netifaces_tag = True -else: - logger.warning("Servers list - Netifaces2 do not support gateways() method, active IP address not possible") - netifaces_tag = False - - try: from zeroconf import ServiceBrowser, ServiceInfo, Zeroconf from zeroconf import __version__ as __zeroconf_version @@ -204,17 +187,8 @@ class GlancesAutoDiscoverClient: except OSError as e: logger.error(f"Cannot start zeroconf: {e}") - # XXX *BSDs: Segmentation fault (core dumped) - # -- https://bitbucket.org/al45tair/netifaces/issues/15 - if not BSD: - try: - # -B @ overwrite the dynamic IPv4 choice - if netifaces_tag and zeroconf_bind_address == '0.0.0.0': - zeroconf_bind_address = self.find_active_ip_address() - except Exception: - # Issue #528 (no network interface available) - # Issue #3219 (no implementation for gateway()) - pass + if zeroconf_bind_address == '0.0.0.0': + zeroconf_bind_address = get_ip_address()[0] # Ensure zeroconf_bind_address is an IP address not an host zeroconf_bind_address = socket.gethostbyname(zeroconf_bind_address) @@ -256,14 +230,6 @@ class GlancesAutoDiscoverClient: else: logger.error("Cannot announce Glances server on the network: zeroconf library not found.") - @staticmethod - def find_active_ip_address(): - """Try to find the active IP addresses.""" - # Interface of the default gateway - gateway_itf = netifaces.gateways()[netifaces.AF_INET][0][1] - # IP address for the interface - return netifaces.ifaddresses(gateway_itf)[netifaces.AF_INET][0]['addr'] - def close(self): if zeroconf_tag: self.zeroconf.unregister_service(self.info) diff --git a/pyproject.toml b/pyproject.toml index 5e702e7a..79e65048 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -95,9 +95,6 @@ export = [ ] gpu = ["nvidia-ml-py"] graph = ["pygal"] -ip = [ - "netifaces2", -] raid = ["pymdstat"] sensors = ["batinfo; platform_system == 'Linux'"] smart = ["pySMART"]