]> git.ipfire.org Git - people/shoehn/ipfire.org.git/blame_incremental - www/pages/cluster.py
Change Color of Menuitem CeBIT.
[people/shoehn/ipfire.org.git] / www / pages / cluster.py
... / ...
CommitLineData
1#!/usr/bin/python
2
3import web
4import web.elements
5from web.javascript import Javascript
6
7class Content(web.Content):
8 def __init__(self):
9 web.Content.__init__(self)
10
11 def __call__(self, lang):
12 ret = """<h3>Icecream Cluster Monitoring</h3>
13 <p>Cluster's CPU load: <span id="loadbar"></span> - Job load: <span id="jobbar"></span></p>
14 <table id="nodes">
15 <thead>
16 <tr>
17 <th class="hostname">Name</th>
18 <th class="arch">Arch</th>
19 <th class="load">Load</th>
20 <th class="jobs">Jobs</th>
21 <th class="speed">Speed</th>
22 </tr>
23 </thead>
24 <tbody>
25 </tbody>
26 </table>
27 <p>&nbsp;<br />Number of nodes: <span id="count">-</span></p>"""
28
29 return ret
30
31page = web.Page()
32page.content = Content()
33page.sidebar = web.elements.DevelopmentSidebar()
34
35page.javascript = Javascript(jquery=1)
36page.javascript.jquery_plugin("progressbar")
37page.javascript.write("""<script type="text/javascript">
38 nodes = new Array();
39 id = 0;
40 busy = false;
41
42 update = function() {
43 $.getJSON("/rpc.py", { method: "cluster_get_info", id : id++ },
44 function(data) {
45 // If we are already busy then exit
46 if (busy == true) return;
47
48 var count = 0;
49
50 if (data.error != "null") return;
51
52 busy = true;
53
54 $.each(data.result.nodes, function(i, node) {
55 var nodeid = node.hostname.replace(/\./g, "");
56 count++;
57
58 nodes[nodeid] = true;
59
60 if ($("#" + nodeid).length) {
61 $("#" + nodeid + "_speed").html(node.speed);
62 } else {
63 row = "<tr id=\\"" + nodeid + "\\" class=\\"node\\">";
64 row += " <td id=\\"" + nodeid + "_hostname\\"></td>";
65 row += " <td id=\\"" + nodeid + "_arch\\">" + node.arch + "</td>";
66 row += " <td><span id=\\"" + nodeid + "_loadbar\\"></span></td>";
67 row += " <td><span id=\\"" + nodeid + "_jobs\\"></span></td>";
68 row += " <td id=\\"" + nodeid + "_speed\\">" + node.speed + "</td>";
69 row += "</tr>";
70 $("#nodes").append(row);
71 }
72 $("#" + nodeid + "_loadbar").progressBar(node.load, {showText: false});
73 $("#" + nodeid + "_jobs").progressBar(node.jobcount.split("/")[0], { max: node.jobcount.split("/")[1], textFormat: 'fraction'});
74 if (node.installing == true) {
75 $("#" + nodeid + "_hostname").html(node.hostname + " *");
76 } else {
77 $("#" + nodeid + "_hostname").html(node.hostname);
78 }
79 });
80
81 $("#loadbar").progressBar(data.result.cluster.load);
82 $("#jobbar").progressBar(data.result.cluster.jobcount.split("/")[0], { max: data.result.cluster.jobcount.split("/")[1], textFormat: 'fraction'});
83 for (var nodeid in nodes) {
84 if (nodes[nodeid] == false) {
85 $("#" + nodeid).remove();
86 nodes.pop(nodeid);
87 } else {
88 nodes[nodeid] = false;
89 }
90 }
91 $("#count").html(count);
92 busy = false;
93 });
94 }
95
96 $(document).ready(function(){
97 // Init loadbar
98 $("#loadbar").progressBar();
99
100 update();
101 setInterval("update()", 2000);
102 })
103 </script>""")