diff options
-rw-r--r-- | .rubocop.yml | 7 | ||||
-rw-r--r-- | slurm_number_jobs.rb | 34 |
2 files changed, 41 insertions, 0 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index 48211dc..303f329 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,12 @@ Layout/LineLength: Max: 80 +Metrics/MethodLength: + CountAsOne: + - 'array' + - 'hash' + - 'heredoc' + Max: 20 + AllCops: NewCops: enable diff --git a/slurm_number_jobs.rb b/slurm_number_jobs.rb new file mode 100644 index 0000000..91fe630 --- /dev/null +++ b/slurm_number_jobs.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +# Report the number of jobs currently in queue, +# aggregated by state, user, and partition +class SlurmNumberJobs + def initialize(collector, config) + @collector = collector + @config = config + end + + def raid + raw = `squeue --format="%P,%u,%T" --noheader` + raw = raw.lines.map(&:strip) + raw = raw.map { |line| line.split(',') } + + tally = raw.tally + + @collector.redact!('slurm_number_jobs') + + tally.each do |labelset, number| + @collector.report!( + 'slurm_number_jobs', + number, + help: 'Number of jobs for a given user, partition, and state', + type: 'gauge', + labels: { + partition: labelset[0], + user: labelset[1], + state: labelset[2] + } + ) + end + end +end |