#NEWLINE# def print_header( procs_status , num_procs ) : #NEWLINE# #INDENT# 'Print system-related info, above the process list.' #NEWLINE# def get_dashes( perc ) : #NEWLINE# #INDENT# dashes = ( '|' * int ( ( ( float ( perc ) / 10 ) * 4 ) ) ) #NEWLINE# empty_dashes = ( ' ' * ( 40 - len ( dashes ) ) ) #NEWLINE# return ( dashes , empty_dashes ) #NEWLINE# #UNINDENT# percs = psutil . cpu_percent ( interval = 0 , percpu = True ) #NEWLINE# for ( cpu_num , perc ) in enumerate ( percs ) : #NEWLINE# #INDENT# ( dashes , empty_dashes ) = get_dashes ( perc ) #NEWLINE# print_line ( ( ' CPU%-2s [%s%s] %5s%%' % ( cpu_num , dashes , empty_dashes , perc ) ) ) #NEWLINE# #UNINDENT# mem = psutil . virtual_memory ( ) #NEWLINE# ( dashes , empty_dashes ) = get_dashes ( mem . percent ) #NEWLINE# used = ( mem . total - mem . available ) #NEWLINE# line = ( ' Mem   [%s%s] %5s%% %6s/%s' % ( dashes , empty_dashes , mem . percent , ( str ( int ( ( ( used / 1024 ) / 1024 ) ) ) + 'M' ) , ( str ( int ( ( ( mem . total / 1024 ) / 1024 ) ) ) + 'M' ) ) ) #NEWLINE# print_line ( line ) #NEWLINE# swap = psutil . swap_memory ( ) #NEWLINE# ( dashes , empty_dashes ) = get_dashes ( av2 . percent ) #NEWLINE# line = ( ' Swap  [%s%s] %5s%% %6s/%s' % ( dashes , empty_dashes , swap . percent , ( str ( int ( ( ( swap . used / 1024 ) / 1024 ) ) ) + 'M' ) , ( str ( int ( ( ( swap . total / 1024 ) / 1024 ) ) ) + 'M' ) ) ) #NEWLINE# print_line ( line ) #NEWLINE# st = [ ] #NEWLINE# for ( x , y ) in procs_status . items ( ) : #NEWLINE# #INDENT# if y : #NEWLINE# #INDENT# st . append ( ( '%s=%s' % ( x , y ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# st . sort ( key = ( lambda x : ( x [ : 3 ] in ( 'run' , 'sle' ) ) ) , reverse = 1 ) #NEWLINE# print_line ( ( ' Processes: %s (%s)' % ( num_procs , ', ' . join ( st ) ) ) ) #NEWLINE# uptime = ( datetime . now ( ) - datetime . fromtimestamp ( psutil . boot_time ( ) ) ) #NEWLINE# ( av1 , av2 , av3 ) = os . getloadavg ( ) #NEWLINE# line = ( ' Load average: %.2f %.2f %.2f  Uptime: %s' % ( av1 , av2 , av3 , str ( uptime ) . split ( '.' ) [ 0 ] ) ) #NEWLINE# print_line ( line )