diff options
author | Javier Sánchez Parra <jsanchez@soleta.eu> | 2022-03-15 12:00:36 +0100 |
---|---|---|
committer | Javier Sánchez Parra <jsanchez@soleta.eu> | 2022-03-16 17:33:34 +0100 |
commit | 3283843d564a188190a3b4a453c1ea867910400f (patch) | |
tree | c4951ad44debc6c8923a6199266d8ca25adff747 /ogcp/views.py | |
parent | 57ab7c11a90f6d4b9a2d54d5590aad88ae7a133f (diff) |
Add /stats data to the dashboard
Add certain statistics on memory and swap usage, as well as the uptime.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index cb1f4de..752db62 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -183,6 +183,25 @@ def get_user(username): return user return None + +intervals = ( + (_('days'), 86400), # 60 * 60 * 24 + (_('hours'), 3600), # 60 * 60 + (_('minutes'), 60), +) + + +def display_time(seconds): + result = [] + + for name, count in intervals: + value = seconds // count + if value: + seconds -= value * count + result.append("{} {}".format(value, name)) + return ', '.join(result) + + @login_manager.user_loader def load_user(username): user_dict = get_user(username) @@ -218,9 +237,15 @@ def index(): images.sort(key=image_modified_date_from_str, reverse=True) disk = images_response.json()['disk'] oglive_list = g.server.get('/oglive/list').json() + stats = g.server.get('/stats').json() + timestamp = datetime.datetime.fromtimestamp(stats.get('time').get('now')) + now = timestamp.strftime('%Y-%m-%d %H:%M:%S') + boot = display_time(stats.get('time').get('boot')) + time_dict = {'now': now, 'boot': boot} return render_template('dashboard.html', clients=clients, images=images, disk=disk, colsize="6", - oglive_list=oglive_list) + oglive_list=oglive_list, stats=stats, + time_dict=time_dict) @app.route('/login', methods=['GET', 'POST']) def login(): |