]>
Commit | Line | Data |
---|---|---|
efe0c55b MT |
1 | #!/usr/bin/python |
2 | ||
3 | import web | |
4 | import web.cluster | |
5 | ||
6 | class Content(web.Content): | |
7 | def __init__(self, name): | |
8 | web.Content.__init__(self, name) | |
9 | ||
10 | self.cluster = web.cluster.Cluster("minerva.ipfire.org") | |
11 | ||
12 | def __call__(self, lang): | |
13 | ret = "<h3>Cluster Monitoring</h4>" | |
14 | ||
15 | ret += """<script type="text/javascript"> | |
16 | nodes = new Array(); | |
17 | ||
18 | update = function() { | |
19 | $.getJSON("http://www.ipfire.org/rpc.py", { type: "cluster" }, | |
20 | function(data) { | |
21 | $.each(data.nodes, function(i, node) { | |
22 | var nodeid = node.hostname.replace(".", "").replace(".", ""); | |
23 | ||
24 | nodes[nodeid] = true; | |
25 | ||
26 | if ($("#" + nodeid).length) { | |
27 | $("#" + nodeid + "_jobs").html(node.jobs); | |
28 | } else { | |
29 | row = "<tr id=\\"" + nodeid + "\\" class=\\"node\\">"; | |
30 | row += " <td id=\\"" + nodeid + "_hostname\\">" + node.hostname + "</td>"; | |
31 | row += " <td id=\\"" + nodeid + "_arch\\">" + node.arch + "</td>"; | |
32 | row += " <td><span id=\\"" + nodeid + "_loadbar\\"></span></td>"; | |
33 | row += " <td id=\\"" + nodeid + "_jobs\\">" + node.jobs + "</td>"; | |
34 | row += "</tr>"; | |
35 | $("#nodes").append(row); | |
36 | } | |
37 | $("#" + nodeid + "_loadbar").progressBar(node.load, {showText: false}); | |
38 | }); | |
39 | $("#loadbar").progressBar(data.cluster.load); | |
40 | for (var nodeid in nodes) { | |
41 | if (nodes[nodeid] == false) { | |
42 | $("#" + nodeid).remove(); | |
43 | nodes.pop(nodeid); | |
44 | } else { | |
45 | nodes[nodeid] = false; | |
46 | } | |
47 | } | |
48 | }); | |
49 | } | |
50 | ||
51 | $(document).ready(function(){ | |
52 | // Init loadbar | |
53 | $("#loadbar").progressBar(); | |
54 | ||
55 | update(); | |
56 | setInterval("update()", 2500); | |
57 | }) | |
58 | </script>""" | |
59 | ||
60 | ret += """<p>Cluster's load: <span id="loadbar"></span></p> | |
61 | <table id="nodes"> | |
62 | <thead> | |
63 | <tr> | |
64 | <th>Name</th> | |
65 | <th>Arch</th> | |
66 | <th>Load</th> | |
67 | <th>Jobs</th> | |
68 | </tr> | |
69 | </thead> | |
70 | <tbody> | |
71 | </tbody> | |
72 | </table>""" | |
73 | ||
74 | return ret | |
75 | ||
76 | Sidebar = web.Sidebar |