-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue_check.py
executable file
·75 lines (61 loc) · 1.83 KB
/
queue_check.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python2
import os, sys, subprocess
queue=None
full = False
if len(sys.argv) == 2:
queue = sys.argv[1]
elif len(sys.argv) == 3 and sys.argv[1] == "--full":
full = True
queue = sys.argv[2]
else:
print("USAGE: [--full] <queue>")
sys.exit(1)
command = "squeue -o \"%.18i %.20P %.20u %.2t %.6D\" | grep " + queue
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = proc.communicate()
users = []
userQueuedJobs = {}
userRunningJobs = {}
userNodes = {}
queuedJobs = 0
runningJobs = 0
usedNodes = 0
for line1 in output[0].split("\\n"):
for line in line1.split("\n"):
split = line.split()
if len(split) == 5:
job = split[0]
user = split[2]
state = split[3]
nodes = int(split[4])
if user not in users:
users.append(user)
userQueuedJobs[user] = []
userRunningJobs[user] = []
userNodes[user] = 0
if state == "R":
userRunningJobs[user].append(job)
runningJobs += 1
userNodes[user] += nodes
usedNodes += nodes
else:
userQueuedJobs[user].append(job)
queuedJobs += 1
elif len(split) > 0:
print "bad split (len " + str(len(split)) + "): " + str(split)
print str(len(users))+" users running "+str(runningJobs)+" jobs on "+str(usedNodes)+" nodes, "+str(queuedJobs)+" queued jobs"
totNodes = 0
for user in users:
runningJobs = userRunningJobs[user]
queuedJobs = userQueuedJobs[user]
nodes = userNodes[user]
print "user: " + user + ",\trunning: " + str(len(runningJobs)) + " (" + str(nodes) + " nodes),\tqueued: " + str(len(queuedJobs))
totNodes += nodes
print "Total nodes in use: " + str(totNodes)
if full:
for user in users:
command = "squeue -u " + user
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out = proc.communicate()[0]
for line1 in out.split("\\n"):
print line1