
Untitled
By: a guest on
Apr 16th, 2012 | syntax:
None | size: 1.01 KB | hits: 11 | expires: Never
#!/usr/bin/env ruby19
class Job
def initialize(line)
@f = line.split
end
def user
@f[1]
end
def status
@f[2]
end
def running?
status == 'RUN'
end
end
stats = Hash.new {|h,k| h[k] = {:running => 0, :other => 0} }
`bjobs -u all | grep -v JOBID`.each_line do |line|
j = Job.new(line)
if j.running?
stats[j.user][:running] += 1
else
stats[j.user][:other] += 1
end
end
total_run = 0
total_others = 0
puts "-" * 80
stats.each do |user, jobs|
printf "%8s" % user
printf ": R{%3s}" % jobs[:running]
printf ": O{%3s}" % jobs[:other]
printf ": T{%3s}\n" % (jobs[:other] + jobs[:running])
total_run += jobs[:running]
total_others += jobs[:other]
end
puts "-" * 80
puts "Total (R) : #{total_run}"
puts "Total (O) : #{total_others}"
puts " (R+O): #{total_others + total_run}"
puts "-" * 80
a_hosts = `bjobs -u all | grep RUN | awk '{print $6}' | sort | uniq | wc -l`
puts "# Active hosts: " + a_hosts