diff --git a/framework/internal/compose.py b/framework/internal/compose.py index 1728ef6..96f94ed 100644 --- a/framework/internal/compose.py +++ b/framework/internal/compose.py @@ -66,3 +66,15 @@ def restart(service: str): cmd = ['docker', 'compose', 'restart', service] subprocess.call(cmd, stdout=subprocess.PIPE, timeout=300) print(f"Restarted service {service}") + +def info() -> dict: + """ + Get information about host and docker + """ + cmd = ['docker', 'info', '-f', 'json'] + result = subprocess.run(cmd, stdout=subprocess.PIPE, timeout=5) + + try: + return json.loads(result.stdout) + except json.decoder.JSONDecodeError: + return {} diff --git a/framework/status-json.py b/framework/status-json.py index 0219bbb..91e4f86 100644 --- a/framework/status-json.py +++ b/framework/status-json.py @@ -12,12 +12,24 @@ import internal.conf as conf def get_timestamp(): + print('Getting timestamp', file=sys.stderr) return int(time.time()) def get_revision(): + print('Getting git revision', file=sys.stderr) cmd = ['git', 'describe', '--dirty', '--always'] return subprocess.check_output(cmd, timeout=5).decode('utf-8').strip() +def get_host_info(): + print('Getting host info', file=sys.stderr) + info = compose.info() + return { + 'kernel': info.get('KernelVersion', 'N/A'), + 'os': info.get('OperatingSystem', 'N/A'), + 'arch': info.get('Architecture', 'N/A'), + 'docker_version': info.get('ServerVersion', 'N/A'), + } + def get_services(): services = {} for service in compose.config().get('services', {}): @@ -88,6 +100,7 @@ def get_ndnping(): status = { 'timestamp': run_safe(get_timestamp), 'revision': run_safe(get_revision), + 'host_info': run_safe(get_host_info), 'services': run_safe(get_services), 'nfd': run_safe(get_nfd), 'nlsr': run_safe(get_nlsr),