From 6925770e4f0b8bf2f7376287b6c7231c89998db6 Mon Sep 17 00:00:00 2001 From: Jan Oliver Oelerich Date: Tue, 19 Jan 2016 09:38:47 +0100 Subject: [PATCH] Added module for tracking the status of Batch computing jobs on a cluster running the Sun Grid Engine (SGE) --- i3pystatus/sge.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 i3pystatus/sge.py diff --git a/i3pystatus/sge.py b/i3pystatus/sge.py new file mode 100644 index 0000000..5bb35cf --- /dev/null +++ b/i3pystatus/sge.py @@ -0,0 +1,53 @@ +import subprocess + +from lxml import etree + +from i3pystatus import IntervalModule + + +class SGETracker(IntervalModule): + """ + Used to display status of Batch computing jobs on a cluster running Sun Grid Engine. + The data is collected via ssh, so a valid ssh address must be specified. + + Requires lxml. + """ + + interval = 60 + + settings = ( + ("ssh", "The SSH connection address. Can be user@host or user:password@host or user@host -p PORT etc."), + 'color', 'format' + ) + required = ("ssh",) + + format = "SGE qw: {queued} / r: {running} / Eqw: {error}" + on_leftclick = None + color = "#ffffff" + + def parse_qstat_xml(self): + xml = subprocess.check_output("ssh {0} \"qstat -f -xml\"".format(self.ssh), stderr=subprocess.STDOUT, + shell=True) + root = etree.fromstring(xml) + jobs = root.xpath('//job_info/job_info/job_list') + + job_dict = {'qw': 0, 'Eqw': 0, 'r': 0} + + for j in jobs: + job_dict[j.find("state").text] += 1 + + return job_dict + + def run(self): + jobs = self.parse_qstat_xml() + + fdict = { + "queued": jobs['qw'], + "error": jobs['Eqw'], + "running": jobs['r'] + } + + self.output = { + "full_text": self.format.format(**fdict).strip(), + "color": self.color + }