aboutsummaryrefslogtreecommitdiff
path: root/lib/jobs/slurm_job_states.rb
blob: 9d4ea94b034dc74f7a0c66a9a4a3ce94dd128021 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class SlurmJobStates
  def initialize(collector, config)
    @collector = collector
    @interval = config[:collect_every]
  end

  def run
    start_time = (Time.now - @interval).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