aboutsummaryrefslogtreecommitdiff
path: root/slurm_number_jobs.rb
blob: 2a0870441f0355a942791b3cc4207fdf2c53f789 (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
28
29
30
31
32
33
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 = `/usr/bin/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