Skip to content

Commit

Permalink
status: add host info
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed May 10, 2024
1 parent d38df2b commit ebedb28
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions framework/internal/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
13 changes: 13 additions & 0 deletions framework/status-json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', {}):
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit ebedb28

Please sign in to comment.