From bc57c085e987f831ee50798109d6bc114182c22c Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Wed, 11 Nov 2020 14:57:09 +0000 Subject: New raider: number of jobs by partition, user, and state --- slurm_number_jobs.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 slurm_number_jobs.rb diff --git a/slurm_number_jobs.rb b/slurm_number_jobs.rb new file mode 100644 index 0000000..0dd3385 --- /dev/null +++ b/slurm_number_jobs.rb @@ -0,0 +1,31 @@ +class SlurmNumberJobs + def initialize(collector, config) + @collector = collector + @config = config + end + + def raid + raw = `squeue --format="%P,%u,%T" --noheader` + raw = raw.lines + raw = raw.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 -- cgit v1.2.1 From fdc0cc08592e4606e684951b5e2503832b15d148 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Wed, 11 Nov 2020 15:43:56 +0000 Subject: slurm_number_jobs rubocop fixes --- .rubocop.yml | 7 +++++++ slurm_number_jobs.rb | 17 ++++++++++------- 2 files changed, 17 insertions(+), 7 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 index 0dd3385..91fe630 100644 --- a/slurm_number_jobs.rb +++ b/slurm_number_jobs.rb @@ -1,3 +1,7 @@ +# 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 @@ -6,20 +10,19 @@ class SlurmNumberJobs def raid raw = `squeue --format="%P,%u,%T" --noheader` - raw = raw.lines - raw = raw.map(&:strip) - raw = raw.map{ |line| line.split(',') } + raw = raw.lines.map(&:strip) + raw = raw.map { |line| line.split(',') } tally = raw.tally - @collector.redact!("slurm_number_jobs") + @collector.redact!('slurm_number_jobs') tally.each do |labelset, number| @collector.report!( - "slurm_number_jobs", + 'slurm_number_jobs', number, - help: "Number of jobs for a given user, partition, and state", - type: "gauge", + help: 'Number of jobs for a given user, partition, and state', + type: 'gauge', labels: { partition: labelset[0], user: labelset[1], -- cgit v1.2.1