Skip to content

Instantly share code, notes, and snippets.

@misshie
Last active October 28, 2016 01:56
Show Gist options
  • Save misshie/867cc1fc58e85471a98a to your computer and use it in GitHub Desktop.
Save misshie/867cc1fc58e85471a98a to your computer and use it in GitHub Desktop.
Modified GridEngine's qstat command showing longer job names
#!/usr/bin/env ruby
# License: the MIT lincense.
# Copyright: MISHIMA, Hiroyuki hmishima at nagasaki-u.ac.jp, 2015
require 'rexml/document'
class Qstat2
JOBNAME_WIDTH = 65
def initialize
@running = 0
@pending = 0
end
def report(jname, state, slots)
puts "#{jname.to_s.ljust(JOBNAME_WIDTH)} #{state.to_s.ljust(10)} #{slots.to_s.ljust(5)}"
end
def stat_count(stat)
case
when stat.to_s.include?("running")
@running += 1
when stat.to_s.include?("pending")
@pending += 1
end
end
def run
doc = REXML::Document.new `qstat -xml`
jinfo = doc.elements["//job_info"]
puts "#{'Job_name'.ljust(JOBNAME_WIDTH)} #{'status'.ljust(10)} #{'slots'.ljust(5)}"
jinfo.each_element("queue_info/job_list") do |job|
jname = job.elements["JB_name"].text
state = job.attribute("state")
slots = job.elements["slots"].text
report(jname, state, slots)
stat_count(state)
end
jinfo.each_element("job_info/job_list") do |job|
jname = job.elements["JB_name"].text
state = job.attribute("state")
slots = job.elements["slots"].text
report(jname, state, slots)
stat_count(state)
end
puts
puts "Running = #{@running}, Pending = #{@pending}"
end
end
if $0 == __FILE__
Qstat2.new.run
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment