aboutsummaryrefslogtreecommitdiff
path: root/pending_on_qos.rb
blob: 7d99c8c5db50429b8012b9a364742f8c894b2aab (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

# For each Viking partition, report the number of jobs pending due to QoS
# reasons.
class PendingOnQos
  def initialize(collector, config)
    @collector = collector
    @partition_thresholds = {
      nodes: 604_800,
      week: 1_209_600,
      month: 2_419_200,
      himem: 604_800,
      himem_week: 1_209_600,
      gpu: 604_800,
      interactive: 900,
      test: 900,
      preempt: 2_419_200
    }
  end

  def raid
    @partition_thresholds.each do |partition, threshold|
      start_time = (Time.now - threshold).strftime('%Y-%m-%d')

      squeue_cmd = [
        'squeue',
        '--format="%A,%R,%V"',
        '--noheader',
        "--partition=#{partition}",
        '--state=PENDING'
      ].join(' ')
      
      output = `#{squeue_cmd}`.split('\n') 

      puts output
    end

    @collector.report!(
      'pending_on_qos',
      255,
      {
        help: 'Number of jobs pending for QoS reasons',
        type: 'gauge',
        labels: {
          partition: 'nodes'
        }
      }
    )
  end
end