Skip to content

Commit

Permalink
Add global status option
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed May 10, 2024
1 parent 140ae28 commit 7978e82
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
33 changes: 33 additions & 0 deletions framework/status-global.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3

import os
import sys
import json

import internal.conf as conf
import internal.compose as compose

if __name__ == '__main__':
config = conf.get()

# Read routers.json
routers: dict[str, dict] = None
with open(os.path.join(config.environment_path, 'dist', 'file-server', 'routers.json')) as stream:
routers = json.load(stream)

# Get status of each node
for rn, router in routers.items():
try:
status_file = f"{router['prefix']}/file-server/status.json"
code, stdout = compose.exec('ndnpingserver', ['ndncatchunks', '-q', status_file, '-r', '2', '-l', '1000'])
if code == 0:
router.update(json.loads(stdout))
router['ndn-up'] = True
else:
raise Exception(f"ndncatchunks failed with {code}")
except Exception as e:
print(f"Error fetching status for {rn}: {e}", file=sys.stderr)
router['ndn-up'] = False
router['ws-tls'] = False

print(json.dumps(routers, indent=4), file=sys.stdout)
7 changes: 7 additions & 0 deletions scripts/cron-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ python3 framework/status-json.py > dist/file-server/status.json

# Done
echo -e "Status updated at $(date)"

# Collect all statuses if enabled
if [[ -n "$COLLECT_STATUS_GLOBAL" ]]; then
echo -e "Waiting before starting global status job ..."
sleep 60
python3 framework/status-global.py > dist/file-server/status-global.json
fi

0 comments on commit 7978e82

Please sign in to comment.