mirror of
https://github.com/nicolargo/glances.git
synced 2024-11-14 10:20:03 +03:00
Client/Server works but no process are displayed. Also rename In/Out by Read/Write for DiskIO according to #339
This commit is contained in:
parent
822f0d8386
commit
803b415497
@ -53,15 +53,13 @@ def main(argv=None):
|
||||
# Init the client
|
||||
client = GlancesClient(args=core.get_args(),
|
||||
server_address=core.server_ip, server_port=int(core.server_port),
|
||||
username=core.username, password=core.password)
|
||||
username=core.username, password=core.password, config=core.get_config())
|
||||
|
||||
# Test if client and server are in the same major version
|
||||
if (not client.login()):
|
||||
print(_("Error: The server version is not compatible"))
|
||||
print(_("Error: The server version is not compatible with the client"))
|
||||
sys.exit(2)
|
||||
|
||||
print("{} {}:{}".format(_("Glances client connected"), core.server_ip, core.server_port))
|
||||
|
||||
# Start the client loop
|
||||
client.serve_forever()
|
||||
|
||||
|
@ -47,7 +47,8 @@ class GlancesClient():
|
||||
def __init__(self,
|
||||
args=None,
|
||||
server_address="localhost", server_port=61209,
|
||||
username="glances", password=""):
|
||||
username="glances", password="",
|
||||
config=None):
|
||||
# Build the URI
|
||||
if (password != ""):
|
||||
uri = 'http://%s:%s@%s:%d' % (username, password, server_address, server_port)
|
||||
@ -61,11 +62,9 @@ class GlancesClient():
|
||||
print(_("Error: creating client socket") + " %s" % uri)
|
||||
pass
|
||||
|
||||
# Init stats
|
||||
self.stats = GlancesStatsClient()
|
||||
|
||||
# Init screen
|
||||
self.screen = glancesCurses(args=args)
|
||||
# Store the arg/config
|
||||
self.args = args
|
||||
self.config = config
|
||||
|
||||
def login(self):
|
||||
"""
|
||||
@ -82,21 +81,38 @@ class GlancesClient():
|
||||
else:
|
||||
print("{} ({})".format(_("Error: Connection to server failed"), err))
|
||||
sys.exit(2)
|
||||
|
||||
if (__version__[:3] == client_version[:3]):
|
||||
# Init stats and limits
|
||||
self.stats = GlancesStatsClient()
|
||||
self.stats.set_plugins(json.loads(self.client.getAllPlugins()))
|
||||
self.stats.load_limits(self.config)
|
||||
|
||||
# Init screen
|
||||
self.screen = glancesCurses(args=self.args)
|
||||
|
||||
# Debug
|
||||
# print "Server version: {}\nClient version: {}\n".format(__version__, client_version)
|
||||
return __version__[:3] == client_version[:3]
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def update(self):
|
||||
"""
|
||||
Get stats from server
|
||||
Return the client/server connection status:
|
||||
- Connected: Connection OK
|
||||
- Disconnected: Connection NOK
|
||||
"""
|
||||
try:
|
||||
server_stats = json.loads(self.client.getAll())
|
||||
except Exception:
|
||||
server_stats = {}
|
||||
|
||||
except socket.error as e:
|
||||
# Client can not get server stats
|
||||
return "Disconnected"
|
||||
else:
|
||||
# Put it in the internal dict
|
||||
self.stats.update(server_stats)
|
||||
return "Connected"
|
||||
|
||||
def serve_forever(self):
|
||||
"""
|
||||
@ -104,10 +120,10 @@ class GlancesClient():
|
||||
"""
|
||||
while True:
|
||||
# Update the stats
|
||||
self.update()
|
||||
cs_status = self.update()
|
||||
|
||||
# Update the screen
|
||||
self.screen.update(self.stats, cs_status="Connected")
|
||||
self.screen.update(self.stats, cs_status=cs_status)
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
|
@ -74,6 +74,7 @@ class GlancesStats(object):
|
||||
Load all plugins in the "plugins" folder
|
||||
"""
|
||||
|
||||
# Set the plugins' path
|
||||
plug_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../plugins")
|
||||
sys.path.insert(0, plug_dir)
|
||||
|
||||
@ -173,50 +174,31 @@ class GlancesStatsServer(GlancesStats):
|
||||
class GlancesStatsClient(GlancesStats):
|
||||
|
||||
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)
|
||||
|
||||
# Load the plugins
|
||||
self.load_plugins()
|
||||
|
||||
# Load the limits
|
||||
self.load_limits()
|
||||
|
||||
|
||||
def load_plugins(self):
|
||||
def set_plugins(self, input_plugins):
|
||||
"""
|
||||
Load all plugins serve by the Glances' server
|
||||
Set the plugin list accoring to the Glances' server
|
||||
"""
|
||||
#!!! TODO: call the getAllPlugins() server method
|
||||
#!!! Build the plugins list
|
||||
|
||||
# plug_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../plugins")
|
||||
# sys.path.insert(0, plug_dir)
|
||||
# Set the plugins' path
|
||||
plug_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../plugins")
|
||||
sys.path.insert(0, plug_dir)
|
||||
|
||||
# header = "glances_"
|
||||
# for plug in os.listdir(plug_dir):
|
||||
# if (plug.startswith(header) and plug.endswith(".py") and
|
||||
# plug != (header + "plugin.py")):
|
||||
# # Import the plugin
|
||||
# m = __import__(os.path.basename(plug)[:-3])
|
||||
# # Add the plugin to the dictionnary
|
||||
# # The key is the plugin name
|
||||
# # for example, the file glances_xxx.py
|
||||
# # generate self._plugins_list["xxx"] = ...
|
||||
# plugname = os.path.basename(plug)[len(header):-3].lower()
|
||||
# self._plugins[plugname] = m.Plugin()
|
||||
pass
|
||||
|
||||
def load_limits(self, config=None):
|
||||
"""
|
||||
Load the limits serve by the Glances' server
|
||||
"""
|
||||
# For each plugins, call the init_limits method
|
||||
# for p in self._plugins:
|
||||
# self._plugins[p].load_limits(config)
|
||||
pass
|
||||
header = "glances_"
|
||||
for plug in input_plugins:
|
||||
# Import the plugin
|
||||
m = __import__(header + plug)
|
||||
# Add the plugin to the dictionnary
|
||||
# The key is the plugin name
|
||||
# for example, the file glances_xxx.py
|
||||
# generate self._plugins_list["xxx"] = ...
|
||||
self._plugins[plug] = m.Plugin()
|
||||
|
||||
def update(self, input_stats={}):
|
||||
"""
|
||||
|
@ -123,9 +123,9 @@ class Plugin(GlancesPlugin):
|
||||
# Header
|
||||
msg = "{0:8}".format(_("DISK I/O"))
|
||||
ret.append(self.curse_add_line(msg, "TITLE"))
|
||||
msg = " {0:>6}".format(_("In/s"))
|
||||
msg = " {0:>6}".format(_("R/s"))
|
||||
ret.append(self.curse_add_line(msg))
|
||||
msg = " {0:>6}".format(_("Out/s"))
|
||||
msg = " {0:>6}".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']):
|
||||
@ -133,11 +133,11 @@ class Plugin(GlancesPlugin):
|
||||
ret.append(self.curse_new_line())
|
||||
msg = "{0:8}".format(i['disk_name'])
|
||||
ret.append(self.curse_add_line(msg))
|
||||
rxps = self.auto_unit(int(i['write_bytes'] // i['time_since_update']))
|
||||
txps = self.auto_unit(int(i['read_bytes'] // i['time_since_update']))
|
||||
msg = " {0:>6}".format(rxps)
|
||||
ret.append(self.curse_add_line(msg))
|
||||
rxps = self.auto_unit(int(i['write_bytes'] // i['time_since_update']))
|
||||
msg = " {0:>6}".format(txps)
|
||||
ret.append(self.curse_add_line(msg))
|
||||
msg = " {0:>6}".format(rxps)
|
||||
ret.append(self.curse_add_line(msg))
|
||||
|
||||
return ret
|
||||
|
@ -51,6 +51,9 @@ class Plugin(GlancesPlugin):
|
||||
# Enter -1 to diplay bottom
|
||||
self.line_curse = 1
|
||||
|
||||
# Init stats
|
||||
self.stats = {}
|
||||
|
||||
def update(self):
|
||||
"""
|
||||
Update load stats
|
||||
|
Loading…
Reference in New Issue
Block a user