这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions src/statistic/work_load.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
}
4 changes: 4 additions & 0 deletions src/web_interface/templates/system_health.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ <h3>{{component['name']}} machine status</h3>
<td class="active" style="text-align: left; padding:5px">python version</td>
<td class="active" style="text-align: right; padding:5px">{{ component['platform']['python'] }}</td>
</tr>
<tr>
<td class="active" style="text-align: left; padding:5px">fact version</td>
<td class="active" style="text-align: right; padding:5px">{{ component['platform']['fact_version'] }}</td>
</tr>
{% endif %}
{% if component['system'] %}
<tr>
Expand Down