Commit fed21c85 authored by Gero Müller's avatar Gero Müller
Browse files

add status page

parent 10c3e0ea
......@@ -14,6 +14,9 @@ auto_migrate = True
[web]
dev_mode = True
# password for the status page /status
#status_password = changeme
# use base when running in subdirectory
base = /vispa
# set dynamic part seperatly
......
......@@ -16,6 +16,7 @@ from StringIO import StringIO
import inspect
import smtplib
from . import url
import thread
try:
......@@ -256,3 +257,13 @@ def send_mail(addr, subject="", content="", sender_addr=None, smtp_host=None,
header_data = (sender_addr, addr, subject)
head = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % header_data
server.sendmail(sender_addr, addr, head + content)
def thread_stacktraces():
frames = sys._current_frames()
data = {}
for thread_id, frame in frames.iteritems():
stacktrace = StringIO()
traceback.print_stack(frame, file=stacktrace)
data[thread_id] = stacktrace.getvalue()
return data
......@@ -171,3 +171,47 @@ class RootController(AbstractController):
"hash": hash
}
return data
@cherrypy.expose
@cherrypy.tools.user(on=False)
@cherrypy.tools.db(on=False)
@cherrypy.tools.workspace(on=False)
@cherrypy.tools.sessions(on=False)
def status(self, password=None):
if password != vispa.config("web", "status_password", None):
return """
<html>
<head>
<title>CherryPy Status</title>
</head>
<body>
<h1>CherryPy Status</h1>
<form method="get">
<label for="password">Password:</label>
<input type="password" name="password" />
<input type="submit" value="Submit" />
</form>
</html>
"""
else:
workerthreadstats = ["<tr><th><a href=\"#%s\">%s</a></th><td>%.4f</td><td>%.4f</td><td>%s</td></tr>"
% (thread_id, thread_id, ts.idle_time(), ts.last_req_time(), ts.url)
for thread_id, ts in cherrypy.tools.status.seen_threads.items()]
tracebacks = ["<h3><a id=\"%s\">%s</a></h3><pre>\n%s</pre>" % (thread_id, thread_id, st)
for thread_id, st in vispa.thread_stacktraces().items()]
return """
<html>
<head>
<title>CherryPy Status</title>
</head>
<body>
<h1>CherryPy Status</h1>
<table>
<tr><th>Thread ID</th><th>Idle Time</th><th>Last Request Time</th><th>URL</th></tr>
%s
</table>
%s
</body>
</html>
""" % ('\n'.join(workerthreadstats),'\n'.join(tracebacks))
......@@ -24,6 +24,7 @@ from vispa.models.shortcuts import *
logger = logging.getLogger(__name__)
class AbstractExtension(object):
""" Base class for Extensions """
......@@ -141,6 +142,7 @@ class Server(object):
'base_dynamic': base_dynamic,
'base_static': base_static
},
"tools.status.on": True,
},
'/extensions': {
'tools.workspace.on': True,
......@@ -289,6 +291,9 @@ class Server(object):
from vispa.tools.json_parameters import JsonParameters
cherrypy.tools.json_parameters = JsonParameters()
from vispa.tools.status import StatusMonitor
cherrypy.tools.status = StatusMonitor()
try:
from ws4py.server.cherrypyserver import WebSocketTool
cherrypy.tools.websocket = WebSocketTool()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment