From 8d4a20a6a843e1e35b5324bc83be422fbed04b87 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sat, 15 Jan 2022 11:33:14 +0100 Subject: [PATCH] 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))