-
Notifications
You must be signed in to change notification settings - Fork 1
/
pbs_qstatsum.py
141 lines (112 loc) · 4.93 KB
/
pbs_qstatsum.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import subprocess as sp
import pandas as pd
import json
import argparse
def get_integers(stringtime):
hr,min,sec = stringtime.split(':')
hr,min,sec = int(hr),int(min),int(sec)
return hr,min,sec
def string_time_to_seconds(stringtime):
hr,min,sec = get_integers(stringtime)
return hr * 60 * 60 + min * 60 + sec
def string_time_to_minutes(stringtime):
hr,min,sec = get_integers(stringtime)
return hr * 60 + min
def string_time_to_hours(stringtime):
hr,min,sec = get_integers(stringtime)
return float(hr) + float(min)/60. + float(sec/60./60.)
def walltime_to_hours(walltime):
return string_time_to_hours(walltime)
def job_sort_formula(jobdata):
rl = jobdata['Resource_List']
base_score = float(rl['base_score'])
score_boost = float(rl['score_boost'])
enable_wfp = float(rl['enable_wfp'])
wfp_factor = float(rl['wfp_factor'])
eligible_time = float(string_time_to_seconds(jobdata['eligible_time']))
walltime = float(string_time_to_seconds(rl['walltime']))
project_priority = float(rl['project_priority'])
nodect = float(rl['nodect'])
total_cpus = float(rl['total_cpus'])
enable_backfill = float(rl['enable_backfill'])
backfill_max = float(rl['backfill_max'])
backfill_factor = float(rl['backfill_factor'])
enable_fifo = float(rl['enable_fifo'])
fifo_factor = float(rl['fifo_factor'])
return ( base_score +
score_boost +
(enable_wfp * wfp_factor * (eligible_time ** 2 / min(max(walltime,21600.0),43200.0) ** 3 * project_priority * nodect / total_cpus)) +
(enable_backfill * min(backfill_max, eligible_time / backfill_factor)) +
(enable_fifo * eligible_time / fifo_factor) )
def main():
parser = argparse.ArgumentParser(description='extract monitoring information from qstat')
parser.add_argument('-r','--running',help='summarize running jobs',action='store_true')
parser.add_argument('-q','--queued',help='summarize queued jobs',action='store_true')
parser.add_argument('-s','--score',help='summarize top jobs in each queue by score',action='store_true')
parser.add_argument('-c','--countdown',help='list running jobs with smallest walltime remaining',action='store_true')
parser.add_argument('-t','--topn',help='how many jobs to print',default=5,type=int)
args = parser.parse_args()
# run qstat to get json output
completed_process = sp.run('/opt/pbs/bin/qstat -f -F json'.split(),capture_output=True)
assert completed_process.returncode == 0
qdata = json.loads(completed_process.stdout)
running_by_queue = {}
queued_by_queue = {}
running_jobs = 0
running_nodes = 0
running_debug = 0
total_nodes = 560
total_prod_nodes = 496
queued_jobs = 0
queued_nodes = 0
queued_debug = 0
queue_node_breakdown = {}
job_data = []
# check running jobs
for jobname,jobdata in qdata['Jobs'].items():
jobid = int(jobname.split('.')[0].replace('[]',''))
state = jobdata['job_state']
qname = jobdata['queue']
nnodes = jobdata['Resource_List']['nodect']
project = jobdata['project']
walltime = walltime_to_hours(jobdata['Resource_List']['walltime'])
nodehours = nnodes * walltime
username = jobdata['Variable_List']['PBS_O_LOGNAME']
try:
remaining_runtime_min = string_time_to_minutes(jobdata['Resource_List']['walltime']) - string_time_to_minutes(jobdata['resources_used']['walltime'])
except:
remaining_runtime_min = string_time_to_minutes(jobdata['Resource_List']['walltime'])
job_data.append({
'id':jobid,
'state':state,
'queue':qname,
'nodes':int(nnodes),
'project':project,
'wallhours':int(walltime),
'nodehours':int(nodehours),
'username':username,
'score':job_sort_formula(jobdata),
'runtime_left':remaining_runtime_min
})
df = pd.DataFrame(job_data)
if(args.running):
print('\nRunning:')
dfr = df[df['state']=='R'][['queue','nodes','nodehours']]
print(dfr.groupby(['queue']).sum())
if(args.queued):
print('\nQueued:')
dfq = df[df['state']=='Q'][['queue','nodes','nodehours']]
print(dfq.groupby(['queue']).sum())
if(args.score):
topn=args.topn
print('\nTop %d Queued Large Jobs:' % topn)
print(df[(df['state']=='Q') & (df['queue'] == 'large')].nlargest(topn,'score').to_string(index=False))
print('\nTop %d Queued Medium Jobs:' % topn)
print(df[(df['state']=='Q') & (df['queue'] == 'medium')].nlargest(topn,'score').to_string(index=False))
print('\nTop %d Queued Small Jobs:' % topn)
print(df[(df['state']=='Q') & (df['queue'] == 'small')].nlargest(topn,'score').to_string(index=False))
if(args.countdown):
print('\n Jobs about to Finish:')
print(df[df['state']=='R'].nsmallest(args.topn,'runtime_left').to_string(index=False))
if __name__ == "__main__":
main()