]>
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): | |
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> | |
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> | |
89b885cc MT |
26 | </table> |
27 | <p> <br />Number of nodes: <span id="count">-</span></p>""" | |
efe0c55b | 28 | |
dba657a8 MT |
29 | return ret |
30 | ||
31 | page = web.Page() | |
32 | page.content = Content() | |
33 | page.sidebar = web.elements.Sidebar() | |
34 | ||
35 | page.javascript = Javascript(jquery=1) | |
36 | page.javascript.jquery_plugin("progressbar") | |
37 | page.javascript.write("""<script type="text/javascript"> | |
efe0c55b | 38 | nodes = new Array(); |
3d0128fa | 39 | id = 0; |
efe0c55b MT |
40 | |
41 | update = function() { | |
3d0128fa | 42 | $.getJSON("/rpc.py", { method: "cluster_get_info", id : id++ }, |
efe0c55b | 43 | function(data) { |
ce0f70d2 | 44 | var count = 0; |
3d0128fa MT |
45 | |
46 | if (data.error != "null") return; | |
47 | ||
48 | $.each(data.result.nodes, function(i, node) { | |
ce0f70d2 MT |
49 | var nodeid = node.hostname.replace(/\./g, ""); |
50 | count++; | |
efe0c55b MT |
51 | |
52 | nodes[nodeid] = true; | |
53 | ||
54 | if ($("#" + nodeid).length) { | |
ce0f70d2 | 55 | $("#" + nodeid + "_speed").html(node.speed); |
efe0c55b MT |
56 | } else { |
57 | row = "<tr id=\\"" + nodeid + "\\" class=\\"node\\">"; | |
89b885cc | 58 | row += " <td id=\\"" + nodeid + "_hostname\\"></td>"; |
efe0c55b MT |
59 | row += " <td id=\\"" + nodeid + "_arch\\">" + node.arch + "</td>"; |
60 | row += " <td><span id=\\"" + nodeid + "_loadbar\\"></span></td>"; | |
ce0f70d2 MT |
61 | row += " <td><span id=\\"" + nodeid + "_jobs\\"></span></td>"; |
62 | row += " <td id=\\"" + nodeid + "_speed\\">" + node.speed + "</td>"; | |
efe0c55b MT |
63 | row += "</tr>"; |
64 | $("#nodes").append(row); | |
65 | } | |
66 | $("#" + nodeid + "_loadbar").progressBar(node.load, {showText: false}); | |
89b885cc MT |
67 | $("#" + nodeid + "_jobs").progressBar(node.jobcount.split("/")[0], { max: node.jobcount.split("/")[1], textFormat: 'fraction'}); |
68 | if (node.installing == true) { | |
69 | $("#" + nodeid + "_hostname").html(node.hostname + " *"); | |
70 | } else { | |
71 | $("#" + nodeid + "_hostname").html(node.hostname); | |
72 | } | |
efe0c55b | 73 | }); |
3d0128fa MT |
74 | |
75 | $("#loadbar").progressBar(data.result.cluster.load); | |
89b885cc | 76 | $("#jobbar").progressBar(data.result.cluster.jobcount.split("/")[0], { max: data.result.cluster.jobcount.split("/")[1], textFormat: 'fraction'}); |
efe0c55b MT |
77 | for (var nodeid in nodes) { |
78 | if (nodes[nodeid] == false) { | |
79 | $("#" + nodeid).remove(); | |
80 | nodes.pop(nodeid); | |
81 | } else { | |
82 | nodes[nodeid] = false; | |
83 | } | |
84 | } | |
ce0f70d2 | 85 | $("#count").html(count); |
efe0c55b MT |
86 | }); |
87 | } | |
88 | ||
89 | $(document).ready(function(){ | |
90 | // Init loadbar | |
91 | $("#loadbar").progressBar(); | |
92 | ||
93 | update(); | |
ce0f70d2 | 94 | setInterval("update()", 2000); |
efe0c55b | 95 | }) |
dba657a8 | 96 | </script>""") |