@@ -243,18 +243,21 @@ def get_jobs(conn):
243243
244244 jobs = [] # This will contain a list of dictionaries.
245245
246- # Some jobs don't yet have a particular attribute as the job hasn't started yet.
246+ # Some jobs don't yet have a particular attribute as the jobs hasn't started yet.
247247 # We have to create that key and set it to something, otherwise we get errors like:
248248 # NameError("name 'resources_used_ncpus' is not defined",)
249249 attribute_names = ['resources_used_ncpus' , 'resources_used_mem' , 'resources_used_vmem' , \
250- 'resources_used_walltime' , 'exec_host' , 'exec_vnode' , 'stime' , 'resources_time_left' ]
250+ 'resources_used_walltime' , 'exec_vnode' , 'stime' , 'etime' , 'resources_time_left' , \
251+ 'resources_used_cpupercent' ]
251252
252253 b = pbs .pbs_statjob (conn , '' , None , None )
253254 while b != None :
254255 attributes = {} # Init the dictionary to empty.
255256 # Init the values of the attributes.
256257 for name in attribute_names :
257258 attributes [name ] = ''
259+ for name in ['resources_used_walltime' , 'resources_used_cput' ]:
260+ attributes [name ] = '0:0:0'
258261
259262 attribs = b .attribs
260263 #print 'DEBUG: ----------- %s -------------------' % b.name
@@ -399,37 +402,37 @@ def job_attributes_reformat(jobs):
399402 queue codes to more understandable words, memory from bytes to MB or GB.
400403 '''
401404
402- for attributes in jobs :
405+ for job in jobs :
403406 # There are some keys that we will never use, remove them.
404- attributes .pop ('variable_list' , None )
405- attributes .pop ('submit_arguments' , None )
406- attributes .pop ('error_path' , None )
407- attributes .pop ('output_path' , None )
407+ job .pop ('variable_list' , None )
408+ job .pop ('submit_arguments' , None )
409+ job .pop ('error_path' , None )
410+ job .pop ('output_path' , None )
408411
409412 # Jobs might be split across hosts or vhosts in which case it will look like this:
410413 # e.g. exec_node = hpcnode03/1+hpcnode04/1
411414 # exec_vnode = (hpcnode03:ncpus=1:mem=5242880kb)+(hpcnode04:ncpus=1:mem=5242880kb)
412415 # Users may wish to use either exec_node or exec_vhost in their HTML templates for
413416 # displaying what host/vnode their job is running on. Here we format both into just strings.
414- if attributes ['exec_host' ]:
417+ if job ['exec_host' ]:
415418 # e.g. exec_host = hpcnode03/1+hpcnode04/1
416419 # Splitting on the + will give a list ['hpcnode03/1', 'hpcnode04/1']
417420 # Then the list comprehension and split will turn this into ['hpcnode03', 'hpcnode04']
418421 # Finally convert this into a string. Use whitespace delimiter so HTML pages will wrap it if needed.
419- attributes ['exec_host' ] = attributes ['exec_host' ].split ('+' )
420- attributes ['exec_host' ] = [s .split ('/' )[0 ] for s in attributes ['exec_host' ]]
421- attributes ['exec_host' ] = ' ' .join (attributes ['exec_host' ])
422- if attributes ['exec_vnode' ]:
422+ job ['exec_host' ] = job ['exec_host' ].split ('+' )
423+ job ['exec_host' ] = [s .split ('/' )[0 ] for s in job ['exec_host' ]]
424+ job ['exec_host' ] = ' ' .join (job ['exec_host' ])
425+ if job ['exec_vnode' ]:
423426 # e.g. exec_vnode = (hpcnode03:ncpus=1:mem=5242880kb)+(hpcnode04:ncpus=1:mem=5242880kb)
424427 # Splitting on the + will give [(hpcnode03:ncpus=1:mem=5242880kb), (hpcnode04:ncpus=1:mem=5242880kb)]
425428 # Then the list comprehension and split etc gives ['hpcnode03', 'hpcnode04']
426429 # Finally convert this into a string. Use whitespace delimiter so HTML pages will wrap it if needed.
427- attributes ['exec_vnode' ] = attributes ['exec_vnode' ].split ('+' )
428- attributes ['exec_vnode' ] = [s .split (':' )[0 ].lstrip ('(' ) for s in attributes ['exec_vnode' ]]
429- attributes ['exec_vnode' ] = ' ' .join (attributes ['exec_vnode' ])
430+ job ['exec_vnode' ] = job ['exec_vnode' ].split ('+' )
431+ job ['exec_vnode' ] = [s .split (':' )[0 ].lstrip ('(' ) for s in job ['exec_vnode' ]]
432+ job ['exec_vnode' ] = ' ' .join (job ['exec_vnode' ])
430433
431434 # This splits user_name@hostname to get just the user_name.
432- attributes ['job_owner' ] = attributes ['job_owner' ].split ('@' )[0 ]
435+ job ['job_owner' ] = job ['job_owner' ].split ('@' )[0 ]
433436
434437 # All times are in seconds since the epoch
435438 # ctime = time job was created e.g. ctime = Fri Mar 6 14:36:07 2015
@@ -439,52 +442,52 @@ def job_attributes_reformat(jobs):
439442 # mtime = time job was last modified e.g. mtime = Tue Mar 17 13:09:19 2015
440443
441444 # Calculate a wait time = time started - time entered queue. This will be in seconds.
442- if attributes ['qtime' ] and attributes ['stime' ]:
443- attributes ['wtime' ] = int (attributes ['stime' ]) - int (attributes ['qtime' ])
444- attributes ['wtime' ] = '%.0f' % (attributes ['wtime' ] / 3600.0 ) # convert to hours
445+ if job ['qtime' ] and job ['stime' ]:
446+ job ['wtime' ] = int (job ['stime' ]) - int (job ['qtime' ])
447+ job ['wtime' ] = '%.0f' % (job ['wtime' ] / 3600.0 ) # convert to hours
445448 else :
446- attributes ['wtime' ] = ''
449+ job ['wtime' ] = ''
447450
448451 # Change time since epoch to localtime.
449452 # If the job has not yet queued or started then that time will be ''.
450- if attributes ['qtime' ]:
451- attributes ['qtime' ] = _epoch_to_localtime (attributes ['qtime' ], "%Y-%m-%d at %I:%M %p" )
452- if attributes ['stime' ]:
453- attributes ['stime' ] = _epoch_to_localtime (attributes ['stime' ], "%Y-%m-%d at %I:%M %p" )
453+ if job ['qtime' ]:
454+ job ['qtime' ] = _epoch_to_localtime (job ['qtime' ], "%Y-%m-%d at %I:%M %p" )
455+ if job ['stime' ]:
456+ job ['stime' ] = _epoch_to_localtime (job ['stime' ], "%Y-%m-%d at %I:%M %p" )
454457
455458 # If the job was queued or started today remove the leading date.
456459 today = datetime .datetime .now ().strftime ('%Y-%m-%d' )
457- if today == attributes ['qtime' ].split ()[0 ]:
458- attributes ['qtime' ] = attributes ['qtime' ].replace ('%s at' % today , '' )
459- attributes ['stime' ] = attributes ['stime' ].replace ('%s at' % today , '' )
460+ if today == job ['qtime' ].split ()[0 ]:
461+ job ['qtime' ] = job ['qtime' ].replace ('%s at' % today , '' )
462+ job ['stime' ] = job ['stime' ].replace ('%s at' % today , '' )
460463
461464 # Change queue code to a word. For queue states see man qstat.
462465 states = {'B' :'Array job' , 'E' :'Exiting' ,'F' :'Finished' ,'H' :'Held' ,'M' :'Moved' ,\
463466 'Q' :'Queued' ,'R' :'Running' ,'S' :'Suspend' ,'T' :'Transiting' ,'U' :'User,suspend' ,\
464467 'W' :'Waiting' , 'X' :'Finished' }
465- attributes ['job_state' ] = states [attributes ['job_state' ]]
468+ job ['job_state' ] = states [job ['job_state' ]]
466469
467470 # Change walltimes from H:M:S to H:M
468- if attributes ['resource_list_walltime' ]:
469- (H ,M ,S ) = attributes ['resource_list_walltime' ].split (':' )
470- attributes ['resource_list_walltime' ] = '%s:%s' % (H ,M )
471+ if job ['resource_list_walltime' ]:
472+ (H ,M ,S ) = job ['resource_list_walltime' ].split (':' )
473+ job ['resource_list_walltime' ] = '%s:%s' % (H ,M )
471474
472- if attributes ['resources_used_walltime' ]:
473- (H ,M ,S ) = attributes ['resources_used_walltime' ].split (':' )
474- attributes ['resources_used_walltime' ] = '%s:%s' % (H ,M )
475- hours_used = attributes ['resources_used_walltime' ].split (':' )[0 ]
476- hours_walltime = attributes ['resource_list_walltime' ].split (':' )[0 ]
477- attributes ['resources_time_left' ] = int (hours_walltime ) - int (hours_used )
475+ if job ['resources_used_walltime' ]:
476+ (H ,M ,S ) = job ['resources_used_walltime' ].split (':' )
477+ job ['resources_used_walltime' ] = '%s:%s' % (H ,M )
478+ hours_used = job ['resources_used_walltime' ].split (':' )[0 ]
479+ hours_walltime = job ['resource_list_walltime' ].split (':' )[0 ]
480+ job ['resources_time_left' ] = int (hours_walltime ) - int (hours_used )
478481
479482 # Change memory from string in kb (eg '264501336kb') to integer Gb (eg 264).
480- if 'resource_list_mem' in attributes :
481- attributes ['resource_list_mem' ] = attributes ['resource_list_mem' ].replace ('gb' , '' )
482- if attributes ['resources_used_mem' ]:
483- m = re .match ('^([0-9]+)kb$' , attributes ['resources_used_mem' ])
484- attributes ['resources_used_mem' ] = '%d' % (int (m .group (1 ))/ 1024 / 1024 )
485- if attributes ['resources_used_vmem' ]:
486- m = re .match ('^([0-9]+)kb$' , attributes ['resources_used_vmem' ])
487- attributes ['resources_used_vmem' ] = '%d' % (int (m .group (1 ))/ 1024 / 1024 )
483+ if 'resource_list_mem' in job :
484+ job ['resource_list_mem' ] = job ['resource_list_mem' ].replace ('gb' , '' )
485+ if job ['resources_used_mem' ]:
486+ m = re .match ('^([0-9]+)kb$' , job ['resources_used_mem' ])
487+ job ['resources_used_mem' ] = '%d' % (int (m .group (1 ))/ 1024 / 1024 )
488+ if job ['resources_used_vmem' ]:
489+ m = re .match ('^([0-9]+)kb$' , job ['resources_used_vmem' ])
490+ job ['resources_used_vmem' ] = '%d' % (int (m .group (1 ))/ 1024 / 1024 )
488491
489492 return jobs
490493
0 commit comments