/
server.py
executable file
·32 lines (28 loc) · 955 Bytes
/
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
#!/usr/bin/env python
import tornado.ioloop
import tornado.web
from urlparse import parse_qs as qs_decode
from urllib import urlencode as qs_encode
from tornado import escape
from plot import plotter
from tsdb import TSDb
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.set_status(200)
self.set_header("Content-Type", "image/svg+xml")
db = TSDb('lego.xe.be',4242)
det = ['ohain.temp','ohain.weight{id=1}','ohain.weight{id=2}','ohain.weight{id=0}']
query = qs_decode(self.request.query)
print query['start']
data = db.query(query['start'][0],None,det,'sum','1h-avg')
# print data
self.finish(plotter(data))
del data
del db
if __name__ == "__main__":
application = tornado.web.Application([
(r"/", MainHandler),
])
application.listen(8080,'0.0.0.0')
print("localhost:8080")
tornado.ioloop.IOLoop.instance().start()