Apply BSD-style license
[bwmon.git] / bwmon / http.py
blob7481cf3cd16fc3a75562b321dfe1dcca49880af4
1 # -*- coding: utf-8 -*-
3 # Copyright 2010 Thomas Perl and Stefan Kögl. All rights reserved.
5 # Developed for a practical course (Large-scaled distributed computing) at the
6 # University of Technology Vienna in the 2010 summer term.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are met:
11 # 1. Redistributions of source code must retain the above copyright notice,
12 # this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright notice,
15 # this list of conditions and the following disclaimer in the documentation
16 # and/or other materials provided with the distribution.
18 # THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
21 # EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 from __future__ import absolute_import
32 import BaseHTTPServer
34 import os
36 JS = open(os.path.join(os.path.dirname(__file__) or '.', '..', 'all.js')).read()
38 HTML = """
39 <script type="text/javascript">
40 window.onload = function() {
41 var paper = new Raphael(0, 0, 640, 480);
42 paper.g.linechart(0, 0, 640, 480, %s, %s);
44 </script>
45 </head>
46 <body>
47 </body>
48 </html>
49 """
51 class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
52 """HTTP Request handler (returns monitoring data)
54 This is a simple request handler used by the built-in
55 HTTP server to visualize the monitoring data.
56 """
57 monitor = None
59 def do_GET(self):
60 """Handler for HTTP GET requests
61 """
62 self.send_response(200)
63 self.send_header('Content-type', 'text/html')
64 self.send_header('Refresh', '5')
65 self.end_headers()
67 x, yy = self.monitor.get_datapoints()
69 self.wfile.write('<html><head><script type="text/javascript">')
70 self.wfile.write(JS)
71 self.wfile.write('</script>')
72 self.wfile.write(HTML % (repr(x), repr(yy)))
74 #server = BaseHTTPServer.HTTPServer(('', 8000), RequestHandler)
75 #while True:
76 # server.handle_request()