Processing squeue JSON output


squeue can produce JSON output with squeue --json.That could be processed with a script but you can do some quick hacks with jq.

Show just a few job fields

$ squeue --json | jq '.jobs[] | {job_id, user_name, account}'
{
  "job_id": 66793003,
  "user_name": "foo",
  "account": "def-foo_cpu"
}
{
  "job_id": 66844842,
  "user_name": "bar",
  "account": "def-bar_cpu"
}
...

List of all accounts currently running jobs, output in raw format

$ squeue --json | jq -r '.jobs | map(.account) | unique | .[]'
cc-debug_cpu
ctb-aaaa-ab_cpu
ctb-aaaa_cpu
ctb-aaaa_gpu
ctb-bbbb_cpu
ctb-cccc_gpu
ctb-dddd_gpu
def-eeee_cpu

How many unique accounts are running jobs?

$ squeue --json | jq '.jobs | map(.account) | unique | length'
251

How many jobs in each partition?

$ squeue --json | jq -r 'reduce .jobs[] as $job ({}; .[$job.partition] |= . + 1)'                            
{
  "cpubase_bycore_b1,cpubackfill": 241,
  "cpubase_bynode_b1,cpubackfill": 6,
  "cpubase_bycore_b5": 2309,
  "cpubase_bynode_b3,cpubackfill": 153,
  "cpubase_bycore_b3,cpubackfill": 2,
  "cpularge_bycore_b3,cpubackfill": 17,
  "cpubase_bycore_b4": 2696,
  "cpularge_bycore_b1,cpubackfill": 48,
  "cpubackfill,cpubase_bynode_b1": 2,
  "cpularge_bycore_b4": 81,
  "cpubase_bynode_b4": 299,
  "cpubase_bynode_b3": 29,
  "cpubase_bynode_b5": 78,
  "gpubase_bynode_b5": 18,
  "gpubase_bygpu_b5": 125,
  "cpubackfill,cpularge_bycore_b3": 1,
  "cpularge_bycore_b5": 78,
  "gpubase_bygpu_b4": 681,
  "cpularge_bynode_b5": 39,
  "cpubackfill,cpubase_bycore_b1": 1,
  "cpubackfill,cpubase_bynode_b3": 14,
  "gpubase_bynode_b4": 47,
  "gpubase_bygpu_b2,gpubackfill": 2,
  "cpularge_bynode_b4": 4,
  "gpubase_bygpu_b3": 31,
  "c-enamul": 1,
  "cpubase_bycore_b3": 414,
  "gpubase_bygpu_b3,gpubackfill": 8,
  "cpubackfill": 34,
  "gpubackfill": 7,
  "cpularge_bycore_b3": 31,
  "cpubase_bycore_b2": 17,
  "cpularge_bynode_b3": 2,
  "cpubase_bynode_b2": 36,
  "cpularge_bycore_b2,cpubackfill": 4,
  "cpularge_bycore_b2": 14,
  "cpubase_bycore_b1": 101,
  "cpubase_bynode_b1": 2,
  "gpubase_bygpu_b2": 3,
  "cpularge_bynode_b3,cpubackfill": 3,
  "gpubase_bygpu_b1": 5,
  "gpubase_bygpu_b1,gpubackfill": 1,
  "cpularge_bycore_b1": 1,
  "cpubase_bynode_b2,cpubackfill": 1
}

Show as an array of key/value pairs (for easier filtering)

$ squeue --json | jq -r 'reduce .jobs[] as $job ({}; .[$job.partition] |= . + 1) | to_entries'           
[
  {
    "key": "cpubase_bycore_b1,cpubackfill",
    "value": 241
  },
  {
    "key": "cpubase_bynode_b1,cpubackfill",
    "value": 6
  },
  {
    "key": "cpubase_bycore_b5",
    "value": 2309
  },
...

Filter them to show only partitions with at least 100 jobs

(And we convert back to a JSON object after filtering for easier reading.)

$ squeue --json | jq -r 'reduce .jobs[] as $job ({}; .[$job.partition] |= . + 1) | to_entries | map(select(.value >= 100)) | from_entries'
{
  "cpubase_bycore_b1,cpubackfill": 241,
  "cpubase_bycore_b5": 2309,
  "cpubase_bynode_b3,cpubackfill": 153,
  "cpubase_bycore_b4": 2696,
  "cpubase_bynode_b4": 299,
  "gpubase_bygpu_b5": 125,
  "gpubase_bygpu_b4": 681,
  "cpubase_bycore_b3": 414,
  "cpubase_bycore_b1": 101
}

Show the top five

$ squeue --json | jq -r 'reduce .jobs[] as $job ({}; .[$job.partition] |= . + 1) | to_entries | sort_by(.value) | reverse | .[:5] | from_entries'
{
  "cpubase_bycore_b4": 2696,
  "cpubase_bycore_b5": 2309,
  "gpubase_bygpu_b4": 681,
  "cpubase_bycore_b3": 414,
  "cpubase_bynode_b4": 299
}

See also