diff options
| author | Nat Lasseter <nat.lasseter@york.ac.uk> | 2020-03-02 10:21:32 +0000 | 
|---|---|---|
| committer | Nat Lasseter <nat.lasseter@york.ac.uk> | 2020-03-02 10:21:32 +0000 | 
| commit | cd0f6b103553f547bc21a8447e785c31f7ce858c (patch) | |
| tree | 9002b355cb4038f6c3e31d2e65ce8e74bceca3fa /lib/longboat/jobs | |
| parent | 6c192e01dad7e9947c466eff521fe22ac775fcd6 (diff) | |
Use classes properly
Diffstat (limited to 'lib/longboat/jobs')
| -rw-r--r-- | lib/longboat/jobs/slurm_job_states.rb | 31 | 
1 files changed, 31 insertions, 0 deletions
| diff --git a/lib/longboat/jobs/slurm_job_states.rb b/lib/longboat/jobs/slurm_job_states.rb new file mode 100644 index 0000000..74c7999 --- /dev/null +++ b/lib/longboat/jobs/slurm_job_states.rb @@ -0,0 +1,31 @@ +module Longboat +  module Jobs +    class SlurmJobStates +      def initialize(collector) +        @collector = collector +        @collector.register!(self) +      end + +      def run +        start_time = (Time.now - 15 * 60).strftime("%H:%M:%S") +        raw = `sacct -a -P -o State -S #{start_time}`.lines.map(&:strip)[1..-1] + +        tally = Hash.new{0} + +        raw.each do |state| +          tally[state] += 1 +        end + +        tally.each do |state, number| +          @collector.report!( +            "longboat_slurm_job_states", +            number, +            help: "Number of jobs in each state", +            type: "gauge", +            labels: {state: state} +          ) +        end +      end +    end +  end +end | 
