A new doc condor_config.html is being added showing the condor configuration
[burt-test.git] / tools / glidein_status.py
blob2da908599ce2df8c22ecd4bf480924c702717345
1 #!/usr/bin/env python
3 # Project:
4 # glideinWMS
6 # File Version:
7 # $Id: glidein_status.py,v 1.34 2011/02/10 21:35:31 parag Exp $
9 # Description:
10 # Equivalent to condor_status, but with glidein specific info
12 # Usage:
13 # glidein_status.py [-help] [-gatekeeper] [-glidecluster] [-withmonitor] [-total] [-site] [-pool name]
15 # Author:
16 # Igor Sfiligoi
19 def help():
20 print "glidein_status.py [-help] [-gatekeeper] [-glidecluster] [-glexec] [-withmonitor] [-bench] [-total] [-site] [-pool name] [-constraint name]"
21 print
22 print "Options:"
23 print " -gatekeeper : Print out the glidein gatekeeper"
24 print " -glidecluster : Print out the glidein cluster nr"
25 print " -glexec : Print out if glexec is used"
26 print " -withmonitor : Print out the monitoring VMs, too"
27 print " -bench : Print out the benchmarking numbers, too"
28 print " -total : Print out only the totals (skip details)"
29 print " -site : Summarize by site (default by entry name)"
30 print " -pool : Same as -pool in condor_status"
31 print " -constraint : Same as -constraint in condor_status"
32 print
35 import time
36 import sys,os.path
37 sys.path.append(os.path.join(sys.path[0],"../lib"))
39 import condorMonitor
41 pool_name=None
42 constraint=None
44 want_gk=False
45 want_glidecluster=False
46 want_monitor=False
47 want_bench=False
48 want_glexec=False
49 total_only=False
50 summarize='entry'
52 arglen=len(sys.argv)
53 i=1
54 while i<arglen:
55 arg=sys.argv[i]
57 if arg=='-gatekeeper':
58 want_gk=True
59 elif arg=='-glidecluster':
60 want_glidecluster=True
61 elif arg=='-glexec':
62 want_glexec=True
63 elif arg=='-withmonitor':
64 want_monitor=True
65 elif arg=='-bench':
66 want_bench=True
67 elif arg=='-total':
68 total_only=True
69 elif arg=='-site':
70 summarize='site'
71 elif arg=='-pool':
72 i+=1
73 pool_name=sys.argv[i]
74 elif arg=='-constraint':
75 i+=1
76 constraint=sys.argv[i]
77 else:
78 help()
79 sys.exit(1)
81 i+=1
83 if not want_monitor:
84 if constraint==None:
85 constraint='IS_MONITOR_VM =!= TRUE'
86 else:
87 constraint='(%s) && (IS_MONITOR_VM =!= TRUE)'%constraint
89 format_list=[('Machine','s'),('State','s'),('Activity','s'),
90 ('GLIDEIN_Site','s'),
91 ('GLIDEIN_Factory','s'),('GLIDEIN_Name','s'),('GLIDEIN_Entry_Name','s'),('EnteredCurrentActivity','i')]
92 attrs=['State','Activity','GLIDEIN_Site','GLIDEIN_Factory','GLIDEIN_Name','GLIDEIN_Entry_Name','EnteredCurrentActivity']
94 if want_gk:
95 format_list.append(('GLIDEIN_Gatekeeper','s'))
96 format_list.append(('GLIDEIN_GridType','s'))
97 attrs.append('GLIDEIN_Gatekeeper')
98 attrs.append('GLIDEIN_GridType')
100 if want_glidecluster:
101 format_list.append(('GLIDEIN_ClusterId','i'))
102 format_list.append(('GLIDEIN_ProcId','i'))
103 format_list.append(('GLIDEIN_Schedd','s'))
104 attrs.append('GLIDEIN_ClusterId')
105 attrs.append('GLIDEIN_ProcId')
106 attrs.append('GLIDEIN_Schedd')
108 if want_glexec:
109 format_list.append(('GLEXEC_STARTER','b'))
110 format_list.append(('GLEXEC_JOB','b'))
111 attrs.append('GLEXEC_STARTER')
112 attrs.append('GLEXEC_JOB')
114 if want_bench:
115 format_list.append(('KFlops','i'))
116 format_list.append(('Mips','i'))
117 attrs.append('KFlops')
118 attrs.append('Mips')
120 cs=condorMonitor.CondorStatus(pool_name=pool_name)
121 cs.load(constraint=constraint,format_list=format_list)
123 data=cs.stored_data
124 keys=data.keys()
126 # sort on the Machine attribute
127 def machine_cmp(x,y):
128 res=cmp(data[x]['Machine'],data[y]['Machine'])
129 if res==0:
130 res=cmp(x,y)
131 return res
133 keys.sort(machine_cmp)
136 counts_header=('Total','Owner','Claimed/Busy','Claimed/Retiring','Claimed/Other','Unclaimed','Matched','Other')
138 if want_bench:
139 counts_header+=('GFlops',' GIPS')
141 now=long(time.time())
142 def fmt_time(t):
143 diff=now-t
144 diff_secs=diff%60
145 diff=diff/60
146 diff_mins=diff%60
147 diff=diff/60
148 diff_hours=diff%24
149 diff_days=diff/24
150 return "%i+%02i:%02i:%02i"%(diff_days,diff_hours,diff_mins,diff_secs)
153 print_mask="%-39s %-9s"
154 if want_gk:
155 print_mask+=" %-5s %-43s"
156 print_mask+=" %-19s %-19s"
157 if want_glidecluster:
158 print_mask+=" %-39s %-14s"
159 if want_glexec:
160 print_mask+=" %-7s"
161 if want_bench:
162 print_mask+=" %-5s %-5s"
163 print_mask+=" %-9s %-8s %-10s"
165 header=('Name','Site')
166 if want_gk:
167 header+=('Grid','Gatekeeper')
168 header+=('Factory','Entry')
169 if want_glidecluster:
170 header+=('GlideSchedd','GlideCluster')
171 if want_glexec:
172 header+=('gLExec',)
173 if want_bench:
174 header+=('MFlop','Mips')
175 header+=('State','Activity','ActvtyTime')
177 if not total_only:
178 print
179 print print_mask%header
180 print
182 counts={'Total':{}}
183 for c in counts_header:
184 counts['Total'][c]=0
186 for vm_name in keys:
187 el=data[vm_name]
189 cel={} # this will have all the needed attributes (??? if nothing else)
190 for a in attrs:
191 if el.has_key(a):
192 cel[a]=el[a]
193 else:
194 cel[a]='???'
195 if cel['EnteredCurrentActivity']!='???':
196 cel['EnteredCurrentActivity']=fmt_time(long(cel['EnteredCurrentActivity']))
198 state=cel['State']
199 activity=cel['Activity']
201 if el.has_key('KFlops'):
202 gflops=(el['KFlops']*1.e-6)
203 mflops_str="%i"%(el['KFlops']/1000)
204 else:
205 mflops=0.0
206 mflops_str="???"
208 if el.has_key('Mips'):
209 gips=el['Mips']*1.e-3
210 mips_str=el['Mips']
211 else:
212 mips=0.0
213 mips_str="???"
215 if summarize=='site':
216 sum_str=cel['GLIDEIN_Site']
217 else:
218 sum_str="%s@%s@%s"%(cel['GLIDEIN_Entry_Name'],cel['GLIDEIN_Name'],cel['GLIDEIN_Factory'])
219 if not counts.has_key(sum_str):
220 counts[sum_str]={}
221 for c in counts_header:
222 counts[sum_str][c]=0
224 for t in ('Total',sum_str):
225 ct=counts[t]
226 ct['Total']+=1
227 if state in ('Owner','Unclaimed','Matched'):
228 ct[state]+=1
229 elif state=='Claimed':
230 if activity in ('Busy','Retiring'):
231 ct['%s/%s'%(state,activity)]+=1
232 else:
233 ct['Claimed/Other']+=1
234 else:
235 ct['Other']+=1
236 if want_bench:
237 ct['GFlops']+=gflops
238 ct[' GIPS']+=gips
241 if not total_only:
242 print_arr=(vm_name,cel['GLIDEIN_Site'])
243 if want_gk:
244 print_arr+=(cel['GLIDEIN_GridType'],cel['GLIDEIN_Gatekeeper'])
245 print_arr+=("%s@%s"%(cel['GLIDEIN_Name'],cel['GLIDEIN_Factory']),cel['GLIDEIN_Entry_Name'])
246 if want_glidecluster:
247 print_arr+=(cel['GLIDEIN_Schedd'],"%i.%i"%(cel['GLIDEIN_ClusterId'],cel['GLIDEIN_ProcId']))
248 if want_glexec:
249 glexec_str='None'
250 if el.has_key('GLEXEC_JOB') and el['GLEXEC_JOB']:
251 glexec_str='Job'
252 elif el.has_key('GLEXEC_STARTER') and el['GLEXEC_STARTER']:
253 glexec_str='Starter'
254 print_arr+=(glexec_str,)
255 if want_bench:
256 print_arr+=(mflops_str,mips_str)
257 print_arr+=(state,activity,cel['EnteredCurrentActivity'])
259 print print_mask%print_arr
261 print
263 count_print_mask="%39s"
264 for c in counts_header:
265 count_print_mask+=" %%%is"%len(c)
266 print count_print_mask%(('',)+counts_header)
268 ckeys=counts.keys()
270 def ltotal_cmp(x,y): # Total last
271 # Total always last
272 if x=='Total':
273 if y=='Total':
274 return 0;
275 else:
276 return 1;
277 elif y=='Total':
278 return -1
280 return cmp(x,y)
282 def entry_cmp(x,y):
283 # Total always last
284 if x=='Total':
285 if y=='Total':
286 return 0;
287 else:
288 return 1;
289 elif y=='Total':
290 return -1
292 # split in pieces and sort end to front
293 x_arr=x.split('@')
294 y_arr=y.split('@')
295 for i in (2,1,0):
296 res=cmp(x_arr[i],y_arr[i])
297 if res!=0:
298 return res
299 return 0
301 if summarize=='site':
302 ckeys.sort(ltotal_cmp)
303 else: # default is entry
304 ckeys.sort(entry_cmp)
306 if len(ckeys)>1:
307 print # put a space before the entry names
309 for t in ckeys:
310 if t=='Total':
311 print # put an empty line before Total
312 count_print_val=[t]
313 for c in counts_header:
314 count_print_val.append(int(counts[t][c]))
316 print count_print_mask%tuple(count_print_val)
318 print