-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsample_application.py
More file actions
63 lines (44 loc) · 1.48 KB
/
sample_application.py
File metadata and controls
63 lines (44 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import pprint
import signal
import sys
import tornado.web
import tornado.httpserver
import tornado.ioloop
from mutornadomon.config import initialize_mutornadomon
def fail():
assert False, 'oops'
class HeloHandler(tornado.web.RequestHandler):
def get(self):
self.write('HELO %s' % self.request.remote_ip)
tornado.ioloop.IOLoop.current().add_callback(fail)
def publisher(metrics):
print('Publishing metrics')
pprint.pprint(metrics)
def main(publish=False, no_app=False):
io_loop = tornado.ioloop.IOLoop.current()
application = tornado.web.Application([
(r'/', HeloHandler)
])
server = tornado.httpserver.HTTPServer(application)
server.listen(8080, '127.0.0.1')
if no_app:
tornado_app = None
else:
tornado_app = application
if publish:
monitor = initialize_mutornadomon(tornado_app=tornado_app,
io_loop=io_loop,
publisher=publisher,
publish_interval=5 * 1000)
else:
monitor = initialize_mutornadomon(tornado_app=tornado_app)
def stop(*args):
print('Good bye')
monitor.stop()
io_loop.stop()
for sig in signal.SIGINT, signal.SIGQUIT, signal.SIGTERM:
signal.signal(sig, stop)
tornado.ioloop.IOLoop.current().start()
if __name__ == '__main__':
main(publish='--publish' in sys.argv,
no_app='--no-app' in sys.argv)