aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Lasseter <nat.lasseter@york.ac.uk>2020-07-15 14:50:35 +0100
committerNat Lasseter <nat.lasseter@york.ac.uk>2020-07-15 14:50:35 +0100
commitb2ec20bcf89ea65d5be0e94b26b9579185a8d6f0 (patch)
tree9fbe5dee394efce65946aecffb09843b27d43afd
parentd166a073ad3a32af77152bf4b16206c32f9890b6 (diff)
remove 'by xxxxxx' from states
-rw-r--r--slurm_job_states.rb24
1 files changed, 11 insertions, 13 deletions
diff --git a/slurm_job_states.rb b/slurm_job_states.rb
index 20b69c8..2881d68 100644
--- a/slurm_job_states.rb
+++ b/slurm_job_states.rb
@@ -7,21 +7,19 @@ class SlurmJobStates
def raid
start_time = (Time.now - @interval).strftime("%H:%M:%S")
- # Get raw data from sacct,
- # read jobs into an array,
- # remove any whitespace from the ends of each string,
- # drop the header,
- # and split each line into state and partition
- raw = `sacct -a -P -o State,Partition -S #{start_time}`.
- lines.
- map(&:strip)[1..-1].
- map{|l|l.split("|")}
+ # Get raw data from sacct and read jobs into an array
+ raw = `sacct -a -P -o State,Partition -S #{start_time}`.lines
+ # remove any whitespace from the ends of each string
+ raw = raw.map(&:strip)
+ # drop the header line
+ raw = raw[1..-1]
+ # split each line into state and partition
+ raw = raw.map{ |l| l.split("|") }
+ # and remove the "by xxxxxx" from CANCELLED jobs
+ raw = raw.map { |state, partition| [state.split[0], partition] }
# Make a tally of each state/partition combo
- tally = Hash.new{0}
- raw.each do |job|
- tally[job] += 1
- end
+ tally = raw.tally
# Clean up any previously reported metrics
# to prevent stale labelsets