From 8d4a20a6a843e1e35b5324bc83be422fbed04b87 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sat, 15 Jan 2022 11:33:14 +0100 Subject: [PATCH 1/5] Web server status check endpoint #1988 --- docs/api.rst | 832 +++++++++++------------ docs/man/glances.1 | 4 +- glances/outputs/glances_bottle.py | 18 +- glances/outputs/glances_stdout_apidoc.py | 39 +- 4 files changed, 446 insertions(+), 447 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index d5bbae5f..8523e68f 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -55,14 +55,14 @@ GET alert Get plugin stats:: # curl http://localhost:61208/api/3/alert - [[1638092725.0, + [[1642242165.0, -1, 'WARNING', 'MEM', - 82.03056466616047, - 82.03056466616047, - 82.03056466616047, - 82.03056466616047, + 82.75770835453343, + 82.75770835453343, + 82.75770835453343, + 82.75770835453343, 1, [], '', @@ -82,7 +82,7 @@ Get plugin stats:: 'refresh': 3.0, 'regex': True, 'result': None, - 'timer': 0.18709087371826172}, + 'timer': 0.20821332931518555}, {'count': 0, 'countmax': 20.0, 'countmin': None, @@ -91,7 +91,7 @@ Get plugin stats:: 'refresh': 3.0, 'regex': True, 'result': None, - 'timer': 0.18697094917297363}] + 'timer': 0.20801949501037598}] Get a specific field:: @@ -109,7 +109,7 @@ Get a specific item when field matchs the given value:: 'refresh': 3.0, 'regex': True, 'result': None, - 'timer': 0.18709087371826172}]} + 'timer': 0.20821332931518555}]} GET core -------- @@ -139,19 +139,19 @@ Get plugin stats:: 'ctx_switches': 0, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 70.5, + 'idle': 70.4, 'interrupts': 0, - 'iowait': 0.3, + 'iowait': 0.2, 'irq': 0.0, 'nice': 0.0, 'soft_interrupts': 0, - 'softirq': 1.0, + 'softirq': 1.7, 'steal': 0.0, 'syscalls': 0, - 'system': 5.3, + 'system': 4.4, 'time_since_update': 1, - 'total': 29.4, - 'user': 22.9} + 'total': 29.5, + 'user': 23.3} Fields descriptions: @@ -173,7 +173,7 @@ Fields descriptions: Get a specific field:: # curl http://localhost:61208/api/3/cpu/total - {'total': 29.4} + {'total': 29.5} GET diskio ---------- @@ -218,22 +218,7 @@ GET docker Get plugin stats:: # curl http://localhost:61208/api/3/docker - [{'Command': ['/bin/sh', - '-c', - 'python3 -m glances -C /glances/conf/glances.conf $GLANCES_OPT'], - 'Id': 'b37a03b9cd71ff9d83bb39ca93e6554a48c82bf8f4c757251f7de4847085061f', - 'Image': ['nicolargo/glances:dev'], - 'Names': ['dockerinfluxdb2grafana_glances_1'], - 'Status': 'paused', - 'cpu_percent': 0.0, - 'io_r': None, - 'io_w': None, - 'key': 'name', - 'memory_usage': None, - 'name': 'dockerinfluxdb2grafana_glances_1', - 'network_rx': None, - 'network_tx': None}, - {'Command': ['/entrypoint.sh', 'influxd'], + [{'Command': ['/entrypoint.sh', 'influxd'], 'Id': 'cf5df66383ead8b7a332b25956506bfc33573ba449d9dab98fcc606454d604cb', 'Image': ['influxdb:latest'], 'Names': ['dockerinfluxdb2grafana_influxdb_1'], @@ -242,9 +227,22 @@ Get plugin stats:: 'io_r': None, 'io_w': None, 'key': 'name', - 'memory_usage': None, + 'memory_usage': 22753280, 'name': 'dockerinfluxdb2grafana_influxdb_1', 'network_rx': None, + 'network_tx': None}, + {'Command': ['/run.sh'], + 'Id': 'f5674bcca78935c38a085cd9d1988b4eaec167fc00e9108740126ff46a11bf83', + 'Image': ['grafana/grafana:latest'], + 'Names': ['dockerinfluxdb2grafana_grafana_1'], + 'Status': 'running', + 'cpu_percent': 0.0, + 'io_r': None, + 'io_w': None, + 'key': 'name', + 'memory_usage': None, + 'name': 'dockerinfluxdb2grafana_grafana_1', + 'network_rx': None, 'network_tx': None}] GET fs @@ -254,13 +252,13 @@ Get plugin stats:: # curl http://localhost:61208/api/3/fs [{'device_name': '/dev/mapper/ubuntu--gnome--vg-root', - 'free': 31174983680, + 'free': 5852827648, 'fs_type': 'ext4', 'key': 'mnt_point', 'mnt_point': '/', - 'percent': 86.5, + 'percent': 97.5, 'size': 243396149248, - 'used': 199833710592}] + 'used': 225155866624}] Get a specific field:: @@ -271,13 +269,13 @@ Get a specific item when field matchs the given value:: # curl http://localhost:61208/api/3/fs/mnt_point// {'/': [{'device_name': '/dev/mapper/ubuntu--gnome--vg-root', - 'free': 31174983680, + 'free': 5852827648, 'fs_type': 'ext4', 'key': 'mnt_point', 'mnt_point': '/', - 'percent': 86.5, + 'percent': 97.5, 'size': 243396149248, - 'used': 199833710592}]} + 'used': 225155866624}]} GET ip ------ @@ -285,16 +283,16 @@ GET ip Get plugin stats:: # curl http://localhost:61208/api/3/ip - {'address': '192.168.0.49', + {'address': '192.168.0.33', 'gateway': '192.168.0.254', 'mask': '255.255.255.0', 'mask_cidr': 24, - 'public_address': '88.165.169.242'} + 'public_address': '91.166.228.228'} Get a specific field:: # curl http://localhost:61208/api/3/ip/address - {'address': '192.168.0.49'} + {'address': '192.168.0.33'} GET load -------- @@ -302,7 +300,7 @@ GET load Get plugin stats:: # curl http://localhost:61208/api/3/load - {'cpucore': 4, 'min1': 1.33, 'min15': 1.33, 'min5': 1.62} + {'cpucore': 4, 'min1': 0.93, 'min15': 1.48, 'min5': 1.13} Fields descriptions: @@ -314,7 +312,7 @@ Fields descriptions: Get a specific field:: # curl http://localhost:61208/api/3/load/min1 - {'min1': 1.33} + {'min1': 0.93} GET mem ------- @@ -322,16 +320,16 @@ GET mem Get plugin stats:: # curl http://localhost:61208/api/3/mem - {'active': 5155495936, - 'available': 1410424832, - 'buffers': 93065216, - 'cached': 1465229312, - 'free': 1410424832, - 'inactive': 1209888768, - 'percent': 82.0, - 'shared': 584937472, + {'active': 5834387456, + 'available': 1353351168, + 'buffers': 304881664, + 'cached': 1838432256, + 'free': 1353351168, + 'inactive': 1002762240, + 'percent': 82.8, + 'shared': 703643648, 'total': 7849021440, - 'used': 6438596608} + 'used': 6495670272} Fields descriptions: @@ -358,13 +356,13 @@ GET memswap Get plugin stats:: # curl http://localhost:61208/api/3/memswap - {'free': 6121762816, - 'percent': 24.3, - 'sin': 1548627968, - 'sout': 4385939456, + {'free': 6441734144, + 'percent': 20.3, + 'sin': 5676781568, + 'sout': 9877434368, 'time_since_update': 1, 'total': 8082419712, - 'used': 1960656896} + 'used': 1640685568} Fields descriptions: @@ -388,11 +386,11 @@ Get plugin stats:: # curl http://localhost:61208/api/3/network [{'alias': None, - 'cumulative_cx': 59804055, - 'cumulative_rx': 19375827, - 'cumulative_tx': 40428228, + 'cumulative_cx': 8464674, + 'cumulative_rx': 21687, + 'cumulative_tx': 8442987, 'cx': 0, - 'interface_name': 'veth2845bac', + 'interface_name': 'vetha426f3c', 'is_up': True, 'key': 'interface_name', 'rx': 0, @@ -400,15 +398,15 @@ Get plugin stats:: 'time_since_update': 1, 'tx': 0}, {'alias': None, - 'cumulative_cx': 3698139, - 'cumulative_rx': 40807, - 'cumulative_tx': 3657332, + 'cumulative_cx': 12586698, + 'cumulative_rx': 1081053, + 'cumulative_tx': 11505645, 'cx': 0, - 'interface_name': 'docker0', - 'is_up': False, + 'interface_name': 'veth5d13ef7', + 'is_up': True, 'key': 'interface_name', 'rx': 0, - 'speed': 0, + 'speed': 10485760000, 'time_since_update': 1, 'tx': 0}] @@ -427,9 +425,9 @@ Fields descriptions: Get a specific field:: # curl http://localhost:61208/api/3/network/interface_name - {'interface_name': ['veth2845bac', + {'interface_name': ['vetha426f3c', + 'veth5d13ef7', 'docker0', - 'veth59b1a36', 'mpqemubr0', 'lo', 'br_grafana', @@ -439,13 +437,13 @@ Get a specific field:: Get a specific item when field matchs the given value:: - # curl http://localhost:61208/api/3/network/interface_name/veth2845bac - {'veth2845bac': [{'alias': None, - 'cumulative_cx': 59804055, - 'cumulative_rx': 19375827, - 'cumulative_tx': 40428228, + # curl http://localhost:61208/api/3/network/interface_name/vetha426f3c + {'vetha426f3c': [{'alias': None, + 'cumulative_cx': 8464674, + 'cumulative_rx': 21687, + 'cumulative_tx': 8442987, 'cx': 0, - 'interface_name': 'veth2845bac', + 'interface_name': 'vetha426f3c', 'is_up': True, 'key': 'interface_name', 'rx': 0, @@ -459,7 +457,7 @@ GET now Get plugin stats:: # curl http://localhost:61208/api/3/now - '2021-11-28 10:45:25 CET' + '2022-01-15 11:22:45 CET' GET percpu ---------- @@ -470,20 +468,7 @@ Get plugin stats:: [{'cpu_number': 0, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 74.0, - 'iowait': 0.0, - 'irq': 0.0, - 'key': 'cpu_number', - 'nice': 0.0, - 'softirq': 0.0, - 'steal': 0.0, - 'system': 6.0, - 'total': 26.0, - 'user': 5.0}, - {'cpu_number': 1, - 'guest': 0.0, - 'guest_nice': 0.0, - 'idle': 10.0, + 'idle': 82.0, 'iowait': 0.0, 'irq': 0.0, 'key': 'cpu_number', @@ -491,8 +476,21 @@ Get plugin stats:: 'softirq': 0.0, 'steal': 0.0, 'system': 2.0, - 'total': 90.0, - 'user': 67.0}] + 'total': 18.0, + 'user': 8.0}, + {'cpu_number': 1, + 'guest': 0.0, + 'guest_nice': 0.0, + 'idle': 17.0, + 'iowait': 0.0, + 'irq': 0.0, + 'key': 'cpu_number', + 'nice': 0.0, + 'softirq': 0.0, + 'steal': 0.0, + 'system': 6.0, + 'total': 83.0, + 'user': 71.0}] Get a specific field:: @@ -511,7 +509,7 @@ Get plugin stats:: 'port': 0, 'refresh': 30, 'rtt_warning': None, - 'status': 0.007373, + 'status': 0.007164, 'timeout': 3}] Get a specific field:: @@ -528,7 +526,7 @@ Get a specific item when field matchs the given value:: 'port': 0, 'refresh': 30, 'rtt_warning': None, - 'status': 0.007373, + 'status': 0.007164, 'timeout': 3}]} GET processcount @@ -537,12 +535,12 @@ GET processcount Get plugin stats:: # curl http://localhost:61208/api/3/processcount - {'pid_max': 0, 'running': 1, 'sleeping': 285, 'thread': 1568, 'total': 353} + {'pid_max': 0, 'running': 1, 'sleeping': 290, 'thread': 1541, 'total': 352} Get a specific field:: # curl http://localhost:61208/api/3/processcount/total - {'total': 353} + {'total': 352} GET processlist --------------- @@ -550,59 +548,52 @@ GET processlist Get plugin stats:: # curl http://localhost:61208/api/3/processlist - [{'cmdline': ['/usr/share/code/code', - '--type=renderer', - '--disable-color-correct-rendering', - '--field-trial-handle=9801772374554752705,8463974869748304130,131072', - '--disable-features=CookiesWithoutSameSiteMustBeSecure,SameSiteByDefaultCookies,SpareRendererForSitePerProcess', - '--lang=en-US', - '--enable-crash-reporter=7c06f526-63e8-47aa-8c08-b95f6ad2ec2d,no_channel', - '--global-crash-keys=7c06f526-63e8-47aa-8c08-b95f6ad2ec2d,no_channel,_companyName=Microsoft,_productName=VSCode,_version=1.59.1', - '--user-data-dir=/home/nicolargo/.config/Code', - '--standard-schemes=vscode-webview,vscode-file', - '--secure-schemes=vscode-webview,vscode-file', - '--bypasscsp-schemes', - '--cors-schemes=vscode-webview,vscode-file', - '--fetch-schemes=vscode-webview,vscode-file', - '--service-worker-schemes=vscode-webview', - '--streaming-schemes', - '--app-path=/usr/share/code/resources/app', - '--no-sandbox', - '--no-zygote', - '--num-raster-threads=2', - '--enable-main-frame-before-activation', - '--renderer-client-id=9', - '--no-v8-untrusted-code-mitigations', - '--shared-files=v8_context_snapshot_data:100', - '--vscode-window-config=vscode:662562c7-385c-48ce-8810-0faf0271b42a'], + [{'cmdline': ['/usr/lib/firefox/firefox'], 'cpu_percent': 0.0, - 'cpu_times': pcputimes(user=2920.73, system=230.07, children_user=9.05, children_system=2.1, iowait=2.94), + 'cpu_times': pcputimes(user=13600.16, system=6195.46, children_user=1815.12, children_system=383.89, iowait=4.63), 'gids': pgids(real=1000, effective=1000, saved=1000), - 'io_counters': [614957056, 18755584, 0, 0, 0], + 'io_counters': [3538935808, 53054558208, 0, 0, 0], 'key': 'pid', - 'memory_info': pmem(rss=1157496832, vms=54968766464, shared=81698816, text=125108224, lib=0, data=1443426304, dirty=0), - 'memory_percent': 14.747020897422852, - 'name': 'code', + 'memory_info': pmem(rss=518144000, vms=4950585344, shared=142413824, text=643072, lib=0, data=1333030912, dirty=0), + 'memory_percent': 6.60138342035157, + 'name': 'GeckoMain', 'nice': 0, - 'num_threads': 20, - 'pid': 239588, - 'ppid': 238897, + 'num_threads': 154, + 'pid': 1503459, + 'ppid': 3847, 'status': 'S', 'time_since_update': 1, 'username': 'nicolargo'}, - {'cmdline': ['/usr/lib/firefox/firefox', '-new-window'], + {'cmdline': ['/usr/lib/firefox/firefox', + '-contentproc', + '-childID', + '14', + '-isForBrowser', + '-prefsLen', + '8563', + '-prefMapSize', + '252236', + '-jsInitLen', + '278884', + '-parentBuildID', + '20211215221728', + '-appDir', + '/usr/lib/firefox/browser', + '1503459', + 'true', + 'tab'], 'cpu_percent': 0.0, - 'cpu_times': pcputimes(user=19063.26, system=6137.23, children_user=12397.16, children_system=2423.4, iowait=7.35), + 'cpu_times': pcputimes(user=4731.62, system=1025.04, children_user=0.0, children_system=0.0, iowait=0.87), 'gids': pgids(real=1000, effective=1000, saved=1000), - 'io_counters': [6021562368, 24573427712, 0, 0, 0], + 'io_counters': [67727360, 65536, 0, 0, 0], 'key': 'pid', - 'memory_info': pmem(rss=629800960, vms=5408382976, shared=170909696, text=626688, lib=0, data=1499762688, dirty=0), - 'memory_percent': 8.023942408800453, - 'name': 'firefox', + 'memory_info': pmem(rss=478609408, vms=3810025472, shared=53080064, text=643072, lib=0, data=1046167552, dirty=0), + 'memory_percent': 6.097695256136286, + 'name': 'Web Content', 'nice': 0, - 'num_threads': 186, - 'pid': 5637, - 'ppid': 3847, + 'num_threads': 24, + 'pid': 1513121, + 'ppid': 1503459, 'status': 'S', 'time_since_update': 1, 'username': 'nicolargo'}] @@ -610,197 +601,197 @@ Get plugin stats:: Get a specific field:: # curl http://localhost:61208/api/3/processlist/pid - {'pid': [239588, - 5637, - 5755, - 5895, - 239766, - 5946, + {'pid': [1503459, + 1513121, + 2195844, + 1503674, + 1503575, + 1503572, + 2195942, 4092, - 462733, - 239606, - 459136, - 490976, - 489301, - 18486, - 480546, - 238929, - 459784, - 465560, - 281859, - 238897, - 476035, - 239618, - 490348, - 5798, - 238993, - 68322, + 1532561, + 2195826, + 1531912, + 2181020, + 2064119, + 1513158, + 2172756, + 2196630, + 1531883, + 1513179, + 2194859, + 1484922, 178587, - 487310, - 459802, - 459989, - 3934, - 491915, - 3913, - 481575, - 239023, - 270468, - 374111, + 1484953, + 1485034, + 2195376, + 2195852, + 1503546, 2259, + 3913, + 2198033, + 2193029, + 1542400, + 1485057, + 1542733, + 18486, + 3934, + 1542791, 3855, + 1531913, + 1484973, + 1479304, 3336, - 348, - 211213, - 238947, 2430, + 2193739, + 1541631, + 211213, + 2193737, + 1517056, + 348, 4181, - 1300, - 483055, - 4928, - 6053, - 150281, - 3853, - 4241, - 483057, - 1139, 4265, + 4928, + 4241, + 1139, + 3853, + 2193803, 1, - 4266, - 4261, - 138395, - 4121, - 237994, 4116, - 4143, - 1158, - 4374, - 483096, - 4152, + 4261, + 2196251, 1180, + 1158, + 1503837, + 2193801, + 4266, + 4152, 1285, - 4287, - 2216, 3847, - 4164, - 4284, - 396199, - 238900, - 483094, + 4287, + 2196261, + 237994, + 4374, + 2196264, + 3764, + 4143, 3863, - 3890, - 4123, - 4274, - 238901, + 1181, + 1544077, + 4164, + 2195625, 4264, 1138, - 1324, - 3764, - 1008, - 1121, - 1153, - 3959, - 4160, - 3858, - 4332, - 2208, - 1575, - 3868, - 1354, - 4196, + 4284, + 1544092, 4078, - 4343, - 4267, - 4279, - 4262, - 4340, - 4263, - 344713, - 5587, - 2394, - 3927, - 4129, + 1544088, 255840, - 1176, - 2406, - 3932, - 4339, - 4281, - 172714, - 4252, - 3921, - 18537, - 239661, - 4273, - 4276, - 3896, - 3902, - 459949, - 4048, - 4120, - 4137, - 1173, - 4285, + 3890, + 138395, + 4274, + 3858, 5573, - 1181, - 4272, - 4057, - 4260, - 67406, - 1178, + 4332, + 4129, + 1575, + 1008, + 1324, + 4196, + 1548391, + 1176, + 1541718, + 1484926, + 1526429, + 1520402, + 1354, + 4279, + 2216, + 4252, + 4123, + 4121, + 600490, + 1484927, + 1537927, + 3927, + 3902, 1147, - 1150, - 37983, + 1484929, + 1153, + 4048, + 4272, + 67406, + 3932, + 4276, + 3959, 1129, - 459734, - 3908, - 4072, - 1010, - 4062, - 3883, - 4141, - 1166, - 37989, + 4160, + 1542748, + 4339, + 4263, + 4340, + 1150, 6521, - 1130, - 459752, - 37992, - 1007, - 344711, - 1135, - 187870, + 5587, + 18537, + 2198013, + 3896, + 1544090, + 4343, + 1173, + 4062, + 1544091, + 3921, + 3908, 1163, - 491873, - 1182, - 1209, + 4137, 1451, - 138445, - 3339, - 2230, - 2403, - 459705, - 37995, + 1178, + 2196267, + 1010, + 344713, + 4273, + 1182, + 4267, + 4281, + 1007, + 1135, + 4057, 213050, + 3883, + 344711, + 1209, + 3339, + 4262, + 2230, + 172714, + 4072, + 1542688, + 1132, + 4260, + 4285, + 138445, + 1166, + 1542646, + 4141, 344710, - 459720, - 1122, - 4601, - 491914, - 2229, - 2035, - 2404, - 3848, - 997, - 2235, - 1335, - 1214, - 375, - 213333, - 238903, 4029, + 4120, + 3868, + 2198032, + 1122, + 2035, + 2229, + 2235, + 3848, + 213333, + 1214, + 997, + 1335, + 375, 2, 3, 4, - 6, 9, 10, 11, @@ -857,13 +848,11 @@ Get a specific field:: 196, 202, 203, - 204, 207, 208, 237, 279, 280, - 288, 289, 291, 359, @@ -892,10 +881,8 @@ Get a specific field:: 904, 915, 932, - 939, 947, 958, - 1132, 1347, 1432, 1433, @@ -908,7 +895,7 @@ Get a specific field:: 2301, 2325, 3909, - 24555, + 4601, 24771, 25388, 57294, @@ -928,91 +915,70 @@ Get a specific field:: 210918, 211155, 211634, - 211932, 212663, - 217976, - 264756, 354417, 378648, 378848, 379044, - 379176, - 379506, - 389975, - 425005, 439123, 439461, - 459971, - 460998, - 478806, - 482831, - 482922, - 482954, - 483095, - 484996, - 486264, - 486448, - 487343, - 487746, - 487752, - 488822, - 489960, - 490238, - 490292, - 490396, - 490397, - 490398, - 490570]} + 507654, + 582345, + 582789, + 609671, + 609799, + 613137, + 632508, + 632584, + 1539753, + 1542716, + 2059667, + 2181763, + 2185178, + 2191796, + 2192521, + 2192986, + 2193330, + 2193618, + 2193622, + 2194689, + 2195181, + 2195212, + 2196123, + 2196215, + 2196622, + 2197142, + 2197157, + 2197268, + 2197643, + 2197703, + 2197756]} Get a specific item when field matchs the given value:: - # curl http://localhost:61208/api/3/processlist/pid/239588 - {'239588': [{'cmdline': ['/usr/share/code/code', - '--type=renderer', - '--disable-color-correct-rendering', - '--field-trial-handle=9801772374554752705,8463974869748304130,131072', - '--disable-features=CookiesWithoutSameSiteMustBeSecure,SameSiteByDefaultCookies,SpareRendererForSitePerProcess', - '--lang=en-US', - '--enable-crash-reporter=7c06f526-63e8-47aa-8c08-b95f6ad2ec2d,no_channel', - '--global-crash-keys=7c06f526-63e8-47aa-8c08-b95f6ad2ec2d,no_channel,_companyName=Microsoft,_productName=VSCode,_version=1.59.1', - '--user-data-dir=/home/nicolargo/.config/Code', - '--standard-schemes=vscode-webview,vscode-file', - '--secure-schemes=vscode-webview,vscode-file', - '--bypasscsp-schemes', - '--cors-schemes=vscode-webview,vscode-file', - '--fetch-schemes=vscode-webview,vscode-file', - '--service-worker-schemes=vscode-webview', - '--streaming-schemes', - '--app-path=/usr/share/code/resources/app', - '--no-sandbox', - '--no-zygote', - '--num-raster-threads=2', - '--enable-main-frame-before-activation', - '--renderer-client-id=9', - '--no-v8-untrusted-code-mitigations', - '--shared-files=v8_context_snapshot_data:100', - '--vscode-window-config=vscode:662562c7-385c-48ce-8810-0faf0271b42a'], - 'cpu_percent': 0.0, - 'cpu_times': [2920.73, 230.07, 9.05, 2.1, 2.94], - 'gids': [1000, 1000, 1000], - 'io_counters': [614957056, 18755584, 0, 0, 0], - 'key': 'pid', - 'memory_info': [1157496832, - 54968766464, - 81698816, - 125108224, - 0, - 1443426304, - 0], - 'memory_percent': 14.747020897422852, - 'name': 'code', - 'nice': 0, - 'num_threads': 20, - 'pid': 239588, - 'ppid': 238897, - 'status': 'S', - 'time_since_update': 1, - 'username': 'nicolargo'}]} + # curl http://localhost:61208/api/3/processlist/pid/1503459 + {'1503459': [{'cmdline': ['/usr/lib/firefox/firefox'], + 'cpu_percent': 0.0, + 'cpu_times': [13600.16, 6195.46, 1815.12, 383.89, 4.63], + 'gids': [1000, 1000, 1000], + 'io_counters': [3538935808, 53054558208, 0, 0, 0], + 'key': 'pid', + 'memory_info': [518144000, + 4950585344, + 142413824, + 643072, + 0, + 1333030912, + 0], + 'memory_percent': 6.60138342035157, + 'name': 'GeckoMain', + 'nice': 0, + 'num_threads': 154, + 'pid': 1503459, + 'ppid': 3847, + 'status': 'S', + 'time_since_update': 1, + 'username': 'nicolargo'}]} GET psutilversion ----------------- @@ -1028,28 +994,15 @@ GET quicklook Get plugin stats:: # curl http://localhost:61208/api/3/quicklook - {'cpu': 29.4, - 'cpu_hz': 3000000000.0, - 'cpu_hz_current': 2330060000.0, + {'cpu': 29.5, + 'cpu_hz': 2025000000.0, + 'cpu_hz_current': 1614371750.0, 'cpu_name': 'Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz', - 'mem': 82.0, + 'mem': 82.8, 'percpu': [{'cpu_number': 0, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 74.0, - 'iowait': 0.0, - 'irq': 0.0, - 'key': 'cpu_number', - 'nice': 0.0, - 'softirq': 0.0, - 'steal': 0.0, - 'system': 6.0, - 'total': 26.0, - 'user': 5.0}, - {'cpu_number': 1, - 'guest': 0.0, - 'guest_nice': 0.0, - 'idle': 10.0, + 'idle': 82.0, 'iowait': 0.0, 'irq': 0.0, 'key': 'cpu_number', @@ -1057,40 +1010,53 @@ Get plugin stats:: 'softirq': 0.0, 'steal': 0.0, 'system': 2.0, - 'total': 90.0, - 'user': 67.0}, + 'total': 18.0, + 'user': 8.0}, + {'cpu_number': 1, + 'guest': 0.0, + 'guest_nice': 0.0, + 'idle': 17.0, + 'iowait': 0.0, + 'irq': 0.0, + 'key': 'cpu_number', + 'nice': 0.0, + 'softirq': 0.0, + 'steal': 0.0, + 'system': 6.0, + 'total': 83.0, + 'user': 71.0}, {'cpu_number': 2, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 74.0, + 'idle': 87.0, + 'iowait': 0.0, + 'irq': 0.0, + 'key': 'cpu_number', + 'nice': 0.0, + 'softirq': 3.0, + 'steal': 0.0, + 'system': 3.0, + 'total': 13.0, + 'user': 3.0}, + {'cpu_number': 3, + 'guest': 0.0, + 'guest_nice': 0.0, + 'idle': 80.0, 'iowait': 0.0, 'irq': 0.0, 'key': 'cpu_number', 'nice': 0.0, 'softirq': 4.0, 'steal': 0.0, - 'system': 4.0, - 'total': 26.0, - 'user': 4.0}, - {'cpu_number': 3, - 'guest': 0.0, - 'guest_nice': 0.0, - 'idle': 76.0, - 'iowait': 1.0, - 'irq': 0.0, - 'key': 'cpu_number', - 'nice': 0.0, - 'softirq': 0.0, - 'steal': 0.0, 'system': 3.0, - 'total': 24.0, - 'user': 5.0}], - 'swap': 24.3} + 'total': 20.0, + 'user': 9.0}], + 'swap': 20.3} Get a specific field:: # curl http://localhost:61208/api/3/quicklook/cpu - {'cpu': 29.4} + {'cpu': 29.5} GET sensors ----------- @@ -1161,7 +1127,7 @@ GET uptime Get plugin stats:: # curl http://localhost:61208/api/3/uptime - {'seconds': 6870587} + {'seconds': 11020020} GET all stats ------------- @@ -1177,33 +1143,33 @@ GET stats history History of a plugin:: # curl http://localhost:61208/api/3/cpu/history - {'system': [['2021-11-28T10:45:25.412479', 5.3], - ['2021-11-28T10:45:26.495214', 5.3], - ['2021-11-28T10:45:27.605090', 4.2]], - 'user': [['2021-11-28T10:45:25.412472', 22.9], - ['2021-11-28T10:45:26.495210', 22.9], - ['2021-11-28T10:45:27.605086', 9.0]]} + {'system': [['2022-01-15T11:22:45.669711', 4.4], + ['2022-01-15T11:22:46.769745', 4.4], + ['2022-01-15T11:22:47.935395', 3.8]], + 'user': [['2022-01-15T11:22:45.669687', 23.3], + ['2022-01-15T11:22:46.769738', 23.3], + ['2022-01-15T11:22:47.935388', 7.9]]} Limit history to last 2 values:: # curl http://localhost:61208/api/3/cpu/history/2 - {'system': [['2021-11-28T10:45:26.495214', 5.3], - ['2021-11-28T10:45:27.605090', 4.2]], - 'user': [['2021-11-28T10:45:26.495210', 22.9], - ['2021-11-28T10:45:27.605086', 9.0]]} + {'system': [['2022-01-15T11:22:46.769745', 4.4], + ['2022-01-15T11:22:47.935395', 3.8]], + 'user': [['2022-01-15T11:22:46.769738', 23.3], + ['2022-01-15T11:22:47.935388', 7.9]]} History for a specific field:: # curl http://localhost:61208/api/3/cpu/system/history - {'system': [['2021-11-28T10:45:25.412479', 5.3], - ['2021-11-28T10:45:26.495214', 5.3], - ['2021-11-28T10:45:27.605090', 4.2]]} + {'system': [['2022-01-15T11:22:45.669711', 4.4], + ['2022-01-15T11:22:46.769745', 4.4], + ['2022-01-15T11:22:47.935395', 3.8]]} Limit history for a specific field to last 2 values:: # curl http://localhost:61208/api/3/cpu/system/history - {'system': [['2021-11-28T10:45:26.495214', 5.3], - ['2021-11-28T10:45:27.605090', 4.2]]} + {'system': [['2022-01-15T11:22:46.769745', 4.4], + ['2022-01-15T11:22:47.935395', 3.8]]} GET limits (used for thresholds) -------------------------------- diff --git a/docs/man/glances.1 b/docs/man/glances.1 index 6241682a..8b5f4456 100644 --- a/docs/man/glances.1 +++ b/docs/man/glances.1 @@ -1,6 +1,6 @@ .\" Man page generated from reStructuredText. . -.TH "GLANCES" "1" "Nov 28, 2021" "3.2.5_beta01" "Glances" +.TH "GLANCES" "1" "Jan 15, 2022" "3.2.5_beta01" "Glances" .SH NAME glances \- An eye on your system . @@ -879,6 +879,6 @@ $ glances –browser .sp Nicolas Hennion aka Nicolargo <\fI\%contact@nicolargo.com\fP> .SH COPYRIGHT -2021, Nicolas Hennion +2022, Nicolas Hennion .\" Generated by docutils manpage writer. . diff --git a/glances/outputs/glances_bottle.py b/glances/outputs/glances_bottle.py index b8931eac..a325fc8a 100644 --- a/glances/outputs/glances_bottle.py +++ b/glances/outputs/glances_bottle.py @@ -2,7 +2,7 @@ # # This file is part of Glances. # -# Copyright (C) 2019 Nicolargo +# Copyright (C) 2022 Nicolargo # # Glances is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by @@ -12,7 +12,7 @@ # Glances is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. +# GNU Lesser General Public License 1for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . @@ -145,6 +145,7 @@ class GlancesBottle(object): def _route(self): """Define route.""" # REST API + self._app.route('/api/%s/status' % self.API_VERSION, method="GET", callback=self._api_status) self._app.route('/api/%s/config' % self.API_VERSION, method="GET", callback=self._api_config) self._app.route('/api/%s/config/' % self.API_VERSION, method="GET", callback=self._api_config_item) self._app.route('/api/%s/args' % self.API_VERSION, method="GET", callback=self._api_args) @@ -226,6 +227,19 @@ class GlancesBottle(object): # Return the static file return static_file(filepath, root=self.STATIC_PATH) + @compress + def _api_status(self): + """Glances API RESTful implementation. + + Return a 200 status code. + This entry point should be used to check the API health. + + See related issue: Web server health check endpoint #1988 + """ + response.status = 200 + + return None + @compress def _api_help(self): """Glances API RESTful implementation. diff --git a/glances/outputs/glances_stdout_apidoc.py b/glances/outputs/glances_stdout_apidoc.py index d31be029..6a7e4529 100644 --- a/glances/outputs/glances_stdout_apidoc.py +++ b/glances/outputs/glances_stdout_apidoc.py @@ -2,7 +2,7 @@ # # This file is part of Glances. # -# Copyright (C) 2021 Nicolargo +# Copyright (C) 2022 Nicolargo # # Glances is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by @@ -53,12 +53,28 @@ def indent_stat(stat, indent=' '): return indent + pformat(stat).replace('\n', '\n' + indent) +def print_api_status(): + sub_title = 'GET API status' + print(sub_title) + print('-' * len(sub_title)) + print('') + print('This entry point should be used to check the API status.') + print('It will return nothing but a 200 return code if everythin is OK.') + print('') + print('Get the Rest API status:') + print('') + print(' # curl -I {}/status'.format(API_URL)) + print(indent_stat('HTTP/1.0 200 OK')) + print('') + + + def print_plugins_list(stat): sub_title = 'GET plugins list' print(sub_title) print('-' * len(sub_title)) print('') - print('Get the plugins list::') + print('Get the plugins list:') print('') print(' # curl {}/pluginslist'.format(API_URL)) print(indent_stat(stat)) @@ -71,7 +87,7 @@ def print_plugin_export(plugin, stat_export): print('-' * len(sub_title)) print('') - print('Get plugin stats::') + print('Get plugin stats:') print('') print(' # curl {}/{}'.format(API_URL, plugin)) print(indent_stat(stat_export)) @@ -115,7 +131,7 @@ def print_plugin_item_value(plugin, stat, stat_export): value = stat_item[item][0] else: value = stat_item[item] - print('Get a specific field::') + print('Get a specific field:') print('') print(' # curl {}/{}/{}'.format(API_URL, plugin, item)) print(indent_stat(stat_item)) @@ -133,7 +149,7 @@ def print_all(): print(sub_title) print('-' * len(sub_title)) print('') - print('Get all Glances stats::') + print('Get all Glances stats:') print('') print(' # curl {}/all'.format(API_URL)) print(' Return a very big dictionnary (avoid using this request, performances will be poor)...') @@ -149,17 +165,17 @@ def print_history(stats): print(sub_title) print('-' * len(sub_title)) print('') - print('History of a plugin::') + print('History of a plugin:') print('') print(' # curl {}/cpu/history'.format(API_URL)) print(indent_stat(json.loads(stats.get_plugin('cpu').get_stats_history(nb=3)))) print('') - print('Limit history to last 2 values::') + print('Limit history to last 2 values:') print('') print(' # curl {}/cpu/history/2'.format(API_URL)) print(indent_stat(json.loads(stats.get_plugin('cpu').get_stats_history(nb=2)))) print('') - print('History for a specific field::') + print('History for a specific field:') print('') print(' # curl {}/cpu/system/history'.format(API_URL)) print(indent_stat(json.loads(stats.get_plugin('cpu').get_stats_history('system')))) @@ -176,12 +192,12 @@ def print_limits(stats): print(sub_title) print('-' * len(sub_title)) print('') - print('All limits/thresholds::') + print('All limits/thresholds:') print('') print(' # curl {}/all/limits'.format(API_URL)) print(indent_stat(stats.getAllLimitsAsDict())) print('') - print('Limits/thresholds for the cpu plugin::') + print('Limits/thresholds for the cpu plugin:') print('') print(' # curl {}/cpu/limits'.format(API_URL)) print(indent_stat(stats.get_plugin('cpu').limits)) @@ -206,6 +222,9 @@ class GlancesStdoutApiDoc(object): # Display header print(APIDOC_HEADER) + # Display API status + print_api_status() + # Display plugins list print_plugins_list(sorted(stats._plugins)) From 2729bd767f697d7d43e8565a21f605977d15657e Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sat, 15 Jan 2022 11:34:52 +0100 Subject: [PATCH 2/5] Update docs for API. Related to issue #1988 --- docs/api.rst | 387 ++++++++++++++++++++++++++------------------------- 1 file changed, 198 insertions(+), 189 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 8523e68f..25f6a9cd 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -11,10 +11,21 @@ The Glances Restfull/API server could be ran using the following command line: Note: Change request URL api/3 by api/2 if you use Glances 2.x. +GET API status +-------------- + +This entry point should be used to check the API status. +It will return nothing but a 200 return code if everythin is OK. + +Get the Rest API status: + + # curl -I http://localhost:61208/api/3/status + 'HTTP/1.0 200 OK' + GET plugins list ---------------- -Get the plugins list:: +Get the plugins list: # curl http://localhost:61208/api/3/pluginslist ['alert', @@ -52,17 +63,17 @@ Get the plugins list:: GET alert --------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/alert - [[1642242165.0, + [[1642242851.0, -1, 'WARNING', 'MEM', - 82.75770835453343, - 82.75770835453343, - 82.75770835453343, - 82.75770835453343, + 83.60534685964623, + 83.60534685964623, + 83.60534685964623, + 83.60534685964623, 1, [], '', @@ -71,7 +82,7 @@ Get plugin stats:: GET amps -------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/amps [{'count': 0, @@ -82,7 +93,7 @@ Get plugin stats:: 'refresh': 3.0, 'regex': True, 'result': None, - 'timer': 0.20821332931518555}, + 'timer': 0.26227450370788574}, {'count': 0, 'countmax': 20.0, 'countmin': None, @@ -91,9 +102,9 @@ Get plugin stats:: 'refresh': 3.0, 'regex': True, 'result': None, - 'timer': 0.20801949501037598}] + 'timer': 0.2620673179626465}] -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/amps/name {'name': ['Dropbox', 'Python', 'Conntrack', 'Nginx', 'Systemd', 'SystemV']} @@ -109,12 +120,12 @@ Get a specific item when field matchs the given value:: 'refresh': 3.0, 'regex': True, 'result': None, - 'timer': 0.20821332931518555}]} + 'timer': 0.26227450370788574}]} GET core -------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/core {'log': 4, 'phys': 2} @@ -124,7 +135,7 @@ Fields descriptions: * **phys**: Number of physical cores (hyper thread CPUs are excluded) (unit is *number*) * **log**: Number of logical CPUs. A logical CPU is the number of physical cores multiplied by the number of threads that can run on each core (unit is *number*) -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/core/phys {'phys': 2} @@ -132,26 +143,26 @@ Get a specific field:: GET cpu ------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/cpu {'cpucore': 4, 'ctx_switches': 0, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 70.4, + 'idle': 67.0, 'interrupts': 0, - 'iowait': 0.2, + 'iowait': 0.4, 'irq': 0.0, 'nice': 0.0, 'soft_interrupts': 0, - 'softirq': 1.7, + 'softirq': 2.5, 'steal': 0.0, 'syscalls': 0, - 'system': 4.4, + 'system': 5.0, 'time_since_update': 1, - 'total': 29.5, - 'user': 23.3} + 'total': 32.7, + 'user': 25.2} Fields descriptions: @@ -170,15 +181,15 @@ Fields descriptions: * **cpucore**: Total number of CPU core (unit is *number*) * **time_since_update**: Number of seconds since last update (unit is *seconds*) -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/cpu/total - {'total': 29.5} + {'total': 32.7} GET diskio ---------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/diskio [{'disk_name': 'sda', @@ -196,7 +207,7 @@ Get plugin stats:: 'write_bytes': 0, 'write_count': 0}] -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/diskio/disk_name {'disk_name': ['sda', 'sda1', 'sda2', 'sda5', 'dm-0', 'dm-1']} @@ -215,7 +226,7 @@ Get a specific item when field matchs the given value:: GET docker ---------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/docker [{'Command': ['/entrypoint.sh', 'influxd'], @@ -227,7 +238,7 @@ Get plugin stats:: 'io_r': None, 'io_w': None, 'key': 'name', - 'memory_usage': 22753280, + 'memory_usage': 22781952, 'name': 'dockerinfluxdb2grafana_influxdb_1', 'network_rx': None, 'network_tx': None}, @@ -248,19 +259,19 @@ Get plugin stats:: GET fs ------ -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/fs [{'device_name': '/dev/mapper/ubuntu--gnome--vg-root', - 'free': 5852827648, + 'free': 5851906048, 'fs_type': 'ext4', 'key': 'mnt_point', 'mnt_point': '/', 'percent': 97.5, 'size': 243396149248, - 'used': 225155866624}] + 'used': 225156788224}] -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/fs/mnt_point {'mnt_point': ['/']} @@ -269,18 +280,18 @@ Get a specific item when field matchs the given value:: # curl http://localhost:61208/api/3/fs/mnt_point// {'/': [{'device_name': '/dev/mapper/ubuntu--gnome--vg-root', - 'free': 5852827648, + 'free': 5851906048, 'fs_type': 'ext4', 'key': 'mnt_point', 'mnt_point': '/', 'percent': 97.5, 'size': 243396149248, - 'used': 225155866624}]} + 'used': 225156788224}]} GET ip ------ -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/ip {'address': '192.168.0.33', @@ -289,7 +300,7 @@ Get plugin stats:: 'mask_cidr': 24, 'public_address': '91.166.228.228'} -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/ip/address {'address': '192.168.0.33'} @@ -297,10 +308,10 @@ Get a specific field:: GET load -------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/load - {'cpucore': 4, 'min1': 0.93, 'min15': 1.48, 'min5': 1.13} + {'cpucore': 4, 'min1': 1.53, 'min15': 1.55, 'min5': 1.61} Fields descriptions: @@ -309,27 +320,27 @@ Fields descriptions: * **min15**: Average sum of the number of processes waiting in the run-queue plus the number currently executing over 15 minutes (unit is *float*) * **cpucore**: Total number of CPU core (unit is *number*) -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/load/min1 - {'min1': 0.93} + {'min1': 1.53} GET mem ------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/mem - {'active': 5834387456, - 'available': 1353351168, - 'buffers': 304881664, - 'cached': 1838432256, - 'free': 1353351168, - 'inactive': 1002762240, - 'percent': 82.8, - 'shared': 703643648, + {'active': 5850939392, + 'available': 1286819840, + 'buffers': 313094144, + 'cached': 1794244608, + 'free': 1286819840, + 'inactive': 996773888, + 'percent': 83.6, + 'shared': 715137024, 'total': 7849021440, - 'used': 6495670272} + 'used': 6562201600} Fields descriptions: @@ -345,7 +356,7 @@ Fields descriptions: * **wired**: *(BSD, macOS)*: memory that is marked to always stay in RAM. It is never moved to disk (unit is *bytes*) * **shared**: *(BSD)*: memory that may be simultaneously accessed by multiple processes (unit is *bytes*) -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/mem/total {'total': 7849021440} @@ -353,16 +364,16 @@ Get a specific field:: GET memswap ----------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/memswap - {'free': 6441734144, + {'free': 6443831296, 'percent': 20.3, - 'sin': 5676781568, + 'sin': 5678075904, 'sout': 9877434368, 'time_since_update': 1, 'total': 8082419712, - 'used': 1640685568} + 'used': 1638588416} Fields descriptions: @@ -374,7 +385,7 @@ Fields descriptions: * **sout**: The number of bytes the system has swapped out from disk (cumulative) (unit is *bytes*) * **time_since_update**: Number of seconds since last update (unit is *seconds*) -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/memswap/total {'total': 8082419712} @@ -382,13 +393,13 @@ Get a specific field:: GET network ----------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/network [{'alias': None, - 'cumulative_cx': 8464674, + 'cumulative_cx': 8501233, 'cumulative_rx': 21687, - 'cumulative_tx': 8442987, + 'cumulative_tx': 8479546, 'cx': 0, 'interface_name': 'vetha426f3c', 'is_up': True, @@ -398,9 +409,9 @@ Get plugin stats:: 'time_since_update': 1, 'tx': 0}, {'alias': None, - 'cumulative_cx': 12586698, - 'cumulative_rx': 1081053, - 'cumulative_tx': 11505645, + 'cumulative_cx': 12641380, + 'cumulative_rx': 1086025, + 'cumulative_tx': 11555355, 'cx': 0, 'interface_name': 'veth5d13ef7', 'is_up': True, @@ -422,7 +433,7 @@ Fields descriptions: * **is_up**: Is the interface up ? (unit is *bool*) * **time_since_update**: Number of seconds since last update (unit is *seconds*) -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/network/interface_name {'interface_name': ['vetha426f3c', @@ -439,9 +450,9 @@ Get a specific item when field matchs the given value:: # curl http://localhost:61208/api/3/network/interface_name/vetha426f3c {'vetha426f3c': [{'alias': None, - 'cumulative_cx': 8464674, + 'cumulative_cx': 8501233, 'cumulative_rx': 21687, - 'cumulative_tx': 8442987, + 'cumulative_tx': 8479546, 'cx': 0, 'interface_name': 'vetha426f3c', 'is_up': True, @@ -454,45 +465,45 @@ Get a specific item when field matchs the given value:: GET now ------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/now - '2022-01-15 11:22:45 CET' + '2022-01-15 11:34:11 CET' GET percpu ---------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/percpu [{'cpu_number': 0, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 82.0, + 'idle': 74.5, 'iowait': 0.0, 'irq': 0.0, 'key': 'cpu_number', 'nice': 0.0, - 'softirq': 0.0, + 'softirq': 6.4, 'steal': 0.0, - 'system': 2.0, - 'total': 18.0, - 'user': 8.0}, + 'system': 3.6, + 'total': 25.5, + 'user': 15.5}, {'cpu_number': 1, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 17.0, + 'idle': 64.8, 'iowait': 0.0, 'irq': 0.0, 'key': 'cpu_number', 'nice': 0.0, - 'softirq': 0.0, + 'softirq': 3.7, 'steal': 0.0, - 'system': 6.0, - 'total': 83.0, - 'user': 71.0}] + 'system': 2.8, + 'total': 35.2, + 'user': 28.7}] -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/percpu/cpu_number {'cpu_number': [0, 1, 2, 3]} @@ -500,7 +511,7 @@ Get a specific field:: GET ports --------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/ports [{'description': 'DefaultGateway', @@ -509,10 +520,10 @@ Get plugin stats:: 'port': 0, 'refresh': 30, 'rtt_warning': None, - 'status': 0.007164, + 'status': 0.013012, 'timeout': 3}] -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/ports/host {'host': ['192.168.0.254']} @@ -526,39 +537,39 @@ Get a specific item when field matchs the given value:: 'port': 0, 'refresh': 30, 'rtt_warning': None, - 'status': 0.007164, + 'status': 0.013012, 'timeout': 3}]} GET processcount ---------------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/processcount - {'pid_max': 0, 'running': 1, 'sleeping': 290, 'thread': 1541, 'total': 352} + {'pid_max': 0, 'running': 1, 'sleeping': 290, 'thread': 1543, 'total': 350} -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/processcount/total - {'total': 352} + {'total': 350} GET processlist --------------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/processlist [{'cmdline': ['/usr/lib/firefox/firefox'], 'cpu_percent': 0.0, - 'cpu_times': pcputimes(user=13600.16, system=6195.46, children_user=1815.12, children_system=383.89, iowait=4.63), + 'cpu_times': pcputimes(user=13640.42, system=6212.95, children_user=1815.12, children_system=383.89, iowait=4.63), 'gids': pgids(real=1000, effective=1000, saved=1000), - 'io_counters': [3538935808, 53054558208, 0, 0, 0], + 'io_counters': [3546947584, 53077909504, 0, 0, 0], 'key': 'pid', - 'memory_info': pmem(rss=518144000, vms=4950585344, shared=142413824, text=643072, lib=0, data=1333030912, dirty=0), - 'memory_percent': 6.60138342035157, + 'memory_info': pmem(rss=504672256, vms=4962189312, shared=144896000, text=643072, lib=0, data=1328582656, dirty=0), + 'memory_percent': 6.429747451422428, 'name': 'GeckoMain', 'nice': 0, - 'num_threads': 154, + 'num_threads': 157, 'pid': 1503459, 'ppid': 3847, 'status': 'S', @@ -583,12 +594,12 @@ Get plugin stats:: 'true', 'tab'], 'cpu_percent': 0.0, - 'cpu_times': pcputimes(user=4731.62, system=1025.04, children_user=0.0, children_system=0.0, iowait=0.87), + 'cpu_times': pcputimes(user=4743.78, system=1026.99, children_user=0.0, children_system=0.0, iowait=0.87), 'gids': pgids(real=1000, effective=1000, saved=1000), - 'io_counters': [67727360, 65536, 0, 0, 0], + 'io_counters': [67805184, 65536, 0, 0, 0], 'key': 'pid', - 'memory_info': pmem(rss=478609408, vms=3810025472, shared=53080064, text=643072, lib=0, data=1046167552, dirty=0), - 'memory_percent': 6.097695256136286, + 'memory_info': pmem(rss=492769280, vms=3810025472, shared=54202368, text=643072, lib=0, data=1046167552, dirty=0), + 'memory_percent': 6.278098279726447, 'name': 'Web Content', 'nice': 0, 'num_threads': 24, @@ -598,7 +609,7 @@ Get plugin stats:: 'time_since_update': 1, 'username': 'nicolargo'}] -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/processlist/pid {'pid': [1503459, @@ -607,10 +618,10 @@ Get a specific field:: 1503674, 1503575, 1503572, - 2195942, 4092, - 1532561, + 2195942, 2195826, + 1532561, 1531912, 2181020, 2064119, @@ -621,17 +632,17 @@ Get a specific field:: 1513179, 2194859, 1484922, - 178587, 1484953, + 178587, 1485034, 2195376, 2195852, 1503546, 2259, 3913, - 2198033, 2193029, 1542400, + 2199185, 1485057, 1542733, 18486, @@ -645,8 +656,8 @@ Get a specific field:: 2430, 2193739, 1541631, - 211213, 2193737, + 211213, 1517056, 348, 4181, @@ -661,9 +672,9 @@ Get a specific field:: 4261, 2196251, 1180, + 2193801, 1158, 1503837, - 2193801, 4266, 4152, 1285, @@ -685,8 +696,8 @@ Get a specific field:: 4284, 1544092, 4078, - 1544088, 255840, + 1544088, 3890, 138395, 4274, @@ -734,13 +745,13 @@ Get a specific field:: 6521, 5587, 18537, - 2198013, 3896, 1544090, 4343, 1173, 4062, 1544091, + 2199173, 3921, 3908, 1163, @@ -778,7 +789,7 @@ Get a specific field:: 4029, 4120, 3868, - 2198032, + 2199184, 1122, 2035, 2229, @@ -936,44 +947,42 @@ Get a specific field:: 2181763, 2185178, 2191796, - 2192521, 2192986, 2193330, 2193618, 2193622, 2194689, 2195181, - 2195212, 2196123, - 2196215, - 2196622, 2197142, 2197157, - 2197268, 2197643, 2197703, - 2197756]} + 2197756, + 2198100, + 2198212, + 2198623]} Get a specific item when field matchs the given value:: # curl http://localhost:61208/api/3/processlist/pid/1503459 {'1503459': [{'cmdline': ['/usr/lib/firefox/firefox'], 'cpu_percent': 0.0, - 'cpu_times': [13600.16, 6195.46, 1815.12, 383.89, 4.63], + 'cpu_times': [13640.42, 6212.95, 1815.12, 383.89, 4.63], 'gids': [1000, 1000, 1000], - 'io_counters': [3538935808, 53054558208, 0, 0, 0], + 'io_counters': [3546947584, 53077909504, 0, 0, 0], 'key': 'pid', - 'memory_info': [518144000, - 4950585344, - 142413824, + 'memory_info': [504672256, + 4962189312, + 144896000, 643072, 0, - 1333030912, + 1328582656, 0], - 'memory_percent': 6.60138342035157, + 'memory_percent': 6.429747451422428, 'name': 'GeckoMain', 'nice': 0, - 'num_threads': 154, + 'num_threads': 157, 'pid': 1503459, 'ppid': 3847, 'status': 'S', @@ -983,7 +992,7 @@ Get a specific item when field matchs the given value:: GET psutilversion ----------------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/psutilversion (5, 8, 0) @@ -991,77 +1000,77 @@ Get plugin stats:: GET quicklook ------------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/quicklook - {'cpu': 29.5, + {'cpu': 32.7, 'cpu_hz': 2025000000.0, - 'cpu_hz_current': 1614371750.0, + 'cpu_hz_current': 1579526250.0, 'cpu_name': 'Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz', - 'mem': 82.8, + 'mem': 83.6, 'percpu': [{'cpu_number': 0, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 82.0, + 'idle': 74.5, 'iowait': 0.0, 'irq': 0.0, 'key': 'cpu_number', 'nice': 0.0, - 'softirq': 0.0, + 'softirq': 6.4, 'steal': 0.0, - 'system': 2.0, - 'total': 18.0, - 'user': 8.0}, + 'system': 3.6, + 'total': 25.5, + 'user': 15.5}, {'cpu_number': 1, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 17.0, + 'idle': 64.8, + 'iowait': 0.0, + 'irq': 0.0, + 'key': 'cpu_number', + 'nice': 0.0, + 'softirq': 3.7, + 'steal': 0.0, + 'system': 2.8, + 'total': 35.2, + 'user': 28.7}, + {'cpu_number': 2, + 'guest': 0.0, + 'guest_nice': 0.0, + 'idle': 89.1, + 'iowait': 1.0, + 'irq': 0.0, + 'key': 'cpu_number', + 'nice': 0.0, + 'softirq': 2.0, + 'steal': 0.0, + 'system': 4.0, + 'total': 10.9, + 'user': 4.0}, + {'cpu_number': 3, + 'guest': 0.0, + 'guest_nice': 0.0, + 'idle': 38.5, 'iowait': 0.0, 'irq': 0.0, 'key': 'cpu_number', 'nice': 0.0, 'softirq': 0.0, 'steal': 0.0, - 'system': 6.0, - 'total': 83.0, - 'user': 71.0}, - {'cpu_number': 2, - 'guest': 0.0, - 'guest_nice': 0.0, - 'idle': 87.0, - 'iowait': 0.0, - 'irq': 0.0, - 'key': 'cpu_number', - 'nice': 0.0, - 'softirq': 3.0, - 'steal': 0.0, - 'system': 3.0, - 'total': 13.0, - 'user': 3.0}, - {'cpu_number': 3, - 'guest': 0.0, - 'guest_nice': 0.0, - 'idle': 80.0, - 'iowait': 0.0, - 'irq': 0.0, - 'key': 'cpu_number', - 'nice': 0.0, - 'softirq': 4.0, - 'steal': 0.0, - 'system': 3.0, - 'total': 20.0, - 'user': 9.0}], + 'system': 2.9, + 'total': 61.5, + 'user': 58.7}], 'swap': 20.3} -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/quicklook/cpu - {'cpu': 29.5} + {'cpu': 32.7} GET sensors ----------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/sensors [{'critical': 105, @@ -1079,7 +1088,7 @@ Get plugin stats:: 'value': 29, 'warning': 105}] -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/sensors/label {'label': ['acpitz 1', @@ -1106,7 +1115,7 @@ Get a specific item when field matchs the given value:: GET system ---------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/system {'hostname': 'XPS13-9333', @@ -1116,7 +1125,7 @@ Get plugin stats:: 'os_version': '5.4.0-77-generic', 'platform': '64bit'} -Get a specific field:: +Get a specific field: # curl http://localhost:61208/api/3/system/os_name {'os_name': 'Linux'} @@ -1124,15 +1133,15 @@ Get a specific field:: GET uptime ---------- -Get plugin stats:: +Get plugin stats: # curl http://localhost:61208/api/3/uptime - {'seconds': 11020020} + {'seconds': 11020705} GET all stats ------------- -Get all Glances stats:: +Get all Glances stats: # curl http://localhost:61208/api/3/all Return a very big dictionnary (avoid using this request, performances will be poor)... @@ -1140,41 +1149,41 @@ Get all Glances stats:: GET stats history ----------------- -History of a plugin:: +History of a plugin: # curl http://localhost:61208/api/3/cpu/history - {'system': [['2022-01-15T11:22:45.669711', 4.4], - ['2022-01-15T11:22:46.769745', 4.4], - ['2022-01-15T11:22:47.935395', 3.8]], - 'user': [['2022-01-15T11:22:45.669687', 23.3], - ['2022-01-15T11:22:46.769738', 23.3], - ['2022-01-15T11:22:47.935388', 7.9]]} + {'system': [['2022-01-15T11:34:11.476949', 5.0], + ['2022-01-15T11:34:12.573555', 5.0], + ['2022-01-15T11:34:13.731339', 3.9]], + 'user': [['2022-01-15T11:34:11.476935', 25.2], + ['2022-01-15T11:34:12.573548', 25.2], + ['2022-01-15T11:34:13.731331', 8.4]]} -Limit history to last 2 values:: +Limit history to last 2 values: # curl http://localhost:61208/api/3/cpu/history/2 - {'system': [['2022-01-15T11:22:46.769745', 4.4], - ['2022-01-15T11:22:47.935395', 3.8]], - 'user': [['2022-01-15T11:22:46.769738', 23.3], - ['2022-01-15T11:22:47.935388', 7.9]]} + {'system': [['2022-01-15T11:34:12.573555', 5.0], + ['2022-01-15T11:34:13.731339', 3.9]], + 'user': [['2022-01-15T11:34:12.573548', 25.2], + ['2022-01-15T11:34:13.731331', 8.4]]} -History for a specific field:: +History for a specific field: # curl http://localhost:61208/api/3/cpu/system/history - {'system': [['2022-01-15T11:22:45.669711', 4.4], - ['2022-01-15T11:22:46.769745', 4.4], - ['2022-01-15T11:22:47.935395', 3.8]]} + {'system': [['2022-01-15T11:34:11.476949', 5.0], + ['2022-01-15T11:34:12.573555', 5.0], + ['2022-01-15T11:34:13.731339', 3.9]]} Limit history for a specific field to last 2 values:: # curl http://localhost:61208/api/3/cpu/system/history - {'system': [['2022-01-15T11:22:46.769745', 4.4], - ['2022-01-15T11:22:47.935395', 3.8]]} + {'system': [['2022-01-15T11:34:12.573555', 5.0], + ['2022-01-15T11:34:13.731339', 3.9]]} GET limits (used for thresholds) -------------------------------- -All limits/thresholds:: +All limits/thresholds: # curl http://localhost:61208/api/3/all/limits {'alert': {'history_size': 3600.0}, @@ -1360,7 +1369,7 @@ All limits/thresholds:: 'wifi_hide': ['lo', 'docker.*'], 'wifi_warning': -75.0}} -Limits/thresholds for the cpu plugin:: +Limits/thresholds for the cpu plugin: # curl http://localhost:61208/api/3/cpu/limits {'cpu_ctx_switches_careful': 160000.0, From 00c65933ae1d0ebd3e72dc30fc3c215a83dfaae2 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sat, 15 Jan 2022 11:38:21 +0100 Subject: [PATCH 3/5] Update docs (again) for API. Related to issue #1988 --- docs/api.rst | 565 ++++++++++++----------- glances/outputs/glances_stdout_apidoc.py | 20 +- 2 files changed, 304 insertions(+), 281 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 25f6a9cd..8942d3e0 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -17,7 +17,7 @@ GET API status This entry point should be used to check the API status. It will return nothing but a 200 return code if everythin is OK. -Get the Rest API status: +Get the Rest API status:: # curl -I http://localhost:61208/api/3/status 'HTTP/1.0 200 OK' @@ -25,7 +25,7 @@ Get the Rest API status: GET plugins list ---------------- -Get the plugins list: +Get the plugins list:: # curl http://localhost:61208/api/3/pluginslist ['alert', @@ -63,17 +63,17 @@ Get the plugins list: GET alert --------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/alert - [[1642242851.0, + [[1642243083.0, -1, 'WARNING', 'MEM', - 83.60534685964623, - 83.60534685964623, - 83.60534685964623, - 83.60534685964623, + 83.71248235499787, + 83.71248235499787, + 83.71248235499787, + 83.71248235499787, 1, [], '', @@ -82,7 +82,7 @@ Get plugin stats: GET amps -------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/amps [{'count': 0, @@ -93,7 +93,7 @@ Get plugin stats: 'refresh': 3.0, 'regex': True, 'result': None, - 'timer': 0.26227450370788574}, + 'timer': 0.41446375846862793}, {'count': 0, 'countmax': 20.0, 'countmin': None, @@ -102,9 +102,9 @@ Get plugin stats: 'refresh': 3.0, 'regex': True, 'result': None, - 'timer': 0.2620673179626465}] + 'timer': 0.4140021800994873}] -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/amps/name {'name': ['Dropbox', 'Python', 'Conntrack', 'Nginx', 'Systemd', 'SystemV']} @@ -120,12 +120,12 @@ Get a specific item when field matchs the given value:: 'refresh': 3.0, 'regex': True, 'result': None, - 'timer': 0.26227450370788574}]} + 'timer': 0.41446375846862793}]} GET core -------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/core {'log': 4, 'phys': 2} @@ -135,7 +135,7 @@ Fields descriptions: * **phys**: Number of physical cores (hyper thread CPUs are excluded) (unit is *number*) * **log**: Number of logical CPUs. A logical CPU is the number of physical cores multiplied by the number of threads that can run on each core (unit is *number*) -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/core/phys {'phys': 2} @@ -143,26 +143,26 @@ Get a specific field: GET cpu ------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/cpu {'cpucore': 4, 'ctx_switches': 0, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 67.0, + 'idle': 57.7, 'interrupts': 0, - 'iowait': 0.4, + 'iowait': 0.7, 'irq': 0.0, 'nice': 0.0, 'soft_interrupts': 0, - 'softirq': 2.5, + 'softirq': 2.1, 'steal': 0.0, 'syscalls': 0, - 'system': 5.0, + 'system': 5.3, 'time_since_update': 1, - 'total': 32.7, - 'user': 25.2} + 'total': 43.1, + 'user': 34.2} Fields descriptions: @@ -181,15 +181,15 @@ Fields descriptions: * **cpucore**: Total number of CPU core (unit is *number*) * **time_since_update**: Number of seconds since last update (unit is *seconds*) -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/cpu/total - {'total': 32.7} + {'total': 43.1} GET diskio ---------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/diskio [{'disk_name': 'sda', @@ -207,7 +207,7 @@ Get plugin stats: 'write_bytes': 0, 'write_count': 0}] -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/diskio/disk_name {'disk_name': ['sda', 'sda1', 'sda2', 'sda5', 'dm-0', 'dm-1']} @@ -226,7 +226,7 @@ Get a specific item when field matchs the given value:: GET docker ---------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/docker [{'Command': ['/entrypoint.sh', 'influxd'], @@ -238,7 +238,7 @@ Get plugin stats: 'io_r': None, 'io_w': None, 'key': 'name', - 'memory_usage': 22781952, + 'memory_usage': None, 'name': 'dockerinfluxdb2grafana_influxdb_1', 'network_rx': None, 'network_tx': None}, @@ -259,19 +259,19 @@ Get plugin stats: GET fs ------ -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/fs [{'device_name': '/dev/mapper/ubuntu--gnome--vg-root', - 'free': 5851906048, + 'free': 5850710016, 'fs_type': 'ext4', 'key': 'mnt_point', 'mnt_point': '/', 'percent': 97.5, 'size': 243396149248, - 'used': 225156788224}] + 'used': 225157984256}] -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/fs/mnt_point {'mnt_point': ['/']} @@ -280,18 +280,18 @@ Get a specific item when field matchs the given value:: # curl http://localhost:61208/api/3/fs/mnt_point// {'/': [{'device_name': '/dev/mapper/ubuntu--gnome--vg-root', - 'free': 5851906048, + 'free': 5850710016, 'fs_type': 'ext4', 'key': 'mnt_point', 'mnt_point': '/', 'percent': 97.5, 'size': 243396149248, - 'used': 225156788224}]} + 'used': 225157984256}]} GET ip ------ -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/ip {'address': '192.168.0.33', @@ -300,7 +300,7 @@ Get plugin stats: 'mask_cidr': 24, 'public_address': '91.166.228.228'} -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/ip/address {'address': '192.168.0.33'} @@ -308,10 +308,10 @@ Get a specific field: GET load -------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/load - {'cpucore': 4, 'min1': 1.53, 'min15': 1.55, 'min5': 1.61} + {'cpucore': 4, 'min1': 2.36, 'min15': 1.56, 'min5': 1.67} Fields descriptions: @@ -320,27 +320,27 @@ Fields descriptions: * **min15**: Average sum of the number of processes waiting in the run-queue plus the number currently executing over 15 minutes (unit is *float*) * **cpucore**: Total number of CPU core (unit is *number*) -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/load/min1 - {'min1': 1.53} + {'min1': 2.36} GET mem ------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/mem - {'active': 5850939392, - 'available': 1286819840, - 'buffers': 313094144, - 'cached': 1794244608, - 'free': 1286819840, - 'inactive': 996773888, - 'percent': 83.6, - 'shared': 715137024, + {'active': 5074616320, + 'available': 1278410752, + 'buffers': 79331328, + 'cached': 1258463232, + 'free': 1278410752, + 'inactive': 1120292864, + 'percent': 83.7, + 'shared': 721162240, 'total': 7849021440, - 'used': 6562201600} + 'used': 6570610688} Fields descriptions: @@ -356,7 +356,7 @@ Fields descriptions: * **wired**: *(BSD, macOS)*: memory that is marked to always stay in RAM. It is never moved to disk (unit is *bytes*) * **shared**: *(BSD)*: memory that may be simultaneously accessed by multiple processes (unit is *bytes*) -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/mem/total {'total': 7849021440} @@ -364,16 +364,16 @@ Get a specific field: GET memswap ----------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/memswap - {'free': 6443831296, - 'percent': 20.3, - 'sin': 5678075904, - 'sout': 9877434368, + {'free': 6375411712, + 'percent': 21.1, + 'sin': 5680271360, + 'sout': 9946386432, 'time_since_update': 1, 'total': 8082419712, - 'used': 1638588416} + 'used': 1707008000} Fields descriptions: @@ -385,7 +385,7 @@ Fields descriptions: * **sout**: The number of bytes the system has swapped out from disk (cumulative) (unit is *bytes*) * **time_since_update**: Number of seconds since last update (unit is *seconds*) -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/memswap/total {'total': 8082419712} @@ -393,13 +393,13 @@ Get a specific field: GET network ----------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/network [{'alias': None, - 'cumulative_cx': 8501233, + 'cumulative_cx': 8512503, 'cumulative_rx': 21687, - 'cumulative_tx': 8479546, + 'cumulative_tx': 8490816, 'cx': 0, 'interface_name': 'vetha426f3c', 'is_up': True, @@ -409,9 +409,9 @@ Get plugin stats: 'time_since_update': 1, 'tx': 0}, {'alias': None, - 'cumulative_cx': 12641380, + 'cumulative_cx': 12652650, 'cumulative_rx': 1086025, - 'cumulative_tx': 11555355, + 'cumulative_tx': 11566625, 'cx': 0, 'interface_name': 'veth5d13ef7', 'is_up': True, @@ -433,7 +433,7 @@ Fields descriptions: * **is_up**: Is the interface up ? (unit is *bool*) * **time_since_update**: Number of seconds since last update (unit is *seconds*) -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/network/interface_name {'interface_name': ['vetha426f3c', @@ -450,9 +450,9 @@ Get a specific item when field matchs the given value:: # curl http://localhost:61208/api/3/network/interface_name/vetha426f3c {'vetha426f3c': [{'alias': None, - 'cumulative_cx': 8501233, + 'cumulative_cx': 8512503, 'cumulative_rx': 21687, - 'cumulative_tx': 8479546, + 'cumulative_tx': 8490816, 'cx': 0, 'interface_name': 'vetha426f3c', 'is_up': True, @@ -465,45 +465,45 @@ Get a specific item when field matchs the given value:: GET now ------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/now - '2022-01-15 11:34:11 CET' + '2022-01-15 11:38:03 CET' GET percpu ---------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/percpu [{'cpu_number': 0, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 74.5, + 'idle': 70.9, 'iowait': 0.0, 'irq': 0.0, 'key': 'cpu_number', 'nice': 0.0, - 'softirq': 6.4, + 'softirq': 0.9, 'steal': 0.0, - 'system': 3.6, - 'total': 25.5, - 'user': 15.5}, + 'system': 2.6, + 'total': 29.1, + 'user': 25.6}, {'cpu_number': 1, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 64.8, - 'iowait': 0.0, + 'idle': 53.3, + 'iowait': 0.8, 'irq': 0.0, 'key': 'cpu_number', 'nice': 0.0, - 'softirq': 3.7, + 'softirq': 3.3, 'steal': 0.0, - 'system': 2.8, - 'total': 35.2, - 'user': 28.7}] + 'system': 4.2, + 'total': 46.7, + 'user': 38.3}] -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/percpu/cpu_number {'cpu_number': [0, 1, 2, 3]} @@ -511,7 +511,7 @@ Get a specific field: GET ports --------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/ports [{'description': 'DefaultGateway', @@ -520,10 +520,10 @@ Get plugin stats: 'port': 0, 'refresh': 30, 'rtt_warning': None, - 'status': 0.013012, + 'status': 0.012442, 'timeout': 3}] -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/ports/host {'host': ['192.168.0.254']} @@ -537,45 +537,29 @@ Get a specific item when field matchs the given value:: 'port': 0, 'refresh': 30, 'rtt_warning': None, - 'status': 0.013012, + 'status': 0.012442, 'timeout': 3}]} GET processcount ---------------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/processcount - {'pid_max': 0, 'running': 1, 'sleeping': 290, 'thread': 1543, 'total': 350} + {'pid_max': 0, 'running': 1, 'sleeping': 290, 'thread': 1534, 'total': 351} -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/processcount/total - {'total': 350} + {'total': 351} GET processlist --------------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/processlist - [{'cmdline': ['/usr/lib/firefox/firefox'], - 'cpu_percent': 0.0, - 'cpu_times': pcputimes(user=13640.42, system=6212.95, children_user=1815.12, children_system=383.89, iowait=4.63), - 'gids': pgids(real=1000, effective=1000, saved=1000), - 'io_counters': [3546947584, 53077909504, 0, 0, 0], - 'key': 'pid', - 'memory_info': pmem(rss=504672256, vms=4962189312, shared=144896000, text=643072, lib=0, data=1328582656, dirty=0), - 'memory_percent': 6.429747451422428, - 'name': 'GeckoMain', - 'nice': 0, - 'num_threads': 157, - 'pid': 1503459, - 'ppid': 3847, - 'status': 'S', - 'time_since_update': 1, - 'username': 'nicolargo'}, - {'cmdline': ['/usr/lib/firefox/firefox', + [{'cmdline': ['/usr/lib/firefox/firefox', '-contentproc', '-childID', '14', @@ -594,12 +578,12 @@ Get plugin stats: 'true', 'tab'], 'cpu_percent': 0.0, - 'cpu_times': pcputimes(user=4743.78, system=1026.99, children_user=0.0, children_system=0.0, iowait=0.87), + 'cpu_times': pcputimes(user=4747.52, system=1027.52, children_user=0.0, children_system=0.0, iowait=0.87), 'gids': pgids(real=1000, effective=1000, saved=1000), 'io_counters': [67805184, 65536, 0, 0, 0], 'key': 'pid', - 'memory_info': pmem(rss=492769280, vms=3810025472, shared=54202368, text=643072, lib=0, data=1046167552, dirty=0), - 'memory_percent': 6.278098279726447, + 'memory_info': pmem(rss=457805824, vms=3803693056, shared=28733440, text=643072, lib=0, data=1046167552, dirty=0), + 'memory_percent': 5.832648407187941, 'name': 'Web Content', 'nice': 0, 'num_threads': 24, @@ -607,189 +591,210 @@ Get plugin stats: 'ppid': 1503459, 'status': 'S', 'time_since_update': 1, + 'username': 'nicolargo'}, + {'cmdline': ['/usr/share/code/code', + '--ms-enable-electron-run-as-node', + '--inspect-port=0', + '/usr/share/code/resources/app/out/bootstrap-fork', + '--type=extensionHost', + '--skipWorkspaceStorageLock'], + 'cpu_percent': 0.0, + 'cpu_times': pcputimes(user=91.5, system=12.44, children_user=23.98, children_system=13.18, iowait=0.06), + 'gids': pgids(real=1000, effective=1000, saved=1000), + 'io_counters': [189956096, 21913600, 0, 0, 0], + 'key': 'pid', + 'memory_info': pmem(rss=441901056, vms=49750560768, shared=27869184, text=125038592, lib=0, data=706924544, dirty=0), + 'memory_percent': 5.630014637850192, + 'name': 'code', + 'nice': 0, + 'num_threads': 14, + 'pid': 2195844, + 'ppid': 1484922, + 'status': 'S', + 'time_since_update': 1, 'username': 'nicolargo'}] -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/processlist/pid - {'pid': [1503459, - 1513121, + {'pid': [1513121, 2195844, + 1503459, 1503674, 1503575, 1503572, 4092, 2195942, - 2195826, 1532561, 1531912, + 2195826, 2181020, 2064119, - 1513158, 2172756, - 2196630, + 1513158, 1531883, 1513179, - 2194859, + 2196630, 1484922, 1484953, 178587, + 2194859, 1485034, 2195376, - 2195852, 1503546, - 2259, + 2195852, 3913, - 2193029, - 1542400, - 2199185, - 1485057, + 2259, + 2199594, 1542733, - 18486, + 2193029, 3934, - 1542791, + 18486, + 1542400, 3855, + 1485057, 1531913, - 1484973, + 1542791, 1479304, 3336, 2430, - 2193739, - 1541631, 2193737, 211213, - 1517056, - 348, - 4181, + 1484973, + 1541631, 4265, - 4928, + 4181, 4241, - 1139, + 4928, 3853, - 2193803, + 2193739, + 1139, 1, 4116, 4261, - 2196251, 1180, - 2193801, 1158, + 1517056, 1503837, - 4266, + 2196251, 4152, + 348, 1285, + 4266, + 2193801, 3847, - 4287, - 2196261, - 237994, - 4374, - 2196264, - 3764, + 2193803, 4143, - 3863, - 1181, - 1544077, + 4287, 4164, - 2195625, - 4264, 1138, - 4284, - 1544092, - 4078, - 255840, - 1544088, - 3890, - 138395, - 4274, - 3858, - 5573, - 4332, - 4129, - 1575, - 1008, - 1324, - 4196, - 1548391, - 1176, - 1541718, - 1484926, - 1526429, - 1520402, - 1354, - 4279, - 2216, - 4252, - 4123, + 3764, + 3863, 4121, - 600490, + 237994, + 255840, + 3858, + 4078, + 1544088, + 4274, + 4129, + 4332, + 2196261, + 2195625, + 2196264, + 1575, + 4374, + 1008, + 4284, + 1548391, + 4264, + 1544077, + 3890, + 1544092, + 1484926, + 1181, + 5573, + 1541718, + 4196, + 1324, + 1176, + 4279, + 138395, + 1354, 1484927, - 1537927, + 2216, 3927, - 3902, 1147, - 1484929, + 3902, + 600490, 1153, 4048, - 4272, + 4252, 67406, 3932, 4276, + 4272, 3959, 1129, + 1537927, 4160, - 1542748, - 4339, - 4263, + 4123, 4340, 1150, + 4339, 6521, - 5587, 18537, - 3896, - 1544090, - 4343, + 4263, 1173, + 1526429, 4062, - 1544091, - 2199173, + 1544090, + 3896, + 4343, 3921, - 3908, - 1163, - 4137, + 1544091, + 2199577, 1451, + 4137, + 1163, 1178, - 2196267, - 1010, + 1484929, + 5587, 344713, + 1010, 4273, - 1182, - 4267, 4281, 1007, + 3908, 1135, + 1520402, 4057, - 213050, + 4267, + 2196267, + 1182, 3883, 344711, 1209, 3339, 4262, 2230, - 172714, 4072, - 1542688, + 172714, 1132, 4260, 4285, 138445, + 213050, 1166, + 1542748, 1542646, 4141, 344710, + 1542688, 4029, 4120, 3868, - 2199184, + 2199593, 1122, 2035, 2229, @@ -956,35 +961,53 @@ Get a specific field: 2196123, 2197142, 2197157, - 2197643, 2197703, 2197756, 2198100, 2198212, - 2198623]} + 2198623, + 2199268, + 2199269]} Get a specific item when field matchs the given value:: - # curl http://localhost:61208/api/3/processlist/pid/1503459 - {'1503459': [{'cmdline': ['/usr/lib/firefox/firefox'], + # curl http://localhost:61208/api/3/processlist/pid/1513121 + {'1513121': [{'cmdline': ['/usr/lib/firefox/firefox', + '-contentproc', + '-childID', + '14', + '-isForBrowser', + '-prefsLen', + '8563', + '-prefMapSize', + '252236', + '-jsInitLen', + '278884', + '-parentBuildID', + '20211215221728', + '-appDir', + '/usr/lib/firefox/browser', + '1503459', + 'true', + 'tab'], 'cpu_percent': 0.0, - 'cpu_times': [13640.42, 6212.95, 1815.12, 383.89, 4.63], + 'cpu_times': [4747.52, 1027.52, 0.0, 0.0, 0.87], 'gids': [1000, 1000, 1000], - 'io_counters': [3546947584, 53077909504, 0, 0, 0], + 'io_counters': [67805184, 65536, 0, 0, 0], 'key': 'pid', - 'memory_info': [504672256, - 4962189312, - 144896000, + 'memory_info': [457805824, + 3803693056, + 28733440, 643072, 0, - 1328582656, + 1046167552, 0], - 'memory_percent': 6.429747451422428, - 'name': 'GeckoMain', + 'memory_percent': 5.832648407187941, + 'name': 'Web Content', 'nice': 0, - 'num_threads': 157, - 'pid': 1503459, - 'ppid': 3847, + 'num_threads': 24, + 'pid': 1513121, + 'ppid': 1503459, 'status': 'S', 'time_since_update': 1, 'username': 'nicolargo'}]} @@ -992,7 +1015,7 @@ Get a specific item when field matchs the given value:: GET psutilversion ----------------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/psutilversion (5, 8, 0) @@ -1000,77 +1023,77 @@ Get plugin stats: GET quicklook ------------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/quicklook - {'cpu': 32.7, + {'cpu': 43.1, 'cpu_hz': 2025000000.0, - 'cpu_hz_current': 1579526250.0, + 'cpu_hz_current': 1420721250.0, 'cpu_name': 'Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz', - 'mem': 83.6, + 'mem': 83.7, 'percpu': [{'cpu_number': 0, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 74.5, + 'idle': 70.9, 'iowait': 0.0, 'irq': 0.0, 'key': 'cpu_number', 'nice': 0.0, - 'softirq': 6.4, + 'softirq': 0.9, 'steal': 0.0, - 'system': 3.6, - 'total': 25.5, - 'user': 15.5}, + 'system': 2.6, + 'total': 29.1, + 'user': 25.6}, {'cpu_number': 1, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 64.8, - 'iowait': 0.0, + 'idle': 53.3, + 'iowait': 0.8, 'irq': 0.0, 'key': 'cpu_number', 'nice': 0.0, - 'softirq': 3.7, + 'softirq': 3.3, 'steal': 0.0, - 'system': 2.8, - 'total': 35.2, - 'user': 28.7}, + 'system': 4.2, + 'total': 46.7, + 'user': 38.3}, {'cpu_number': 2, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 89.1, - 'iowait': 1.0, + 'idle': 54.7, + 'iowait': 2.6, 'irq': 0.0, 'key': 'cpu_number', 'nice': 0.0, - 'softirq': 2.0, + 'softirq': 1.7, 'steal': 0.0, - 'system': 4.0, - 'total': 10.9, - 'user': 4.0}, + 'system': 3.4, + 'total': 45.3, + 'user': 37.6}, {'cpu_number': 3, 'guest': 0.0, 'guest_nice': 0.0, - 'idle': 38.5, + 'idle': 45.5, 'iowait': 0.0, 'irq': 0.0, 'key': 'cpu_number', 'nice': 0.0, 'softirq': 0.0, 'steal': 0.0, - 'system': 2.9, - 'total': 61.5, - 'user': 58.7}], - 'swap': 20.3} + 'system': 5.8, + 'total': 54.5, + 'user': 48.8}], + 'swap': 21.1} -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/quicklook/cpu - {'cpu': 32.7} + {'cpu': 43.1} GET sensors ----------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/sensors [{'critical': 105, @@ -1088,7 +1111,7 @@ Get plugin stats: 'value': 29, 'warning': 105}] -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/sensors/label {'label': ['acpitz 1', @@ -1115,7 +1138,7 @@ Get a specific item when field matchs the given value:: GET system ---------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/system {'hostname': 'XPS13-9333', @@ -1125,7 +1148,7 @@ Get plugin stats: 'os_version': '5.4.0-77-generic', 'platform': '64bit'} -Get a specific field: +Get a specific field:: # curl http://localhost:61208/api/3/system/os_name {'os_name': 'Linux'} @@ -1133,15 +1156,15 @@ Get a specific field: GET uptime ---------- -Get plugin stats: +Get plugin stats:: # curl http://localhost:61208/api/3/uptime - {'seconds': 11020705} + {'seconds': 11020937} GET all stats ------------- -Get all Glances stats: +Get all Glances stats:: # curl http://localhost:61208/api/3/all Return a very big dictionnary (avoid using this request, performances will be poor)... @@ -1149,41 +1172,41 @@ Get all Glances stats: GET stats history ----------------- -History of a plugin: +History of a plugin:: # curl http://localhost:61208/api/3/cpu/history - {'system': [['2022-01-15T11:34:11.476949', 5.0], - ['2022-01-15T11:34:12.573555', 5.0], - ['2022-01-15T11:34:13.731339', 3.9]], - 'user': [['2022-01-15T11:34:11.476935', 25.2], - ['2022-01-15T11:34:12.573548', 25.2], - ['2022-01-15T11:34:13.731331', 8.4]]} + {'system': [['2022-01-15T11:38:03.818557', 5.3], + ['2022-01-15T11:38:04.940621', 5.3], + ['2022-01-15T11:38:06.106691', 4.6]], + 'user': [['2022-01-15T11:38:03.818543', 34.2], + ['2022-01-15T11:38:04.940614', 34.2], + ['2022-01-15T11:38:06.106677', 10.5]]} -Limit history to last 2 values: +Limit history to last 2 values:: # curl http://localhost:61208/api/3/cpu/history/2 - {'system': [['2022-01-15T11:34:12.573555', 5.0], - ['2022-01-15T11:34:13.731339', 3.9]], - 'user': [['2022-01-15T11:34:12.573548', 25.2], - ['2022-01-15T11:34:13.731331', 8.4]]} + {'system': [['2022-01-15T11:38:04.940621', 5.3], + ['2022-01-15T11:38:06.106691', 4.6]], + 'user': [['2022-01-15T11:38:04.940614', 34.2], + ['2022-01-15T11:38:06.106677', 10.5]]} -History for a specific field: +History for a specific field:: # curl http://localhost:61208/api/3/cpu/system/history - {'system': [['2022-01-15T11:34:11.476949', 5.0], - ['2022-01-15T11:34:12.573555', 5.0], - ['2022-01-15T11:34:13.731339', 3.9]]} + {'system': [['2022-01-15T11:38:03.818557', 5.3], + ['2022-01-15T11:38:04.940621', 5.3], + ['2022-01-15T11:38:06.106691', 4.6]]} Limit history for a specific field to last 2 values:: # curl http://localhost:61208/api/3/cpu/system/history - {'system': [['2022-01-15T11:34:12.573555', 5.0], - ['2022-01-15T11:34:13.731339', 3.9]]} + {'system': [['2022-01-15T11:38:04.940621', 5.3], + ['2022-01-15T11:38:06.106691', 4.6]]} GET limits (used for thresholds) -------------------------------- -All limits/thresholds: +All limits/thresholds:: # curl http://localhost:61208/api/3/all/limits {'alert': {'history_size': 3600.0}, @@ -1369,7 +1392,7 @@ All limits/thresholds: 'wifi_hide': ['lo', 'docker.*'], 'wifi_warning': -75.0}} -Limits/thresholds for the cpu plugin: +Limits/thresholds for the cpu plugin:: # curl http://localhost:61208/api/3/cpu/limits {'cpu_ctx_switches_careful': 160000.0, diff --git a/glances/outputs/glances_stdout_apidoc.py b/glances/outputs/glances_stdout_apidoc.py index 6a7e4529..77873fbb 100644 --- a/glances/outputs/glances_stdout_apidoc.py +++ b/glances/outputs/glances_stdout_apidoc.py @@ -61,7 +61,7 @@ def print_api_status(): print('This entry point should be used to check the API status.') print('It will return nothing but a 200 return code if everythin is OK.') print('') - print('Get the Rest API status:') + print('Get the Rest API status::') print('') print(' # curl -I {}/status'.format(API_URL)) print(indent_stat('HTTP/1.0 200 OK')) @@ -74,7 +74,7 @@ def print_plugins_list(stat): print(sub_title) print('-' * len(sub_title)) print('') - print('Get the plugins list:') + print('Get the plugins list::') print('') print(' # curl {}/pluginslist'.format(API_URL)) print(indent_stat(stat)) @@ -87,7 +87,7 @@ def print_plugin_export(plugin, stat_export): print('-' * len(sub_title)) print('') - print('Get plugin stats:') + print('Get plugin stats::') print('') print(' # curl {}/{}'.format(API_URL, plugin)) print(indent_stat(stat_export)) @@ -131,7 +131,7 @@ def print_plugin_item_value(plugin, stat, stat_export): value = stat_item[item][0] else: value = stat_item[item] - print('Get a specific field:') + print('Get a specific field::') print('') print(' # curl {}/{}/{}'.format(API_URL, plugin, item)) print(indent_stat(stat_item)) @@ -149,7 +149,7 @@ def print_all(): print(sub_title) print('-' * len(sub_title)) print('') - print('Get all Glances stats:') + print('Get all Glances stats::') print('') print(' # curl {}/all'.format(API_URL)) print(' Return a very big dictionnary (avoid using this request, performances will be poor)...') @@ -165,17 +165,17 @@ def print_history(stats): print(sub_title) print('-' * len(sub_title)) print('') - print('History of a plugin:') + print('History of a plugin::') print('') print(' # curl {}/cpu/history'.format(API_URL)) print(indent_stat(json.loads(stats.get_plugin('cpu').get_stats_history(nb=3)))) print('') - print('Limit history to last 2 values:') + print('Limit history to last 2 values::') print('') print(' # curl {}/cpu/history/2'.format(API_URL)) print(indent_stat(json.loads(stats.get_plugin('cpu').get_stats_history(nb=2)))) print('') - print('History for a specific field:') + print('History for a specific field::') print('') print(' # curl {}/cpu/system/history'.format(API_URL)) print(indent_stat(json.loads(stats.get_plugin('cpu').get_stats_history('system')))) @@ -192,12 +192,12 @@ def print_limits(stats): print(sub_title) print('-' * len(sub_title)) print('') - print('All limits/thresholds:') + print('All limits/thresholds::') print('') print(' # curl {}/all/limits'.format(API_URL)) print(indent_stat(stats.getAllLimitsAsDict())) print('') - print('Limits/thresholds for the cpu plugin:') + print('Limits/thresholds for the cpu plugin::') print('') print(' # curl {}/cpu/limits'.format(API_URL)) print(indent_stat(stats.get_plugin('cpu').limits)) From 30c93b4a9521e74f7cffe7faa04eee2b4f7f1bd9 Mon Sep 17 00:00:00 2001 From: myersg86 Date: Sat, 15 Jan 2022 12:40:46 -0700 Subject: [PATCH 4/5] Fix typo in CONTRIBUTING.md CONTRIBUTING.md:61: usefull -> useful --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8a267e7f..ad1282c4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,7 +58,7 @@ Example: > 2. This is the second step > 3. Further steps, etc. > -> Screenshot (if usefull) +> Screenshot (if useful) > > Any other information you want to share that is relevant to the issue being > reported. This might include the lines of code that you have identified as From f9697e8b8e41f10623c6be24515f0428b0406e56 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sun, 23 Jan 2022 10:42:43 +0100 Subject: [PATCH 5/5] Including battery and AC adapter health in Glances #1049 --- glances/main.py | 7 ++++ glances/outputs/glances_unicode.py | 37 +++++++++++++++++++ glances/plugins/glances_plugin.py | 7 ++-- glances/plugins/glances_processlist.py | 4 +- glances/plugins/glances_sensors.py | 20 +++++++++- glances/plugins/sensors/glances_batpercent.py | 16 +++++++- 6 files changed, 83 insertions(+), 8 deletions(-) create mode 100644 glances/outputs/glances_unicode.py diff --git a/glances/main.py b/glances/main.py index 539b89eb..eb9c2407 100644 --- a/glances/main.py +++ b/glances/main.py @@ -451,6 +451,13 @@ Examples of use: dest='sparkline', help='display sparklines instead of bar in the curses interface', ) + parser.add_argument( + '--disable-unicode', + action='store_true', + default=False, + dest='disable_unicode', + help='disable unicode characters in the curses interface', + ) parser.add_argument( '--theme-white', action='store_true', diff --git a/glances/outputs/glances_unicode.py b/glances/outputs/glances_unicode.py new file mode 100644 index 00000000..e8b103c3 --- /dev/null +++ b/glances/outputs/glances_unicode.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# +# This file is part of Glances. +# +# Copyright (C) 2022 Nicolargo +# +# Glances is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Glances is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . + +"""Manage unicode message for Glances output.""" + +_unicode_message = { + 'ARROW_LEFT': [u'\u2190', u'<'], + 'ARROW_RIGHT': [u'\u2192', u'>'], + 'ARROW_UP': [u'\u2191', u'^'], + 'ARROW_DOWN': [u'\u2193', u'v'], + 'CHECK': [u'\u2713', u''], + 'PROCESS_SELECTOR': [u'>', u'>'], +} + + +def unicode_message(key, args=None): + """Return the unicode message for the given key.""" + if args and hasattr(args, 'disable_unicode') and args.disable_unicode: + return _unicode_message[key][1] + else: + return _unicode_message[key][0] diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index 589e1070..10f9c08d 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -28,13 +28,14 @@ import json import copy from operator import itemgetter -from glances.compat import iterkeys, itervalues, listkeys, map, mean, nativestr +from glances.compat import iterkeys, itervalues, listkeys, map, mean, nativestr, u from glances.actions import GlancesActions from glances.history import GlancesHistory from glances.logger import logger from glances.events import glances_events from glances.thresholds import glances_thresholds from glances.timer import Counter, Timer +from glances.outputs.glances_unicode import unicode_message fields_unit_short = {'percent': '%'} @@ -1137,9 +1138,9 @@ class GlancesPlugin(object): if trend is None: ret = ' ' elif trend > significant: - ret = '/' + ret = unicode_message('ARROW_UP', self.args) elif trend < -significant: - ret = '\\' + ret = unicode_message('ARROW_DOWN', self.args) return ret def _check_decorator(fct): diff --git a/glances/plugins/glances_processlist.py b/glances/plugins/glances_processlist.py index 6f48496b..774e665a 100644 --- a/glances/plugins/glances_processlist.py +++ b/glances/plugins/glances_processlist.py @@ -26,6 +26,7 @@ from glances.logger import logger from glances.globals import WINDOWS from glances.compat import key_exist_value_not_none_not_v from glances.processes import glances_processes, sort_stats +from glances.outputs.glances_unicode import unicode_message from glances.plugins.glances_core import Plugin as CorePlugin from glances.plugins.glances_plugin import GlancesPlugin @@ -363,7 +364,8 @@ class Plugin(GlancesPlugin): # * display a special character at the beginning of the line # * underline the command name if args.is_standalone: - ret.append(self.curse_add_line('>' if selected else ' ', 'SELECTED')) + ret.append(self.curse_add_line(unicode_message('PROCESS_SELECTOR') if selected else ' ', + 'SELECTED')) # CPU ret.append(self._get_process_curses_cpu(p, selected, args)) diff --git a/glances/plugins/glances_sensors.py b/glances/plugins/glances_sensors.py index 4dd3fe27..65bf0c28 100644 --- a/glances/plugins/glances_sensors.py +++ b/glances/plugins/glances_sensors.py @@ -27,6 +27,7 @@ from glances.compat import iteritems, to_fahrenheit from glances.timer import Counter from glances.plugins.sensors.glances_batpercent import Plugin as BatPercentPlugin from glances.plugins.sensors.glances_hddtemp import Plugin as HddTempPlugin +from glances.outputs.glances_unicode import unicode_message from glances.plugins.glances_plugin import GlancesPlugin SENSOR_TEMP_UNIT = 'C' @@ -187,6 +188,18 @@ class Plugin(GlancesPlugin): # Set the alert in the view self.views[i[self.get_key()]]['value']['decoration'] = alert + def battery_trend(self, stats): + """Return the trend characterr for the battery""" + if 'status' not in stats: + return '' + if stats['status'].startswith('Charg'): + return unicode_message('ARROW_UP') + elif stats['status'].startswith('Discharg'): + return unicode_message('ARROW_DOWN') + elif stats['status'].startswith('Full'): + return unicode_message('CHECK') + return '' + def msg_curse(self, args=None, max_width=None): """Return the dict to display in the curse interface.""" # Init the return message @@ -213,19 +226,22 @@ class Plugin(GlancesPlugin): msg = '{:{width}}'.format(i["label"][:name_max_width], width=name_max_width) ret.append(self.curse_add_line(msg)) if i['value'] in (b'ERR', b'SLP', b'UNK', b'NOS'): - msg = '{:>13}'.format(i['value']) + msg = '{:>14}'.format(i['value']) ret.append( self.curse_add_line(msg, self.get_views(item=i[self.get_key()], key='value', option='decoration')) ) else: if args.fahrenheit and i['type'] != 'battery' and i['type'] != 'fan_speed': + trend = '' value = to_fahrenheit(i['value']) unit = 'F' else: + trend = self.battery_trend(i) value = i['value'] unit = i['unit'] try: - msg = '{:>13.0f}{}'.format(value, unit) + msg = '{:.0f}{}{}'.format(value, unit, trend) + msg = '{:>14}'.format(msg) ret.append( self.curse_add_line( msg, self.get_views(item=i[self.get_key()], key='value', option='decoration') diff --git a/glances/plugins/sensors/glances_batpercent.py b/glances/plugins/sensors/glances_batpercent.py index f412a717..57ccb27a 100644 --- a/glances/plugins/sensors/glances_batpercent.py +++ b/glances/plugins/sensors/glances_batpercent.py @@ -119,12 +119,24 @@ class GlancesGrabBat(object): # 'unit': '%'}] for b in self.bat.stat: self.bat_list.append( - {'label': 'BAT {}'.format(b.path.split('/')[-1]), 'value': b.capacity, 'unit': '%'} + { + 'label': 'BAT {}'.format(b.path.split('/')[-1]), + 'value': b.capacity, + 'unit': '%', + 'status': b.status + } ) elif psutil_tag and hasattr(self.bat.sensors_battery(), 'percent'): # Use psutil to grab the stats # Give directly the battery percent - self.bat_list = [{'label': 'Battery', 'value': int(self.bat.sensors_battery().percent), 'unit': '%'}] + self.bat_list = [ + { + 'label': 'Battery', + 'value': int(self.bat.sensors_battery().percent), + 'unit': '%', + 'status': 'Charging' if self.bat.sensors_battery().power_plugged else 'Discharging' + } + ] def get(self): """Get the stats."""