glances: cleanup end of line whitespace

there were a lot of lines with end of line whitespace. Clean it all up.
This commit is contained in:
Brandon Philips 2012-11-28 21:22:11 -08:00
parent d04b03036e
commit 4d472ac771
2 changed files with 106 additions and 106 deletions

View File

@ -106,7 +106,7 @@ else:
try: try:
# virtual_memory() is only available with PsUtil 0.6+ # virtual_memory() is only available with PsUtil 0.6+
psutil.virtual_memory() psutil.virtual_memory()
except: except:
try: try:
# (phy|virt)mem_usage methods only available with PsUtil 0.3.0+ # (phy|virt)mem_usage methods only available with PsUtil 0.3.0+
psutil.phymem_usage() psutil.phymem_usage()
@ -283,7 +283,7 @@ class glancesLogs:
Else: Else:
Update the existing item Update the existing item
""" """
# Add Top process sort depending on alert type # Add Top process sort depending on alert type
if (item_type.startswith("MEM")): if (item_type.startswith("MEM")):
# MEM # MEM
@ -484,7 +484,7 @@ class glancesStats:
self.glancesgrabfs = glancesGrabFs() self.glancesgrabfs = glancesGrabFs()
except Exception: except Exception:
self.glancesgrabfs = {} self.glancesgrabfs = {}
# Init the sensors stats (optionnal) # Init the sensors stats (optionnal)
if sensors_tag: if sensors_tag:
try: try:
@ -494,12 +494,12 @@ class glancesStats:
# Process list refresh # Process list refresh
self.process_list_refresh = True self.process_list_refresh = True
# Init the all_stats used by the server # Init the all_stats used by the server
# all_stats is a dict of dicts filled by the server # all_stats is a dict of dicts filled by the server
if (self.server_tag): if (self.server_tag):
self.all_stats = collections.defaultdict(dict) self.all_stats = collections.defaultdict(dict)
# Cached informations (no need to be refreshed) # Cached informations (no need to be refreshed)
# Host and OS informations # Host and OS informations
if (not self.client_tag): if (not self.client_tag):
@ -531,28 +531,28 @@ class glancesStats:
""" """
Get process (proc) statistics Get process (proc) statistics
!!! No performance gap (CPU %) !!! No performance gap (CPU %)
!!! Without: 1.5 - 2.0 !!! Without: 1.5 - 2.0
!!! With: 2.0 - 2.2 !!! With: 2.0 - 2.2
""" """
procstat = proc.as_dict(['get_memory_info', 'get_cpu_percent', 'get_memory_percent', procstat = proc.as_dict(['get_memory_info', 'get_cpu_percent', 'get_memory_percent',
'pid', 'username', 'get_nice', 'pid', 'username', 'get_nice',
'get_cpu_times', 'name', 'status', 'cmdline']) 'get_cpu_times', 'name', 'status', 'cmdline'])
if psutil_get_io_counter_tag: if psutil_get_io_counter_tag:
procstat['io_counters'] = proc.get_io_counters() procstat['io_counters'] = proc.get_io_counters()
procstat['status'] = str(procstat['status'])[:1].upper() procstat['status'] = str(procstat['status'])[:1].upper()
procstat['cmdline'] = " ".join(procstat['cmdline']) procstat['cmdline'] = " ".join(procstat['cmdline'])
return procstat return procstat
def __get_process_stats__(self, proc): def __get_process_stats__(self, proc):
""" """
Get process (proc) statistics Get process (proc) statistics
""" """
procstat = {} procstat = {}
procstat['memory_info'] = proc.get_memory_info() procstat['memory_info'] = proc.get_memory_info()
if psutil_get_cpu_percent_tag: if psutil_get_cpu_percent_tag:
procstat['cpu_percent'] = \ procstat['cpu_percent'] = \
proc.get_cpu_percent(interval=0) proc.get_cpu_percent(interval=0)
@ -582,7 +582,7 @@ class glancesStats:
procstat['cpu_times'] = proc.get_cpu_times() procstat['cpu_times'] = proc.get_cpu_times()
procstat['name'] = proc.name procstat['name'] = proc.name
procstat['cmdline'] = " ".join(proc.cmdline) procstat['cmdline'] = " ".join(proc.cmdline)
return procstat return procstat
@ -602,7 +602,7 @@ class glancesStats:
if input_stats != {}: if input_stats != {}:
self.cpu = input_stats["cpu"] self.cpu = input_stats["cpu"]
else: else:
if not hasattr(self, 'cputime_old'): if not hasattr(self, 'cputime_old'):
self.cputime_old = psutil.cpu_times() self.cputime_old = psutil.cpu_times()
self.cputime_total_old = (self.cputime_old.user + self.cputime_total_old = (self.cputime_old.user +
self.cputime_old.system + self.cputime_old.system +
@ -664,10 +664,10 @@ class glancesStats:
if input_stats != {}: if input_stats != {}:
self.percpu = input_stats["percpu"] self.percpu = input_stats["percpu"]
else: else:
if not hasattr(self, 'percputime_old'): if not hasattr(self, 'percputime_old'):
self.percputime_old = psutil.cpu_times(percpu = True) self.percputime_old = psutil.cpu_times(percpu = True)
self.percputime_total_old = [] self.percputime_total_old = []
for i in range(len(self.percputime_old)): for i in range(len(self.percputime_old)):
self.percputime_total_old.append(self.percputime_old[i].user + self.percputime_total_old.append(self.percputime_old[i].user +
self.percputime_old[i].system + self.percputime_old[i].system +
self.percputime_old[i].idle) self.percputime_old[i].idle)
@ -675,13 +675,13 @@ class glancesStats:
for i in range(len(self.percputime_old)): for i in range(len(self.percputime_old)):
if hasattr(self.percputime_old[i], 'nice'): if hasattr(self.percputime_old[i], 'nice'):
self.percputime_total_old[i] += self.percputime_old[i].nice self.percputime_total_old[i] += self.percputime_old[i].nice
for i in range(len(self.percputime_old)): for i in range(len(self.percputime_old)):
if hasattr(self.percputime_old[i], 'iowait'): if hasattr(self.percputime_old[i], 'iowait'):
self.percputime_total_old[i] += self.percputime_old[i].iowait self.percputime_total_old[i] += self.percputime_old[i].iowait
for i in range(len(self.percputime_old)): for i in range(len(self.percputime_old)):
if hasattr(self.percputime_old[i], 'irq'): if hasattr(self.percputime_old[i], 'irq'):
self.percputime_total_old[i] += self.percputime_old[i].irq self.percputime_total_old[i] += self.percputime_old[i].irq
for i in range(len(self.percputime_old)): for i in range(len(self.percputime_old)):
if hasattr(self.percputime_old[i], 'softirq'): if hasattr(self.percputime_old[i], 'softirq'):
self.percputime_total_old[i] += self.percputime_old[i].softirq self.percputime_total_old[i] += self.percputime_old[i].softirq
self.percpu = [] self.percpu = []
@ -689,26 +689,26 @@ class glancesStats:
try: try:
self.percputime_new = psutil.cpu_times(percpu = True) self.percputime_new = psutil.cpu_times(percpu = True)
self.percputime_total_new = [] self.percputime_total_new = []
for i in range(len(self.percputime_new)): for i in range(len(self.percputime_new)):
self.percputime_total_new.append(self.percputime_new[i].user + self.percputime_total_new.append(self.percputime_new[i].user +
self.percputime_new[i].system + self.percputime_new[i].system +
self.percputime_new[i].idle) self.percputime_new[i].idle)
# Only available on some OS # Only available on some OS
for i in range(len(self.percputime_new)): for i in range(len(self.percputime_new)):
if hasattr(self.percputime_new[i], 'nice'): if hasattr(self.percputime_new[i], 'nice'):
self.percputime_total_new[i] += self.percputime_new[i].nice self.percputime_total_new[i] += self.percputime_new[i].nice
for i in range(len(self.percputime_new)): for i in range(len(self.percputime_new)):
if hasattr(self.percputime_new[i], 'iowait'): if hasattr(self.percputime_new[i], 'iowait'):
self.percputime_total_new[i] += self.percputime_new[i].iowait self.percputime_total_new[i] += self.percputime_new[i].iowait
for i in range(len(self.percputime_new)): for i in range(len(self.percputime_new)):
if hasattr(self.percputime_new[i], 'irq'): if hasattr(self.percputime_new[i], 'irq'):
self.percputime_total_new[i] += self.percputime_new[i].irq self.percputime_total_new[i] += self.percputime_new[i].irq
for i in range(len(self.percputime_new)): for i in range(len(self.percputime_new)):
if hasattr(self.percputime_new[i], 'softirq'): if hasattr(self.percputime_new[i], 'softirq'):
self.percputime_total_new[i] += self.percputime_new[i].softirq self.percputime_total_new[i] += self.percputime_new[i].softirq
perpercent = [] perpercent = []
self.percpu = [] self.percpu = []
for i in range(len(self.percputime_new)): for i in range(len(self.percputime_new)):
perpercent.append(100 / (self.percputime_total_new[i] - perpercent.append(100 / (self.percputime_total_new[i] -
self.percputime_total_old[i])) self.percputime_total_old[i]))
cpu = {'kernel': cpu = {'kernel':
@ -723,7 +723,7 @@ class glancesStats:
if hasattr(self.percputime_new[i], 'nice'): if hasattr(self.percputime_new[i], 'nice'):
cpu['nice'] = (self.percputime_new[i].nice - cpu['nice'] = (self.percputime_new[i].nice -
self.percputime_old[i].nice) * perpercent[i] self.percputime_old[i].nice) * perpercent[i]
self.percpu.append(cpu) self.percpu.append(cpu)
self.percputime_old = self.percputime_new self.percputime_old = self.percputime_new
self.percputime_total_old = self.percputime_total_new self.percputime_total_old = self.percputime_total_new
except Exception: except Exception:
@ -736,7 +736,7 @@ class glancesStats:
if input_stats != {}: if input_stats != {}:
self.load = input_stats["load"] self.load = input_stats["load"]
else: else:
if hasattr(os, 'getloadavg'): if hasattr(os, 'getloadavg'):
getload = os.getloadavg() getload = os.getloadavg()
self.load = {'min1': getload[0], self.load = {'min1': getload[0],
'min5': getload[1], 'min5': getload[1],
@ -768,7 +768,7 @@ class glancesStats:
self.memswap = {'total': virtmem.total, self.memswap = {'total': virtmem.total,
'used': virtmem.used, 'used': virtmem.used,
'free': virtmem.free, 'free': virtmem.free,
'percent': virtmem.percent} 'percent': virtmem.percent}
else: else:
# For olders PsUtil version # For olders PsUtil version
# Physical memory (RAM) # Physical memory (RAM)
@ -788,7 +788,7 @@ class glancesStats:
else: else:
self.mem = {} self.mem = {}
# Virtual memory (SWAP) # Virtual memory (SWAP)
if hasattr(psutil, 'virtmem_usage'): if hasattr(psutil, 'virtmem_usage'):
virtmem = psutil.virtmem_usage() virtmem = psutil.virtmem_usage()
self.memswap = {'total': virtmem.total, self.memswap = {'total': virtmem.total,
'used': virtmem.used, 'used': virtmem.used,
@ -807,8 +807,8 @@ class glancesStats:
else: else:
if psutil_network_io_tag: if psutil_network_io_tag:
self.network = [] self.network = []
if hasattr(psutil, 'network_io_counters'): if hasattr(psutil, 'network_io_counters'):
if not hasattr(self, 'network_old'): if not hasattr(self, 'network_old'):
self.network_old = psutil.network_io_counters(True) self.network_old = psutil.network_io_counters(True)
else: else:
self.network_new = psutil.network_io_counters(True) self.network_new = psutil.network_io_counters(True)
@ -849,8 +849,8 @@ class glancesStats:
else: else:
if psutil_disk_io_tag: if psutil_disk_io_tag:
self.diskio = [] self.diskio = []
if psutil_disk_io_tag and hasattr(psutil, 'disk_io_counters'): if psutil_disk_io_tag and hasattr(psutil, 'disk_io_counters'):
if not hasattr(self, 'diskio_old'): if not hasattr(self, 'diskio_old'):
self.diskio_old = psutil.disk_io_counters(True) self.diskio_old = psutil.disk_io_counters(True)
else: else:
self.diskio_new = psutil.disk_io_counters(True) self.diskio_new = psutil.disk_io_counters(True)
@ -894,7 +894,7 @@ class glancesStats:
else: else:
if self.process_list_refresh: if self.process_list_refresh:
self.process_first_grab = False self.process_first_grab = False
if not hasattr(self, 'process_all'): if not hasattr(self, 'process_all'):
self.process_all = [proc for proc in psutil.process_iter()] self.process_all = [proc for proc in psutil.process_iter()]
self.process_first_grab = True self.process_first_grab = True
self.process = [] self.process = []
@ -1373,9 +1373,9 @@ class glancesScreen:
cs_status: cs_status:
"None": standalone or server mode "None": standalone or server mode
"Connected": Client is connected to the server "Connected": Client is connected to the server
"Disconnected": Client is disconnected from the server "Disconnected": Client is disconnected from the server
""" """
# Get stats for processes (used in another functions for logs) # Get stats for processes (used in another functions for logs)
processcount = stats.getProcessCount() processcount = stats.getProcessCount()
processlist = stats.getProcessList(screen.getProcessSortedBy()) processlist = stats.getProcessList(screen.getProcessSortedBy())
@ -1385,12 +1385,12 @@ class glancesScreen:
self.displayLoad(stats.getLoad(), stats.getCore(), processlist, cpu_offset) self.displayLoad(stats.getLoad(), stats.getCore(), processlist, cpu_offset)
self.displayMem(stats.getMem(), stats.getMemSwap(), processlist, cpu_offset) self.displayMem(stats.getMem(), stats.getMemSwap(), processlist, cpu_offset)
network_count = self.displayNetwork(stats.getNetwork()) network_count = self.displayNetwork(stats.getNetwork())
sensors_count = self.displaySensors(stats.getSensors(), sensors_count = self.displaySensors(stats.getSensors(),
self.network_y + network_count) self.network_y + network_count)
diskio_count = self.displayDiskIO(stats.getDiskIO(), diskio_count = self.displayDiskIO(stats.getDiskIO(),
self.network_y + sensors_count + network_count) self.network_y + sensors_count + network_count)
fs_count = self.displayFs(stats.getFs(), fs_count = self.displayFs(stats.getFs(),
self.network_y + sensors_count + self.network_y + sensors_count +
network_count + diskio_count) network_count + diskio_count)
log_count = self.displayLog(self.network_y + sensors_count + network_count + log_count = self.displayLog(self.network_y + sensors_count + network_count +
diskio_count + fs_count) diskio_count + fs_count)
@ -1409,7 +1409,7 @@ class glancesScreen:
cs_status: cs_status:
"None": standalone or server mode "None": standalone or server mode
"Connected": Client is connected to the server "Connected": Client is connected to the server
"Disconnected": Client is disconnected from the server "Disconnected": Client is disconnected from the server
""" """
# Flush display # Flush display
self.erase() self.erase()
@ -1421,9 +1421,9 @@ class glancesScreen:
cs_status: cs_status:
"None": standalone or server mode "None": standalone or server mode
"Connected": Client is connected to the server "Connected": Client is connected to the server
"Disconnected": Client is disconnected from the server "Disconnected": Client is disconnected from the server
""" """
# flush display # flush display
self.flush(stats, cs_status = cs_status) self.flush(stats, cs_status = cs_status)
@ -1462,7 +1462,7 @@ class glancesScreen:
# Get screen size # Get screen size
screen_x = self.screen.getmaxyx()[1] screen_x = self.screen.getmaxyx()[1]
screen_y = self.screen.getmaxyx()[0] screen_y = self.screen.getmaxyx()[0]
# Is it possible to display extended stats ? # Is it possible to display extended stats ?
# If yes then tag_extendedcpu = True # If yes then tag_extendedcpu = True
tag_extendedcpu = screen_x > self.cpu_x + 79 + 17 tag_extendedcpu = screen_x > self.cpu_x + 79 + 17
@ -1474,14 +1474,14 @@ class glancesScreen:
tag_percpu = screen_x > self.cpu_x + 79 + (len(percpu)-1)*10 tag_percpu = screen_x > self.cpu_x + 79 + (len(percpu)-1)*10
else: else:
tag_percpu = False tag_percpu = False
# Compute x offset # Compute x offset
if (tag_percpu): if (tag_percpu):
offset_x = (len(percpu)-1)*10 offset_x = (len(percpu)-1)*10
elif (tag_extendedcpu): elif (tag_extendedcpu):
offset_x = 17 offset_x = 17
else: else:
offset_x = 0 offset_x = 0
# Display CPU stats # Display CPU stats
if (screen_y > self.cpu_y + 5 and tag_percpu): if (screen_y > self.cpu_y + 5 and tag_percpu):
@ -1517,7 +1517,7 @@ class glancesScreen:
# No alert for IDLE # No alert for IDLE
self.term_window.addnstr(self.cpu_y + 3, self.cpu_x + 10 + i*10, self.term_window.addnstr(self.cpu_y + 3, self.cpu_x + 10 + i*10,
"%.1f" % percpu[i]['idle'], 8) "%.1f" % percpu[i]['idle'], 8)
elif (screen_y > self.cpu_y + 5 and elif (screen_y > self.cpu_y + 5 and
screen_x > self.cpu_x + 18): screen_x > self.cpu_x + 18):
# Display summary information # Display summary information
@ -1532,8 +1532,8 @@ class glancesScreen:
self.term_window.addnstr(self.cpu_y, self.cpu_x + 10, self.term_window.addnstr(self.cpu_y, self.cpu_x + 10,
"%.1f%%" % (100 - cpu['idle']), 8) "%.1f%%" % (100 - cpu['idle']), 8)
self.term_window.addnstr(self.cpu_y + 1, self.cpu_x, self.term_window.addnstr(self.cpu_y + 1, self.cpu_x,
_("User:"), 8) _("User:"), 8)
alert = self.__getCpuAlert(cpu['user']) alert = self.__getCpuAlert(cpu['user'])
logs.add(alert, "CPU user", cpu['user'], proclist) logs.add(alert, "CPU user", cpu['user'], proclist)
@ -1549,13 +1549,13 @@ class glancesScreen:
"%.1f" % cpu['kernel'], 8, "%.1f" % cpu['kernel'], 8,
self.__colors_list[alert]) self.__colors_list[alert])
# No alert for IDLE # No alert for IDLE
self.term_window.addnstr(self.cpu_y + 3, self.cpu_x, self.term_window.addnstr(self.cpu_y + 3, self.cpu_x,
_("Idle:"), 8) _("Idle:"), 8)
self.term_window.addnstr(self.cpu_y + 3, self.cpu_x + 10, self.term_window.addnstr(self.cpu_y + 3, self.cpu_x + 10,
"%.1f" % cpu['idle'], 8) "%.1f" % cpu['idle'], 8)
if (screen_y > self.cpu_y + 5 and tag_extendedcpu): if (screen_y > self.cpu_y + 5 and tag_extendedcpu):
# Display extended CPU stats whenspace is available # Display extended CPU stats whenspace is available
self.term_window.addnstr(self.cpu_y + 1, self.cpu_x + 17, self.term_window.addnstr(self.cpu_y + 1, self.cpu_x + 17,
_("IO Wait:"), 8) _("IO Wait:"), 8)
try: try:
@ -1565,7 +1565,7 @@ class glancesScreen:
except: except:
self.term_window.addnstr(self.cpu_y + 1, self.cpu_x + 27, self.term_window.addnstr(self.cpu_y + 1, self.cpu_x + 27,
"N/A", 8) "N/A", 8)
self.term_window.addnstr(self.cpu_y + 2, self.cpu_x + 17, self.term_window.addnstr(self.cpu_y + 2, self.cpu_x + 17,
_("IRQ:"), 8) _("IRQ:"), 8)
try: try:
self.term_window.addnstr(self.cpu_y + 2, self.cpu_x + 27, self.term_window.addnstr(self.cpu_y + 2, self.cpu_x + 27,
@ -1573,7 +1573,7 @@ class glancesScreen:
except: except:
self.term_window.addnstr(self.cpu_y + 2, self.cpu_x + 27, self.term_window.addnstr(self.cpu_y + 2, self.cpu_x + 27,
"N/A", 8) "N/A", 8)
self.term_window.addnstr(self.cpu_y + 3, self.cpu_x + 17, self.term_window.addnstr(self.cpu_y + 3, self.cpu_x + 17,
_("Nice:"), 8) _("Nice:"), 8)
try: try:
self.term_window.addnstr(self.cpu_y + 3, self.cpu_x + 27, self.term_window.addnstr(self.cpu_y + 3, self.cpu_x + 27,
@ -1744,7 +1744,7 @@ class glancesScreen:
screen_x > self.sensors_x + 28): screen_x > self.sensors_x + 28):
# Sensors header # Sensors header
self.term_window.addnstr(self.sensors_y, self.sensors_x, self.term_window.addnstr(self.sensors_y, self.sensors_x,
_("Sensors"), 8, self.title_color _("Sensors"), 8, self.title_color
if self.hascolors else curses.A_UNDERLINE) if self.hascolors else curses.A_UNDERLINE)
self.term_window.addnstr(self.sensors_y, self.sensors_x+22, self.term_window.addnstr(self.sensors_y, self.sensors_x+22,
_("C"), 3) _("C"), 3)
@ -1963,7 +1963,7 @@ class glancesScreen:
if not psutil_get_io_counter_tag: if not psutil_get_io_counter_tag:
tag_io = False tag_io = False
# VMS # VMS
self.term_window.addnstr( self.term_window.addnstr(
self.process_y + 2, process_x, self.process_y + 2, process_x,
@ -2023,7 +2023,7 @@ class glancesScreen:
self.term_window.addnstr( self.term_window.addnstr(
self.process_y + 2, process_x + process_name_x, self.process_y + 2, process_x + process_name_x,
_("IO_W"), 6) _("IO_W"), 6)
process_name_x += 8 process_name_x += 8
# PROCESS NAME # PROCESS NAME
self.term_window.addnstr( self.term_window.addnstr(
self.process_y + 2, process_x + process_name_x, self.process_y + 2, process_x + process_name_x,
@ -2094,7 +2094,7 @@ class glancesScreen:
# TIME+ # TIME+
if tag_proc_time: if tag_proc_time:
process_time = processlist[processes]['cpu_times'] process_time = processlist[processes]['cpu_times']
try: try:
dtime = timedelta(seconds=sum(process_time)) dtime = timedelta(seconds=sum(process_time))
except: except:
# Catched on some Amazon EC2 server # Catched on some Amazon EC2 server
@ -2131,7 +2131,7 @@ class glancesScreen:
self.__autoUnit(io_write), 6) self.__autoUnit(io_write), 6)
except: except:
pass pass
# display process command line # display process command line
max_process_name = screen_x - process_x - process_name_x max_process_name = screen_x - process_x - process_name_x
process_name = processlist[processes]['name'] process_name = processlist[processes]['name']
@ -2151,7 +2151,7 @@ class glancesScreen:
cs_status: cs_status:
"None": standalone or server mode "None": standalone or server mode
"Connected": Client is connected to the server "Connected": Client is connected to the server
"Disconnected": Client is disconnected from the server "Disconnected": Client is disconnected from the server
""" """
# Caption # Caption
@ -2165,7 +2165,7 @@ class glancesScreen:
msg_client = _("Disconnected from")+" "+format(server_ip) msg_client = _("Disconnected from")+" "+format(server_ip)
msg_client_style = self.ifCRITICAL_color2 if self.hascolors else curses.A_UNDERLINE msg_client_style = self.ifCRITICAL_color2 if self.hascolors else curses.A_UNDERLINE
msg_help = _("Press 'h' for help") msg_help = _("Press 'h' for help")
if (client_tag): if (client_tag):
if (screen_y > self.caption_y and if (screen_y > self.caption_y and
screen_x > self.caption_x + len(msg_client)): screen_x > self.caption_x + len(msg_client)):
self.term_window.addnstr(max(self.caption_y, screen_y - 1), self.term_window.addnstr(max(self.caption_y, screen_y - 1),
@ -2173,16 +2173,16 @@ class glancesScreen:
msg_client_style) msg_client_style)
if (screen_x > self.caption_x + len(msg_client)+3+len(msg_help)): if (screen_x > self.caption_x + len(msg_client)+3+len(msg_help)):
self.term_window.addnstr(max(self.caption_y, screen_y - 1), self.term_window.addnstr(max(self.caption_y, screen_y - 1),
self.caption_x+len(msg_client), " | "+msg_help, 3+len(msg_help)) self.caption_x+len(msg_client), " | "+msg_help, 3+len(msg_help))
else: else:
self.term_window.addnstr(max(self.caption_y, screen_y - 1), self.term_window.addnstr(max(self.caption_y, screen_y - 1),
self.caption_x, msg_help, len(msg_help)) self.caption_x, msg_help, len(msg_help))
def displayHelp(self): def displayHelp(self):
""" """
Show the help panel Show the help panel
""" """
if not self.help_tag: if not self.help_tag:
return 0 return 0
screen_x = self.screen.getmaxyx()[1] screen_x = self.screen.getmaxyx()[1]
@ -2318,7 +2318,7 @@ class glancesHtml:
# Init refresh time # Init refresh time
self.__refresh_time = refresh_time self.__refresh_time = refresh_time
# Set the root path # Set the root path
self.root_path = htmlfolder + '/' self.root_path = htmlfolder + '/'
@ -2383,7 +2383,7 @@ class glancesHtml:
elif current > limits.getLOADWarning(core): elif current > limits.getLOADWarning(core):
return 'WARNING' return 'WARNING'
elif current > limits.getLOADCareful(core): elif current > limits.getLOADCareful(core):
return 'CAREFUL' return 'CAREFUL'
return 'OK' return 'OK'
def __getLoadColor(self, load, core=1): def __getLoadColor(self, load, core=1):
@ -2495,7 +2495,7 @@ class GlancesHandler(SimpleXMLRPCRequestHandler):
Main XMLRPC handler Main XMLRPC handler
""" """
rpc_paths = ('/RPC2',) rpc_paths = ('/RPC2',)
def log_message(self, format, *args): def log_message(self, format, *args):
# No message displayed on the server side # No message displayed on the server side
pass pass
@ -2504,27 +2504,27 @@ class GlancesHandler(SimpleXMLRPCRequestHandler):
class GlancesInstance(): class GlancesInstance():
""" """
All the methods of this class are published as XML RPC methods All the methods of this class are published as XML RPC methods
""" """
def __init__(self, refresh_time = 1): def __init__(self, refresh_time = 1):
self.timer = Timer(0) self.timer = Timer(0)
self.refresh_time = refresh_time self.refresh_time = refresh_time
def __update__(self): def __update__(self):
# Never update more than 1 time per refresh_time # Never update more than 1 time per refresh_time
if self.timer.finished(): if self.timer.finished():
stats.update() stats.update()
self.timer = Timer(self.refresh_time) self.timer = Timer(self.refresh_time)
def init(self): def init(self):
# Return the Glances version # Return the Glances version
return __version__ return __version__
def getAll(self): def getAll(self):
# Update and return all the stats # Update and return all the stats
self.__update__() self.__update__()
return json.dumps(stats.getAll()) return json.dumps(stats.getAll())
def getCpu(self): def getCpu(self):
# Update and return CPU stats # Update and return CPU stats
self.__update__() self.__update__()
@ -2554,20 +2554,20 @@ class GlancesInstance():
class GlancesServer(): class GlancesServer():
""" """
This class creates and manages the TCP client This class creates and manages the TCP client
""" """
def __init__(self, bind_address, bind_port = 61209, def __init__(self, bind_address, bind_port = 61209,
RequestHandler = GlancesHandler, RequestHandler = GlancesHandler,
refresh_time = 1): refresh_time = 1):
self.server = SimpleXMLRPCServer((bind_address, bind_port), self.server = SimpleXMLRPCServer((bind_address, bind_port),
requestHandler = RequestHandler) requestHandler = RequestHandler)
self.server.register_introspection_functions() self.server.register_introspection_functions()
self.server.register_instance(GlancesInstance(refresh_time)) self.server.register_instance(GlancesInstance(refresh_time))
return return
def serve_forever(self): def serve_forever(self):
self.server.serve_forever() self.server.serve_forever()
def server_close(self): def server_close(self):
self.server.server_close() self.server.server_close()
@ -2643,7 +2643,7 @@ def end():
# Stop the client loop # Stop the client loop
#~ client.client_quit() #~ client.client_quit()
pass pass
# Stop the classical CLI loop # Stop the classical CLI loop
screen.end() screen.end()
@ -2681,10 +2681,10 @@ def main():
server_tag = True server_tag = True
else: else:
server_tag = False server_tag = False
# Set the default refresh time # Set the default refresh time
refresh_time = 2 refresh_time = 2
# Set the default TCP port for client and server # Set the default TCP port for client and server
server_port = 61209 server_port = 61209
bind_ip = "0.0.0.0" bind_ip = "0.0.0.0"
@ -2692,8 +2692,8 @@ def main():
# Manage args # Manage args
try: try:
opts, args = getopt.getopt(sys.argv[1:], "B:bdemnho:f:t:vsc:p:", opts, args = getopt.getopt(sys.argv[1:], "B:bdemnho:f:t:vsc:p:",
["bind", "bytepersec", "diskio", "mount", ["bind", "bytepersec", "diskio", "mount",
"sensors", "netrate", "help", "output", "sensors", "netrate", "help", "output",
"file", "time", "version", "server", "file", "time", "version", "server",
"client", "port"]) "client", "port"])
except getopt.GetoptError as err: except getopt.GetoptError as err:
@ -2773,7 +2773,7 @@ def main():
if html_tag or csv_tag: if html_tag or csv_tag:
print(_("Error: Can not use both -c and -o flag")) print(_("Error: Can not use both -c and -o flag"))
sys.exit(2) sys.exit(2)
if html_tag: if html_tag:
if not html_lib_tag: if not html_lib_tag:
print(_("Error: Need Jinja2 library to export into HTML")) print(_("Error: Need Jinja2 library to export into HTML"))
@ -2812,25 +2812,25 @@ def main():
sensors_tag = True sensors_tag = True
elif server_tag: elif server_tag:
sensors_tag = True sensors_tag = True
# Init Glances depending of the mode (standalone, client, server) # Init Glances depending of the mode (standalone, client, server)
if server_tag: if server_tag:
# Init the server # Init the server
print(_("Glances server is running on")+ " %s:%s" % (bind_ip, server_port)) print(_("Glances server is running on")+ " %s:%s" % (bind_ip, server_port))
server = GlancesServer(bind_ip, server_port, GlancesHandler, refresh_time) server = GlancesServer(bind_ip, server_port, GlancesHandler, refresh_time)
# Init stats # Init stats
stats = glancesStats(server_tag = True) stats = glancesStats(server_tag = True)
elif client_tag: elif client_tag:
# Init the client (displaying server stat in the CLI) # Init the client (displaying server stat in the CLI)
client = GlancesClient(server_ip, server_port) client = GlancesClient(server_ip, server_port)
# Test if client and server are in the same major version # Test if client and server are in the same major version
if not client.client_init(): if not client.client_init():
print(_("Error: The server version is not compatible")) print(_("Error: The server version is not compatible"))
sys.exit(2) sys.exit(2)
# Init Limits # Init Limits
limits = glancesLimits() limits = glancesLimits()
@ -2841,10 +2841,10 @@ def main():
stats = glancesStats(client_tag = True) stats = glancesStats(client_tag = True)
# Init screen # Init screen
screen = glancesScreen(refresh_time=refresh_time) screen = glancesScreen(refresh_time=refresh_time)
else: else:
# Init the classical CLI # Init the classical CLI
# Init Limits # Init Limits
limits = glancesLimits() limits = glancesLimits()
@ -2869,13 +2869,13 @@ def main():
# Glances - Main loop # Glances - Main loop
##################### #####################
if server_tag: if server_tag:
# Start the server loop # Start the server loop
server.serve_forever() server.serve_forever()
elif client_tag: elif client_tag:
# Start the client (CLI) loop # Start the client (CLI) loop
while True: while True:
# Get server system informations # Get server system informations
server_stats = client.client_get() server_stats = client.client_get()
if server_stats == {}: if server_stats == {}:

View File

@ -27,29 +27,29 @@ import glances
import multiprocessing import multiprocessing
class TestGlancesStat(unittest.TestCase): class TestGlancesStat(unittest.TestCase):
def setUp(self): def setUp(self):
self.stats = glances.glancesStats() self.stats = glances.glancesStats()
self.stats.update() self.stats.update()
def test_Glances_getCore(self): def test_Glances_getCore(self):
self.assertEqual(self.stats.getCore(), multiprocessing.cpu_count()) self.assertEqual(self.stats.getCore(), multiprocessing.cpu_count())
def test_Glances_getCpu(self): def test_Glances_getCpu(self):
self.stats.update() self.stats.update()
self.assertEqual(len(self.stats.getCpu()), 4) self.assertEqual(len(self.stats.getCpu()), 4)
def test_Glances_getPerCpu(self): def test_Glances_getPerCpu(self):
self.stats.update() self.stats.update()
self.assertEqual(len(self.stats.getPerCpu()), multiprocessing.cpu_count()) self.assertEqual(len(self.stats.getPerCpu()), multiprocessing.cpu_count())
def test_Glances_getMem(self): def test_Glances_getMem(self):
self.stats.update() self.stats.update()
self.assertTrue(len(self.stats.getMem()) > 2) self.assertTrue(len(self.stats.getMem()) > 2)
def test_Glances_getMemSwap(self): def test_Glances_getMemSwap(self):
self.stats.update() self.stats.update()
self.assertTrue(len(self.stats.getMemSwap()) > 2) self.assertTrue(len(self.stats.getMemSwap()) > 2)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()