Permalink
Please sign in to comment.
Showing
with
90 additions
and 7 deletions.
- +1 −0 everware/__init__.py
- +42 −0 everware/stats_handler.py
- +16 −0 everware/user_spawn_handler.py
- +21 −7 scripts/everware-server
- +10 −0 share/static/html/stats.html
| @@ -0,0 +1,42 @@ | ||
| +from jupyterhub.handlers.pages import BaseHandler | ||
| +from docker import Client | ||
| +from tornado import gen | ||
| + | ||
| + | ||
| +class StatsHandler(BaseHandler): | ||
| + """Handler for the stats page ['/hub/stats']. | ||
| + | ||
| + Fills the page with some statistics on everware. | ||
| + """ | ||
| + container_statuses = { | ||
| + 'running': 'running', | ||
| + 'restarting': 'restarting', | ||
| + 'paused': 'paused', | ||
| + 'exited': 'exited' | ||
| + } | ||
| + | ||
| + def initialize(self, stats): | ||
| + """Initialize the handler. | ||
| + | ||
| + Parameters | ||
| + ---------- | ||
| + stats : dict | ||
| + A dict containing all the stats on the everware instance. | ||
| + """ | ||
| + self.stats = stats | ||
| + | ||
| + @gen.coroutine | ||
| + def get(self, *args, **kwargs): | ||
| + running_container_count = yield self.get_running_container_count() | ||
| + html = self.render_template( | ||
| + 'stats.html', | ||
| + running_container_count=running_container_count, | ||
| + total_launch_count=self.stats['total_launch_count'] | ||
| + ) | ||
| + self.finish(html) | ||
| + | ||
| + @gen.coroutine | ||
| + def get_running_container_count(self): | ||
| + """Get the number of currently running containers.""" | ||
| + return len(Client().containers( | ||
| + filters={'status': self.container_statuses['running']})) |
| @@ -0,0 +1,10 @@ | ||
| +{% extends "page.html" %} | ||
| + | ||
| +{% block main %} | ||
| + <p> | ||
| + Currently running containers: {{ running_container_count }} | ||
| + </p> | ||
| + <p> | ||
| + Total number of launches: {{ total_launch_count }} | ||
| + </p> | ||
| +{% endblock %} |
0 comments on commit
9b292b3