diff --git a/src/statistic/work_load.py b/src/statistic/work_load.py index f255b38ff..e2f0ab435 100644 --- a/src/statistic/work_load.py +++ b/src/statistic/work_load.py @@ -1,9 +1,10 @@ ''' generate workload statistics ''' +from common_helper_files import get_directory_for_filename, get_version_string_from_git +import distro import logging import os -import distro import psutil import sys from time import time @@ -13,24 +14,25 @@ class WorkLoadStatistic(object): - def __init__(self, config=None, component="backend"): + def __init__(self, config=None, component='backend'): self.config = config self.component = component self.db = StatisticDbUpdater(config=self.config) - logging.debug("{}: Online".format(self.component)) + self.platform_information = self._get_platform_information() + logging.debug('{}: Online'.format(self.component)) def shutdown(self): - logging.debug("{}: shutting down -> set offline message".format(self.component)) + logging.debug('{}: shutting down -> set offline message'.format(self.component)) self.db.update_statistic(self.component, {'status': 'offline', 'last_update': time()}) self.db.shutdown() def update(self, unpacking_workload=None, analysis_workload=None, compare_workload=None): stats = { 'name': self.component, - 'status': "online", + 'status': 'online', 'last_update': time(), 'system': self._get_system_information(), - 'platform': self._get_platform_information(), + 'platform': self.platform_information, } if unpacking_workload: stats['unpacking'] = unpacking_workload @@ -45,17 +47,17 @@ def _get_system_information(self): try: disk_usage = psutil.disk_usage(self.config['data_storage']['firmware_file_storage_directory']) except Exception: - disk_usage = psutil.disk_usage("/") + disk_usage = psutil.disk_usage('/') try: cpu_freq = psutil.cpu_freq().current except Exception: - cpu_freq = "unknown" + cpu_freq = 'unknown' result = { 'cpu_cores': psutil.cpu_count(logical=False), 'virtual_cpu_cores': psutil.cpu_count(), 'cpu_freq': cpu_freq, - 'load_average': ", ".join(str(x) for x in os.getloadavg()), + 'load_average': ', '.join(str(x) for x in os.getloadavg()), 'memory_total': memory_usage.total, 'memory_used': memory_usage.used, 'memory_percent': memory_usage.percent, @@ -67,6 +69,11 @@ def _get_system_information(self): @staticmethod def _get_platform_information(): - operating_system = " ".join(distro.linux_distribution()[0:2]) - python_version = ".".join(str(x) for x in sys.version_info[0:3]) - return {"os": operating_system, "python": python_version} + operating_system = ' '.join(distro.linux_distribution()[0:2]) + python_version = '.'.join(str(x) for x in sys.version_info[0:3]) + fact_version = get_version_string_from_git(get_directory_for_filename(__file__)) + return { + 'os': operating_system, + 'python': python_version, + 'fact_version': fact_version + } diff --git a/src/web_interface/templates/system_health.html b/src/web_interface/templates/system_health.html index bb9c63c99..8901e7539 100644 --- a/src/web_interface/templates/system_health.html +++ b/src/web_interface/templates/system_health.html @@ -36,6 +36,10 @@

{{component['name']}} machine status

python version {{ component['platform']['python'] }} + + fact version + {{ component['platform']['fact_version'] }} + {% endif %} {% if component['system'] %}