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