mirror of https://github.com/nicolargo/glances
Correct a bug on the client/server mode for processes list
parent
803b415497
commit
3cbde4d2d5
|
@ -58,9 +58,9 @@ class GlancesClient():
|
|||
# Try to connect to the URI
|
||||
try:
|
||||
self.client = ServerProxy(uri)
|
||||
except Exception:
|
||||
print(_("Error: creating client socket") + " %s" % uri)
|
||||
pass
|
||||
except Exception as e:
|
||||
print("{} {} ({})".format(_("Error: creating client socket"), uri, e))
|
||||
sys.exit(2)
|
||||
|
||||
# Store the arg/config
|
||||
self.args = args
|
||||
|
@ -82,6 +82,7 @@ class GlancesClient():
|
|||
print("{} ({})".format(_("Error: Connection to server failed"), err))
|
||||
sys.exit(2)
|
||||
|
||||
# Test if client and server are "compatible"
|
||||
if (__version__[:3] == client_version[:3]):
|
||||
# Init stats and limits
|
||||
self.stats = GlancesStatsClient()
|
||||
|
@ -116,7 +117,7 @@ class GlancesClient():
|
|||
|
||||
def serve_forever(self):
|
||||
"""
|
||||
Main loop
|
||||
Main client loop
|
||||
"""
|
||||
while True:
|
||||
# Update the stats
|
||||
|
|
|
@ -160,10 +160,10 @@ class glancesProcesses:
|
|||
continue
|
||||
# Update processcount (global statistics)
|
||||
try:
|
||||
self.processcount[str(proc.status)] += 1
|
||||
self.processcount[str(proc.status())] += 1
|
||||
except KeyError:
|
||||
# Key did not exist, create it
|
||||
self.processcount[str(proc.status)] = 1
|
||||
self.processcount[str(proc.status())] = 1
|
||||
else:
|
||||
self.processcount['total'] += 1
|
||||
# Update thread number (global statistics)
|
||||
|
|
|
@ -185,8 +185,7 @@ class GlancesInstance():
|
|||
The goal is to dynamicaly generate the API get'Stats'() methods
|
||||
"""
|
||||
|
||||
# print "!!! __getattr__ in the GlancesInstance classe"
|
||||
# print "!!! Method: %s" % item
|
||||
# print "DEBUG: Call method: %s" % item
|
||||
header = 'get'
|
||||
# Check if the attribute starts with 'get'
|
||||
if (item.startswith(header)):
|
||||
|
@ -203,22 +202,6 @@ class GlancesInstance():
|
|||
# Default behavior
|
||||
raise AttributeError(item)
|
||||
|
||||
# !!! How to implement theses method in v2 ?
|
||||
|
||||
# def __getTimeSinceLastUpdate(self, IOType):
|
||||
# assert(IOType in ['net', 'disk', 'process_disk'])
|
||||
# return getTimeSinceLastUpdate(IOType)
|
||||
|
||||
# def getNetTimeSinceLastUpdate(self):
|
||||
# return getTimeSinceLastUpdate('net')
|
||||
|
||||
# def getDiskTimeSinceLastUpdate(self):
|
||||
# return getTimeSinceLastUpdate('net')
|
||||
|
||||
# def getProcessDiskTimeSinceLastUpdate(self):
|
||||
# return getTimeSinceLastUpdate('process_disk')
|
||||
|
||||
|
||||
class GlancesServer():
|
||||
"""
|
||||
This class creates and manages the TCP server
|
||||
|
|
|
@ -113,14 +113,12 @@ class GlancesStats(object):
|
|||
else:
|
||||
# For client mode
|
||||
# Update plugin stats with items sent by the server
|
||||
# print input_stats['processcount']
|
||||
# sys.exit(2)
|
||||
for p in input_stats:
|
||||
# print "Set: %s" % p
|
||||
# print "Input: %s" % input_stats[p]
|
||||
# print "Plugins: %s" % self._plugins
|
||||
self._plugins[p].set_stats(input_stats[p])
|
||||
|
||||
def update(self, input_stats={}):
|
||||
# !!! Why __update__ and update method ?
|
||||
# Update the stats
|
||||
self.__update__(input_stats)
|
||||
|
||||
|
@ -137,6 +135,9 @@ class GlancesStats(object):
|
|||
|
||||
|
||||
class GlancesStatsServer(GlancesStats):
|
||||
"""
|
||||
This class store, update and give stats for the server
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
# Init the stats
|
||||
|
@ -172,15 +173,14 @@ class GlancesStatsServer(GlancesStats):
|
|||
|
||||
|
||||
class GlancesStatsClient(GlancesStats):
|
||||
"""
|
||||
This class store, update and give stats for the client
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
# Init the plugin list dict
|
||||
self._plugins = collections.defaultdict(dict)
|
||||
|
||||
# Init the all_stats dict used by the server
|
||||
# all_stats is a dict of dicts filled by the server
|
||||
self.all_stats = collections.defaultdict(dict)
|
||||
|
||||
def set_plugins(self, input_plugins):
|
||||
"""
|
||||
Set the plugin list accoring to the Glances' server
|
||||
|
@ -198,19 +198,5 @@ class GlancesStatsClient(GlancesStats):
|
|||
# The key is the plugin name
|
||||
# for example, the file glances_xxx.py
|
||||
# generate self._plugins_list["xxx"] = ...
|
||||
# print "DEBUG: Init %s plugin" % plug
|
||||
self._plugins[plug] = m.Plugin()
|
||||
|
||||
def update(self, input_stats={}):
|
||||
"""
|
||||
Update the stats
|
||||
"""
|
||||
|
||||
# Update the stats
|
||||
GlancesStats.__update__(self, input_stats)
|
||||
|
||||
# Build the all_stats with the get_raw() method of the plugins
|
||||
for p in self._plugins:
|
||||
self.all_stats[p] = self._plugins[p].get_raw()
|
||||
|
||||
def getAll(self):
|
||||
return self.all_stats
|
||||
|
|
|
@ -121,11 +121,11 @@ class Plugin(GlancesPlugin):
|
|||
|
||||
# Build the string message
|
||||
# Header
|
||||
msg = "{0:8}".format(_("DISK I/O"))
|
||||
msg = "{0:9}".format(_("DISK I/O"))
|
||||
ret.append(self.curse_add_line(msg, "TITLE"))
|
||||
msg = " {0:>6}".format(_("R/s"))
|
||||
msg = "{0:>7}".format(_("R/s"))
|
||||
ret.append(self.curse_add_line(msg))
|
||||
msg = " {0:>6}".format(_("W/s"))
|
||||
msg = "{0:>7}".format(_("W/s"))
|
||||
ret.append(self.curse_add_line(msg))
|
||||
# Disk list (sorted by name)
|
||||
for i in sorted(self.stats, key=lambda diskio: diskio['disk_name']):
|
||||
|
|
|
@ -33,7 +33,7 @@ class Plugin(GlancesPlugin):
|
|||
GlancesPlugin.__init__(self)
|
||||
|
||||
# Nothing else to do...
|
||||
# 'processes' is already init in the _processes.py script
|
||||
# 'processes' is already init in the glances_processes.py script
|
||||
|
||||
# We want to display the stat in the curse interface
|
||||
self.display_curse = True
|
||||
|
|
|
@ -34,17 +34,6 @@ class Plugin(GlancesPlugin):
|
|||
def __init__(self):
|
||||
GlancesPlugin.__init__(self)
|
||||
|
||||
# Nothing else to do...
|
||||
# 'processes' is already init in the _processes.py script
|
||||
|
||||
def update(self):
|
||||
"""
|
||||
Update processes stats
|
||||
"""
|
||||
|
||||
# Note: Update is done in the processcount plugin
|
||||
|
||||
self.stats = glances_processes.getlist()
|
||||
# We want to display the stat in the curse interface
|
||||
self.display_curse = True
|
||||
# Set the message position
|
||||
|
@ -54,6 +43,17 @@ class Plugin(GlancesPlugin):
|
|||
# Enter -1 to diplay bottom
|
||||
self.line_curse = 4
|
||||
|
||||
# Note 'processes' is already init in the _processes.py script
|
||||
|
||||
def update(self):
|
||||
"""
|
||||
Update processes stats
|
||||
"""
|
||||
|
||||
# Note: Update is done in the processcount plugin
|
||||
self.stats = glances_processes.getlist()
|
||||
|
||||
|
||||
def msg_curse(self, args=None):
|
||||
"""
|
||||
Return the dict to display in the curse interface
|
||||
|
|
Loading…
Reference in New Issue