]> git.ipfire.org Git - people/shoehn/ipfire.org.git/blame - www/pages/cluster.py
Change Color of Menuitem CeBIT.
[people/shoehn/ipfire.org.git] / www / pages / cluster.py
CommitLineData
efe0c55b
MT
1#!/usr/bin/python
2
3import web
dba657a8
MT
4import web.elements
5from web.javascript import Javascript
efe0c55b
MT
6
7class Content(web.Content):
dba657a8
MT
8 def __init__(self):
9 web.Content.__init__(self)
efe0c55b
MT
10
11 def __call__(self, lang):
e9dd1647 12 ret = """<h3>Icecream Cluster Monitoring</h3>
89b885cc 13 <p>Cluster's CPU load: <span id="loadbar"></span> - Job load: <span id="jobbar"></span></p>
dba657a8
MT
14 <table id="nodes">
15 <thead>
16 <tr>
baeb04f9
JPT
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>
dba657a8
MT
22 </tr>
23 </thead>
24 <tbody>
25 </tbody>
89b885cc
MT
26 </table>
27 <p>&nbsp;<br />Number of nodes: <span id="count">-</span></p>"""
efe0c55b 28
dba657a8
MT
29 return ret
30
31page = web.Page()
32page.content = Content()
3a205dfe 33page.sidebar = web.elements.DevelopmentSidebar()
dba657a8
MT
34
35page.javascript = Javascript(jquery=1)
36page.javascript.jquery_plugin("progressbar")
37page.javascript.write("""<script type="text/javascript">
efe0c55b 38 nodes = new Array();
3d0128fa 39 id = 0;
14025650 40 busy = false;
efe0c55b
MT
41
42 update = function() {
3d0128fa 43 $.getJSON("/rpc.py", { method: "cluster_get_info", id : id++ },
efe0c55b 44 function(data) {
14025650
MT
45 // If we are already busy then exit
46 if (busy == true) return;
47
ce0f70d2 48 var count = 0;
3d0128fa
MT
49
50 if (data.error != "null") return;
14025650
MT
51
52 busy = true;
3d0128fa
MT
53
54 $.each(data.result.nodes, function(i, node) {
ce0f70d2
MT
55 var nodeid = node.hostname.replace(/\./g, "");
56 count++;
efe0c55b
MT
57
58 nodes[nodeid] = true;
59
60 if ($("#" + nodeid).length) {
ce0f70d2 61 $("#" + nodeid + "_speed").html(node.speed);
efe0c55b
MT
62 } else {
63 row = "<tr id=\\"" + nodeid + "\\" class=\\"node\\">";
baeb04f9
JPT
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>";
efe0c55b
MT
69 row += "</tr>";
70 $("#nodes").append(row);
71 }
72 $("#" + nodeid + "_loadbar").progressBar(node.load, {showText: false});
89b885cc
MT
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 }
efe0c55b 79 });
3d0128fa
MT
80
81 $("#loadbar").progressBar(data.result.cluster.load);
89b885cc 82 $("#jobbar").progressBar(data.result.cluster.jobcount.split("/")[0], { max: data.result.cluster.jobcount.split("/")[1], textFormat: 'fraction'});
efe0c55b
MT
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 }
ce0f70d2 91 $("#count").html(count);
14025650 92 busy = false;
efe0c55b
MT
93 });
94 }
95
96 $(document).ready(function(){
97 // Init loadbar
98 $("#loadbar").progressBar();
99
100 update();
ce0f70d2 101 setInterval("update()", 2000);
efe0c55b 102 })
dba657a8 103 </script>""")