forked from lyger/matsuri-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
53 lines (39 loc) · 1.53 KB
/
server.py
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
from pathlib import Path
import tornado
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from matsuri_monitor import Supervisor, handlers
tornado.options.define('port', default=8080, type=int, help='Run on the given port')
tornado.options.define('debug', default=False, type=bool, help='Run in debug mode')
tornado.options.define('interval', default=300, type=float, help='Seconds between updates')
def main():
"""Create app and start server"""
supervisor = Supervisor(tornado.options.options.interval)
static_path = Path(__file__).parent.absolute() / 'matsuri_monitor' / 'static'
static_url_prefix = r'/_monitor/static/'
print(static_path)
server = tornado.httpserver.HTTPServer(
tornado.web.Application(
[
(r'/_monitor', handlers.MainHandler),
(r'/_monitor/live.json', handlers.APIHandler, {'json_source': supervisor.live_json}),
(r'/_monitor/archive.json', handlers.ArchivesHandler),
],
debug=tornado.options.options.debug,
static_path=static_path,
static_url_prefix=static_url_prefix,
)
)
if tornado.options.options.debug:
server.listen(tornado.options.options.port)
else:
server.bind(tornado.options.options.port)
server.start(1)
current_ioloop = tornado.ioloop.IOLoop.current()
supervisor.start(current_ioloop)
current_ioloop.start()
if __name__ == '__main__':
tornado.options.parse_command_line()
main()