Permalink
Please sign in to comment.
Browse files
Merge pull request #202 from StrausMG/stats_page
new url for displaying statistics
- Loading branch information...
Showing
with
91 additions
and 8 deletions.
- +2 −1 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
| @@ -1,6 +1,7 @@ | ||
| -__version__ = "0.10.1" | ||
| +__version__ = "0.11.0" | ||
| from .spawner import * | ||
| from .authenticator import * | ||
| from .user_spawn_handler import * | ||
| from .user_wait_handler import * | ||
| from .home_handler import * | ||
| +from .stats_handler import * |
| @@ -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
88152cf