Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
new url for displaying statistics #202
Merged
Commits
Jump to file or symbol
Failed to load files and symbols.
| @@ -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 %} |