Looks beter after the last commit ! Some TODO to do in the glances_restful_api.py files...

This commit is contained in:
nicolargo 2023-12-10 19:59:33 +01:00
parent cbb2facc87
commit 1f1622a625
2 changed files with 8 additions and 6 deletions

View File

@ -7,6 +7,8 @@
# SPDX-License-Identifier: LGPL-3.0-only
#
from collections import Counter
# from glances.logger import logger
# This constant defines the list of available processes sort key
@ -35,14 +37,15 @@ def create_program_dict(p):
'status': p['status'],
}
def update_program_dict(program, p):
"""Update an existing entry in the dict (existing program)"""
# some values can be None, e.g. macOS system processes
program['num_threads'] += p['num_threads'] or 0
program['cpu_percent'] += p['cpu_percent'] or 0
program['memory_percent'] += p['memory_percent'] or 0
program['cpu_times'] += p['cpu_times'] or ()
program['memory_info'] += p['memory_info'] or ()
program['cpu_times'] = dict(Counter(program['cpu_times']) + Counter(p['cpu_times']))
program['memory_info'] = dict(Counter(program['memory_info']) + Counter(p['memory_info']))
program['io_counters'] += p['io_counters']
program['childrens'].append(p['pid'])
@ -51,6 +54,7 @@ def update_program_dict(program, p):
program['nice'] = p['nice'] if p['nice'] == program['nice'] else '_'
program['status'] = p['status'] if p['status'] == program['status'] else '_'
def processes_to_programs(processes):
"""Convert a list of processes to a list of programs."""
# Start to build a dict of programs (key is program name)

View File

@ -280,10 +280,8 @@ class TestGlances(unittest.TestCase):
# stats_to_check = [ ]
print('INFO: [TEST_017] Check PROGRAM stats')
stats_grab = processes_to_programs(stats.get_plugin('processlist').get_raw())
self.assertTrue(type(stats_grab) is list, msg='Programs stats is not a list')
print('INFO: PROGRAM list stats: %s items in the list' % len(stats_grab))
# Check if number of processes in the list equal counter
# self.assertEqual(total, len(stats_grab))
self.assertIsInstance(stats_grab, list, msg='Programs stats list is not a list')
self.assertIsInstance(stats_grab[0], dict, msg='First item should be a dict')
def test_018_string_value_to_float(self):
"""Check string_value_to_float function"""