diff --git a/README.rst b/README.rst index 2bd78edc..d4d554ec 100644 --- a/README.rst +++ b/README.rst @@ -196,11 +196,11 @@ use the following code: 'system': 5.4, 'total': 7.3, 'user': 3.0} - >>> gl.cpu["total"] + >>> gl.cpu.get("total") 7.3 - >>> gl.mem["used"] + >>> gl.mem.get("used") 12498582144 - >>> gl.auto_unit(gl.mem["used"]) + >>> gl.auto_unit(gl.mem.get("used")) 11.6G If the stats return a list of items (like network interfaces or processes), you can @@ -210,7 +210,7 @@ access them by their name: >>> gl.network.keys() ['wlp0s20f3', 'veth33b370c', 'veth19c7711'] - >>> gl.network["wlp0s20f3"] + >>> gl.network.get("wlp0s20f3") {'alias': None, 'bytes_all': 362, 'bytes_all_gauge': 9242285709, diff --git a/docs/api/python.rst b/docs/api/python.rst index a710918a..398e5bb9 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': 535006181, + 'ctx_switches': 9270037, 'guest': 0.0, - 'idle': 93.6, - 'interrupts': 380648409, - 'iowait': 0.5, + 'idle': 92.9, + 'interrupts': 6399251, + 'iowait': 0.2, 'irq': 0.0, 'nice': 0.0, - 'soft_interrupts': 132081953, + 'soft_interrupts': 2465459, 'steal': 0.0, 'syscalls': 0, - 'system': 4.3, - 'total': 6.2, - 'user': 1.7} - >>> gl.cpu["total"] - 6.2 - >>> gl.mem["used"] - 12873501848 - >>> gl.auto_unit(gl.mem["used"]) - 12.0G + 'system': 4.5, + 'total': 6.6, + 'user': 2.3} + >>> gl.cpu.get("total") + 6.6 + >>> gl.mem.get("used") + 9278827984 + >>> gl.auto_unit(gl.mem.get("used")) + 8.64G 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': 0, - 'bytes_all_gauge': 1422410128, - 'bytes_all_rate_per_sec': 0.0, - 'bytes_recv': 0, - 'bytes_recv_gauge': 998664612, - 'bytes_recv_rate_per_sec': 0.0, - 'bytes_sent': 0, - 'bytes_sent_gauge': 423745516, - 'bytes_sent_rate_per_sec': 0.0, + 'bytes_all': 2046, + 'bytes_all_gauge': 1072158728, + 'bytes_all_rate_per_sec': 11750.0, + 'bytes_recv': 1424, + 'bytes_recv_gauge': 1055691424, + 'bytes_recv_rate_per_sec': 8178.0, + 'bytes_sent': 622, + 'bytes_sent_gauge': 16467304, + 'bytes_sent_rate_per_sec': 3572.0, 'interface_name': 'wlp0s20f3', 'key': 'interface_name', 'speed': 0, - 'time_since_update': 0.14729881286621094} + 'time_since_update': 0.1741182804107666} Init Glances Python API ----------------------- @@ -95,32 +95,7 @@ Alert stats: >>> type(gl.alert) >>> gl.alert - [{'avg': 94.8653648999833, - 'begin': 1763286833, - 'count': 2, - 'desc': '', - 'end': -1, - 'global_msg': 'High swap (paging) usage', - 'max': 94.8654125837446, - 'min': 94.86531721622201, - 'sort': 'memory_percent', - 'state': 'CRITICAL', - 'sum': 189.7307297999666, - 'top': ['code', 'code', 'code'], - 'type': 'MEMSWAP'}, - {'avg': 78.36805228965103, - 'begin': 1763286833, - 'count': 2, - 'desc': '', - 'end': -1, - 'global_msg': 'High swap (paging) usage', - 'max': 78.38760588895987, - 'min': 78.3484986903422, - 'sort': 'memory_percent', - 'state': 'WARNING', - 'sum': 156.73610457930207, - 'top': [], - 'type': 'MEM'}] + [] Alert fields description: @@ -161,7 +136,7 @@ Ports stats: 'port': 0, 'refresh': 30, 'rtt_warning': None, - 'status': 0.005299, + 'status': 0.005353, 'timeout': 3}] Ports fields description: @@ -199,17 +174,17 @@ Diskio stats: Return a dict of dict with key= >>> gl.diskio.keys() ['nvme0n1', 'nvme0n1p1', 'nvme0n1p2', 'nvme0n1p3', 'dm-0', 'dm-1'] - >>> gl.diskio["nvme0n1"] + >>> gl.diskio.get("nvme0n1") {'disk_name': 'nvme0n1', 'key': 'disk_name', - 'read_bytes': 12468341248, - 'read_count': 602636, + 'read_bytes': 6307091968, + 'read_count': 212136, 'read_latency': 0, - 'read_time': 194714, - 'write_bytes': 26341803008, - 'write_count': 2629337, + 'read_time': 25497, + 'write_bytes': 5472228352, + 'write_count': 237246, 'write_latency': 0, - 'write_time': 2265062} + 'write_time': 197091} Diskio fields description: @@ -294,11 +269,11 @@ Processcount stats: >>> type(gl.processcount) >>> gl.processcount - {'pid_max': 0, 'running': 1, 'sleeping': 419, 'thread': 2236, 'total': 565} + {'pid_max': 0, 'running': 1, 'sleeping': 406, 'thread': 1964, 'total': 559} >>> gl.processcount.keys() ['total', 'running', 'sleeping', 'thread', 'pid_max'] - >>> gl.processcount["total"] - 565 + >>> gl.processcount.get("total") + 559 Processcount fields description: @@ -366,12 +341,12 @@ Percpu stats: Return a dict of dict with key= >>> gl.percpu.keys() [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] - >>> gl.percpu["0"] + >>> gl.percpu.get("0") {'cpu_number': 0, 'dpc': None, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 23.0, + 'idle': 28.0, 'interrupt': None, 'iowait': 0.0, 'irq': 0.0, @@ -379,8 +354,8 @@ Percpu stats: 'nice': 0.0, 'softirq': 0.0, 'steal': 0.0, - 'system': 10.0, - 'total': 77.0, + 'system': 4.0, + 'total': 72.0, 'user': 0.0} Percpu fields description: @@ -436,7 +411,7 @@ System stats: 'platform': '64bit'} >>> gl.system.keys() ['os_name', 'hostname', 'platform', 'os_version', 'linux_distro', 'hr_name'] - >>> gl.system["os_name"] + >>> gl.system.get("os_name") 'Linux' System fields description: @@ -468,21 +443,21 @@ Network stats: Return a dict of dict with key= >>> gl.network.keys() ['wlp0s20f3'] - >>> gl.network["wlp0s20f3"] + >>> gl.network.get("wlp0s20f3") {'alias': None, 'bytes_all': 0, - 'bytes_all_gauge': 1422410128, + 'bytes_all_gauge': 1072158728, 'bytes_all_rate_per_sec': 0.0, 'bytes_recv': 0, - 'bytes_recv_gauge': 998664612, + 'bytes_recv_gauge': 1055691424, 'bytes_recv_rate_per_sec': 0.0, 'bytes_sent': 0, - 'bytes_sent_gauge': 423745516, + 'bytes_sent_gauge': 16467304, 'bytes_sent_rate_per_sec': 0.0, 'interface_name': 'wlp0s20f3', 'key': 'interface_name', 'speed': 0, - 'time_since_update': 0.0027916431427001953} + 'time_since_update': 0.0031774044036865234} Network fields description: @@ -523,23 +498,23 @@ Cpu stats: >>> gl.cpu {'cpucore': 16, - 'ctx_switches': 535006181, + 'ctx_switches': 9270037, 'guest': 0.0, - 'idle': 93.6, - 'interrupts': 380648409, - 'iowait': 0.5, + 'idle': 92.9, + 'interrupts': 6399251, + 'iowait': 0.2, 'irq': 0.0, 'nice': 0.0, - 'soft_interrupts': 132081953, + 'soft_interrupts': 2465459, 'steal': 0.0, 'syscalls': 0, - 'system': 4.3, - 'total': 6.2, - 'user': 1.7} + 'system': 4.5, + 'total': 6.6, + 'user': 2.3} >>> gl.cpu.keys() ['total', 'user', 'nice', 'system', 'idle', 'iowait', 'irq', 'steal', 'guest', 'ctx_switches', 'interrupts', 'soft_interrupts', 'syscalls', 'cpucore'] - >>> gl.cpu["total"] - 6.2 + >>> gl.cpu.get("total") + 6.6 Cpu fields description: @@ -602,7 +577,7 @@ Amps stats: Return a dict of dict with key= >>> gl.amps.keys() ['Dropbox', 'Python', 'Conntrack', 'Nginx', 'Systemd', 'SystemV'] - >>> gl.amps["Dropbox"] + >>> gl.amps.get("Dropbox") {'count': 0, 'countmax': None, 'countmin': 1.0, @@ -611,7 +586,7 @@ Amps stats: 'refresh': 3.0, 'regex': True, 'result': None, - 'timer': 0.18408846855163574} + 'timer': 0.1661975383758545} Amps fields description: @@ -642,168 +617,37 @@ Processlist stats: >>> gl.processlist Return a dict of dict with key= >>> gl.processlist.keys() - [14491, 15217, 14405, 6591, 7144, 7916, 7821, 15970, 7719, 206241, 65967, 7715, 7730, 11980, 14625, 5458, 3065, 6882, 16024, 206256, 206240, 5866, 206273, 14503, 14287, 519417, 206265, 208329, 9851, 15058, 14443, 625522, 629000, 14504, 626107, 627383, 628762, 554747, 82833, 15628, 15050, 15056, 6893, 6047, 127391, 6406, 14824, 7536, 628997, 22334, 15022, 15887, 6861, 5881, 5706, 2656, 3684, 6034, 6442, 739, 14358, 5579, 6856, 5811, 6418, 5938, 127406, 15054, 5592, 6061, 8517, 15057, 5627, 6093, 5625, 5571, 2763, 3080, 5739, 3683, 5395, 1, 74748, 5655, 6440, 14290, 2694, 2682, 5293, 5597, 5620, 5783, 2686, 5127, 14289, 5149, 2629, 6027, 3069, 3120, 6330, 2483, 5600, 6934, 5151, 5688, 3048, 2640, 3721, 5630, 5102, 5643, 23869, 3030, 2764, 5152, 3690, 188085, 5594, 2678, 5991, 12575, 3762, 2914, 5647, 12566, 5845, 5146, 2924, 2484, 2661, 5602, 2679, 2624, 5216, 2634, 2482, 5382, 5165, 5645, 5893, 5441, 5552, 801, 5884, 5759, 5854, 5719, 5959, 5731, 5900, 5393, 5595, 5635, 2670, 5363, 5641, 5279, 5220, 5862, 9860, 2623, 6255, 2648, 263958, 11482, 5580, 5367, 2815, 602027, 554330, 5454, 5147, 2622, 2481, 2628, 263959, 6448, 3856, 2505, 14957, 2665, 628993, 3692, 3726, 5134, 3709, 6682, 5227, 3701, 3694, 14304, 3281, 585939, 628996, 602177, 263629, 263636, 2503, 2761, 3282, 263988, 14626, 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, 129, 133, 135, 136, 137, 138, 139, 141, 143, 144, 145, 146, 147, 148, 149, 151, 153, 155, 156, 157, 165, 176, 185, 186, 212, 230, 266, 267, 268, 269, 270, 271, 272, 273, 274, 276, 277, 356, 357, 359, 360, 361, 362, 366, 443, 444, 607, 612, 613, 614, 620, 674, 675, 770, 771, 806, 994, 1023, 1031, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1070, 1096, 1097, 1098, 1099, 1105, 1218, 1223, 1252, 1341, 1348, 1394, 1395, 1877, 1878, 1879, 1880, 1881, 1882, 1883, 1884, 1885, 1886, 1887, 1888, 1889, 1890, 1918, 1920, 1921, 1922, 1923, 1924, 1925, 1926, 1927, 1933, 1959, 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2023, 2024, 2029, 2030, 2031, 2032, 2033, 2034, 2035, 2036, 2037, 2038, 2039, 2041, 2042, 2043, 2044, 2046, 2047, 2050, 2051, 3636, 3637, 3638, 3639, 3729, 3792, 3793, 3794, 3795, 3796, 3797, 3798, 3799, 4014, 23612, 551209, 554173, 563763, 564799, 572071, 575338, 577707, 578926, 580233, 582044, 587172, 593022, 597504, 599102, 599105, 603415, 603908, 605802, 609572, 611270, 612096, 614758, 615030, 615031, 615032, 615638, 617933, 617977, 617978, 618247, 618729, 619988, 621702, 621934, 621968, 622028, 622059, 622060, 622061, 622099, 622516, 622694, 623253, 623921, 624040, 624094, 624529, 624563, 624587, 624841, 624989, 625001, 627881, 628116, 628509, 628511, 628513, 629042] - >>> gl.processlist["14491"] - {'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=14304', - '--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,7369772581480644079,13259302147474375396,262144', - '--enable-features=DocumentPolicyIncludeJSCallStacksInCrashReports,EarlyEstablishGpuChannel,EstablishGpuChannelAsync', - '--disable-features=CalculateNativeWinOcclusion,FontationsLinuxSystemFonts,ScreenAIOCREnabled,SpareRendererForSitePerProcess', - '--variations-seed-version'], - 'cpu_percent': 0.0, - 'cpu_times': {'children_system': 3569.28, - 'children_user': 2647.23, + [30532, 129, 7722, 6446, 8756, 8852, 6423, 8840, 9543, 7548, 10383, 5247, 10239, 6971, 7838, 7562, 7550, 10672, 7715, 8639, 6711, 10143, 29150, 8081, 8853, 9153, 8794, 3018, 6207, 9171, 9629, 3613, 9374, 8333, 6244, 6219, 8711, 30172, 28756, 29409, 5453, 29262, 5991, 5363, 9409, 9408, 7371, 9406, 9407, 9402, 5677, 8641, 8642, 3031, 2669, 29063, 5812, 6722, 5815, 30529, 6689, 5605, 6684, 8156, 6124, 5724, 5575, 5375, 5826, 5878, 6763, 3025, 6242, 5409, 5412, 5355, 4271, 3609, 5386, 5437, 2776, 5394, 5189, 749, 4946, 2700, 5087, 2641, 1, 2704, 2703, 5627, 5803, 3087, 4924, 4943, 4948, 3495, 2509, 2649, 5388, 5381, 3621, 5429, 3004, 5418, 2858, 5479, 6050, 3596, 2797, 4904, 4950, 5435, 2974, 3685, 5634, 3496, 5783, 2688, 5432, 5462, 808, 5389, 5678, 2684, 2510, 2864, 2690, 2645, 5175, 2508, 5009, 5661, 5574, 5738, 5336, 5230, 2636, 5653, 5584, 5643, 5186, 5383, 5157, 8342, 2685, 4961, 5427, 5690, 2655, 5013, 5073, 2635, 5428, 5367, 8469, 4944, 2746, 9198, 9154, 5161, 2710, 5243, 2634, 2507, 4931, 2640, 3778, 6250, 8656, 6540, 30525, 2979, 2981, 3626, 3634, 3234, 3650, 5020, 3633, 3629, 3501, 30528, 2980, 2769, 3016, 3017, 3235, 3500, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 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, 106, 107, 108, 109, 110, 111, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 157, 164, 165, 166, 168, 169, 171, 176, 186, 188, 203, 212, 216, 218, 264, 270, 271, 272, 273, 274, 275, 276, 277, 278, 352, 355, 357, 358, 359, 360, 361, 362, 363, 364, 367, 369, 370, 447, 448, 450, 611, 616, 617, 618, 624, 651, 652, 653, 654, 657, 658, 659, 660, 661, 662, 683, 684, 738, 780, 781, 817, 1000, 1001, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, 1025, 1026, 1027, 1028, 1255, 1303, 1366, 1369, 1370, 1371, 1387, 1388, 1389, 1390, 1439, 1440, 1443, 1444, 1525, 1529, 1896, 1897, 1898, 1899, 1900, 1901, 1902, 1903, 1904, 1905, 1906, 1907, 1908, 1909, 1938, 1939, 1941, 1942, 1943, 1944, 1945, 1946, 1947, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, 2032, 2044, 2045, 2050, 2051, 2052, 2053, 2054, 2055, 2056, 2057, 2058, 2059, 2061, 2063, 2064, 2066, 2068, 2071, 2072, 2075, 2322, 2323, 2326, 3558, 3559, 3560, 3561, 3562, 3660, 3706, 3707, 3708, 3709, 3710, 3711, 3712, 3713, 3949, 3956, 4080, 4725, 4859, 4877, 7686, 13970, 14398, 14514, 15908, 16227, 16410, 16721, 28674, 28676, 28726, 29096, 30133] + >>> gl.processlist.get("30532") + {'cmdline': ['/home/nicolargo/dev/glances/.venv/bin/python3', + '-m', + 'glances', + '-C', + 'conf/glances.conf', + '--api-doc'], + 'cpu_percent': 75.1, + 'cpu_times': {'children_system': 0.03, + 'children_user': 0.01, 'iowait': 0.0, - 'system': 1286.96, - 'user': 7559.57}, + 'system': 0.4, + 'user': 0.4}, 'gids': {'effective': 1000, 'real': 1000, 'saved': 1000}, - 'io_counters': [1442849792, - 2364071936, - 1442849792, - 2364071936, - 1, - 200706048, - 450560, - 200706048, - 450560, - 1, - 122423296, - 311296, - 122423296, - 311296, - 1, - 9239552, - 8192, - 9239552, - 8192, - 1, - 52189184, - 0, - 52189184, - 0, - 1, - 191697920, - 0, - 191697920, - 0, - 1, - 7135232, - 0, - 7135232, - 0, - 1, - 2829312, - 8192, - 2829312, - 8192, - 1, - 9852928, - 0, - 9852928, - 0, - 1, - 44275712, - 458461184, - 44275712, - 458461184, - 1, - 118339584, - 132268032, - 118339584, - 132268032, - 1, - 55313408, - 5238784, - 55313408, - 5238784, - 1, - 274432, - 0, - 274432, - 0, - 1, - 4116480, - 0, - 4116480, - 0, - 1, - 42649600, - 0, - 42649600, - 0, - 1, - 35771392, - 0, - 35771392, - 0, - 1, - 16037888, - 0, - 16037888, - 0, - 1, - 2330624, - 0, - 2330624, - 0, - 1, - 7868416, - 0, - 7868416, - 0, - 1, - 17367040, - 0, - 17367040, - 0, - 1, - 8646656, - 11378688, - 8646656, - 11378688, - 1, - 1232896, - 0, - 1232896, - 0, - 1, - 1406976, - 0, - 1406976, - 0, - 1], + 'io_counters': [20688896, 86016, 8990720, 86016, 1], 'key': 'pid', - 'memory_info': {'data': 6884929536, + 'memory_info': {'data': 100184064, 'dirty': 0, 'lib': 0, - 'rss': 3534999552, - 'shared': 55246848, - 'text': 148733952, - 'vms': 1526390317056}, - 'memory_percent': 21.524846539162567, - 'name': 'code', + 'rss': 81117184, + 'shared': 18477056, + 'text': 31211520, + 'vms': 415424512}, + 'memory_percent': 0.49392852502078194, + 'name': 'python3', 'nice': 0, - 'num_threads': 90, - 'pid': 14491, - 'status': 'S', - 'time_since_update': 0.44155144691467285, + 'num_threads': 3, + 'pid': 30532, + 'status': 'R', + 'time_since_update': 0.45221495628356934, 'username': 'nicolargo'} Processlist fields description: @@ -887,11 +731,14 @@ Load stats: >>> type(gl.load) >>> gl.load - {'cpucore': 16, 'min1': 0.939453125, 'min15': 0.669921875, 'min5': 0.744140625} + {'cpucore': 16, + 'min1': 1.77197265625, + 'min15': 0.69287109375, + 'min5': 1.29052734375} >>> gl.load.keys() ['min1', 'min5', 'min15', 'cpucore'] - >>> gl.load["min1"] - 0.939453125 + >>> gl.load.get("min1") + 1.77197265625 Load fields description: @@ -924,13 +771,13 @@ Sensors stats: Return a dict of dict with key=