]> git.ipfire.org Git - ipfire.org.git/commitdiff
Some changes on the cluster page.
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Jul 2009 16:20:09 +0000 (18:20 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Jul 2009 16:20:09 +0000 (18:20 +0200)
www/pages/cluster/__init__.py
www/web/cluster.py

index 8b5dcbea1201aa3f2f1c2c36095daeffae878da7..ddd3694722a29776227ee317c2f0cef68dddfda5 100644 (file)
@@ -10,8 +10,7 @@ class Content(web.Content):
 
        def __call__(self, lang):
                ret = """<h3>Icecream Cluster Monitoring</h4>
-                       <p>Cluster's CPU load: <span id="loadbar"></span> Job load: <span id="jobbar"></span> -
-                               Number of nodes: <span id="count">-</span></p>
+                       <p>Cluster's CPU load: <span id="loadbar"></span> - Job load: <span id="jobbar"></span></p>
                                <table id="nodes">
                                        <thead>
                                                <tr>
@@ -24,7 +23,8 @@ class Content(web.Content):
                                        </thead>
                                        <tbody>
                                        </tbody>
-                               </table>"""
+                               </table>
+                               <p>&nbsp;<br />Number of nodes: <span id="count">-</span></p>"""
 
                return ret
 
@@ -55,7 +55,7 @@ page.javascript.write("""<script type="text/javascript">
                                                                        $("#" + nodeid + "_speed").html(node.speed);
                                                                } else {
                                                                        row  = "<tr id=\\"" + nodeid + "\\" class=\\"node\\">";
-                                                                       row += "  <td id=\\"" + nodeid + "_hostname\\">" + node.hostname + "</td>";
+                                                                       row += "  <td id=\\"" + nodeid + "_hostname\\"></td>";
                                                                        row += "  <td id=\\"" + nodeid + "_arch\\">" + node.arch + "</td>";
                                                                        row += "  <td><span id=\\"" + nodeid + "_loadbar\\"></span></td>";
                                                                        row += "  <td><span id=\\"" + nodeid + "_jobs\\"></span></td>";
@@ -64,11 +64,16 @@ page.javascript.write("""<script type="text/javascript">
                                                                        $("#nodes").append(row);
                                                                }
                                                                $("#" + nodeid + "_loadbar").progressBar(node.load, {showText: false});
-                                                               $("#" + nodeid + "_jobs").progressBar(node.jobs.split("/")[0], { max: node.jobs.split("/")[1], textFormat: 'fraction'}); 
+                                                               $("#" + nodeid + "_jobs").progressBar(node.jobcount.split("/")[0], { max: node.jobcount.split("/")[1], textFormat: 'fraction'});
+                                                               if (node.installing == true) {
+                                                                       $("#" + nodeid + "_hostname").html(node.hostname + " *");
+                                                               } else {
+                                                                       $("#" + nodeid + "_hostname").html(node.hostname);
+                                                               }
                                                        });
 
                                                        $("#loadbar").progressBar(data.result.cluster.load);
-                                                       $("#jobbar").progressBar(data.result.cluster.jobs.split("/")[0], { max: data.result.cluster.jobs.split("/")[1], textFormat: 'fraction'});
+                                                       $("#jobbar").progressBar(data.result.cluster.jobcount.split("/")[0], { max: data.result.cluster.jobcount.split("/")[1], textFormat: 'fraction'});
                                                        for (var nodeid in nodes) {
                                                                if (nodes[nodeid] == false) {
                                                                        $("#" + nodeid).remove();
index 855a7da92c9e554a2ee04ddcd810f52691fc5b9d..bddf3fe4b2aa2d038b2950e9a030194e2c70cbcf 100644 (file)
@@ -1,22 +1,26 @@
 #!/usr/bin/python
 
+import os
 import telnetlib
 
 import simplejson as json
 
 class Node(object):
-       def __init__(self, hostname, address, arch, speed, jobs, load):
+       def __init__(self, hostname, address, arch, speed, jobcount, load, installing):
                self.hostname = hostname
                self.address = address
                self.arch = arch
                self.speed = speed
+               self.installing = installing
 
-               (jobs_cur, jobs_max) = jobs.split("/")
+               (jobs_cur, jobs_max) = jobcount.split("/")
                if jobs_cur > jobs_max:
                        jobs_cur = jobs_max
-               self.jobs = "%s/%s" % (jobs_cur, jobs_max)
+               self.jobcount = "%s/%s" % (jobs_cur, jobs_max)
 
                self.load = int(load) / 10 # in percent
+               
+               self.jobs = []
        
        def __str__(self):
                return self.hostname
@@ -29,9 +33,18 @@ class Node(object):
                print "  Address: %s" % self.address
                print "  Arch   : %s" % self.arch
                print "  Speed  : %s" % self.speed
-               print "  Jobs   : %s" % self.jobs
+               print "  Jobs   : %s" % self.jobcount
                print "  Load   : %s" % self.load
 
+class Job(object):
+       def __init__(self, id, status, submitter, compiler, file):
+               self.id = id
+               self.status = status
+               self.submitter = submitter
+               self.compiler = compiler
+               self.file = file
+
+
 class Cluster(object):
        def __init__(self, scheduler, port=8766):
                self.scheduler = scheduler
@@ -56,11 +69,11 @@ class Cluster(object):
                return load
        
        @property
-       def jobs(self):
+       def jobcount(self):
                jobs_cur = jobs_max = 0
                for node in self.nodes:
-                       jobs_cur += int(node.jobs.split("/")[0])
-                       jobs_max += int(node.jobs.split("/")[1])
+                       jobs_cur += int(node.jobcount.split("/")[0])
+                       jobs_max += int(node.jobcount.split("/")[1])
                return "%s/%s" % (jobs_cur, jobs_max)
 
        @property
@@ -69,16 +82,35 @@ class Cluster(object):
                        return self._nodes
                ret = []
                data = self.command("listcs")
+               node = None
                for line in data:
-                       if line.startswith("  "): continue
-                       if not line.startswith(" "): continue
-                       (a, hostname, address, arch, speed, jobs, load) = line.split(" ")
-                       address = address.strip("()")
-                       arch = arch.strip("[]")
-                       speed = speed.split("=")[1]
-                       jobs = jobs.split("=")[1]
-                       load = load.split("=")[1]
-                       ret.append(Node(hostname, address, arch, speed, jobs, load))
+                       if not line.startswith(" "):
+                               continue # does not belong to the data
+
+                       if line.startswith("  ") and node: # Job
+                               (a, b, c, id, status, submitter, compiler, file) = line.split(" ")
+                               submitter = submitter[4:]
+                               compiler = compiler[3:]
+                               file = os.path.basename(file)
+                               job = Job(id, status, submitter, compiler, file)
+                               node.jobs.append(job)
+
+                       elif line.startswith(" "): # Node
+                               installing = False
+                               a = line.split(" ")
+                               if len(a) > 7:
+                                       installing = True
+                                       line = " ".join(a[0:7])
+                               
+                               (a, hostname, address, arch, speed, jobcount, load) = line.split(" ")
+                               address = address.strip("()")
+                               arch = arch.strip("[]")
+                               speed = speed[6:]
+                               jobcount = jobcount[5:]
+                               load = load[5:]
+                               node = Node(hostname, address, arch, speed, jobcount, load, installing)
+                               ret.append(node)
+                       
                self._nodes = ret
                return ret
 
@@ -90,14 +122,22 @@ class Cluster(object):
                        tmp = { "hostname" : node.hostname,
                                        "address"  : node.address,
                                        "arch"     : node.arch,
-                                       "jobs"     : node.jobs,
+                                       "jobcount" : node.jobcount,
                                        "load"     : node.load,
-                                       "speed"    : node.speed, }
+                                       "speed"    : node.speed,
+                                       "installing" : node.installing,}
+                       jobs = []
+                       for job in node.jobs:
+                               jobs.append({ "id"        : job.id,
+                                                         "status"    : job.status,
+                                                         "submitter" : job.submitter,
+                                                         "compiler"  : job.compiler,
+                                                         "file"      : job.file, })
+                       tmp["jobs"] = jobs
                        nodes.append(tmp)
                ret["nodes"] = nodes
-               ret["cluster"] = { "load"  : self.load,
-                                                  "jobs"  : self.jobs, }
-               #return json.dumps(ret)
+               ret["cluster"] = { "load"     : self.load,
+                                                  "jobcount" : self.jobcount, }
                return ret