mirror of
https://github.com/nicolargo/glances.git
synced 2024-11-27 19:04:50 +03:00
Client Browser's thread management added.
Curses Browser's key bug fixed.
This commit is contained in:
parent
8aecac8f21
commit
41f4826522
3
.gitignore
vendored
3
.gitignore
vendored
@ -47,3 +47,6 @@ _build
|
|||||||
# web ui
|
# web ui
|
||||||
node_modules/
|
node_modules/
|
||||||
bower_components/
|
bower_components/
|
||||||
|
|
||||||
|
# visual stdio code
|
||||||
|
.vscode/
|
@ -219,12 +219,16 @@ class GlancesClientBrowser(object):
|
|||||||
# It's done by the GlancesAutoDiscoverListener class (autodiscover.py)
|
# It's done by the GlancesAutoDiscoverListener class (autodiscover.py)
|
||||||
# Or define staticaly in the configuration file (module static_list.py)
|
# Or define staticaly in the configuration file (module static_list.py)
|
||||||
# For each server in the list, grab elementary stats (CPU, LOAD, MEM, OS...)
|
# For each server in the list, grab elementary stats (CPU, LOAD, MEM, OS...)
|
||||||
|
thread_list = {}
|
||||||
while True:
|
while self.screen.is_end == False:
|
||||||
logger.debug("Iter through the following server list: {}".format(self.get_servers_list()))
|
logger.debug("Iter through the following server list: {}".format(self.get_servers_list()))
|
||||||
for v in self.get_servers_list():
|
for v in self.get_servers_list():
|
||||||
thread = threading.Thread(target=self.__update_stats, args=[v])
|
key = v["key"]
|
||||||
thread.start()
|
thread = thread_list.get(key, None)
|
||||||
|
if thread is None or thread.is_alive() == False:
|
||||||
|
thread = threading.Thread(target=self.__update_stats, args=[v])
|
||||||
|
thread_list[key] = thread
|
||||||
|
thread.start()
|
||||||
|
|
||||||
# Update the screen (list or Glances client)
|
# Update the screen (list or Glances client)
|
||||||
if self.screen.active_server is None:
|
if self.screen.active_server is None:
|
||||||
@ -234,6 +238,10 @@ class GlancesClientBrowser(object):
|
|||||||
# Display the active server
|
# Display the active server
|
||||||
self.__display_server(self.get_servers_list()[self.screen.active_server])
|
self.__display_server(self.get_servers_list()[self.screen.active_server])
|
||||||
|
|
||||||
|
# exit key pressed
|
||||||
|
for thread in thread_list.values():
|
||||||
|
thread.join()
|
||||||
|
|
||||||
def serve_forever(self):
|
def serve_forever(self):
|
||||||
"""Wrapper to the serve_forever function.
|
"""Wrapper to the serve_forever function.
|
||||||
|
|
||||||
|
@ -61,6 +61,8 @@ class GlancesCursesBrowser(_GlancesCurses):
|
|||||||
self._page_max = 0
|
self._page_max = 0
|
||||||
self._page_max_lines = 0
|
self._page_max_lines = 0
|
||||||
|
|
||||||
|
self.is_end = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def active_server(self):
|
def active_server(self):
|
||||||
"""Return the active server or None if it's the browser list."""
|
"""Return the active server or None if it's the browser list."""
|
||||||
@ -124,6 +126,8 @@ class GlancesCursesBrowser(_GlancesCurses):
|
|||||||
"""Set next page."""
|
"""Set next page."""
|
||||||
if self._current_page + 1 < self._page_max:
|
if self._current_page + 1 < self._page_max:
|
||||||
self._current_page += 1
|
self._current_page += 1
|
||||||
|
else:
|
||||||
|
self._current_page = 0
|
||||||
self.cursor_position = 0
|
self.cursor_position = 0
|
||||||
|
|
||||||
def __catch_key(self, stats):
|
def __catch_key(self, stats):
|
||||||
@ -138,7 +142,8 @@ class GlancesCursesBrowser(_GlancesCurses):
|
|||||||
# 'ESC'|'q' > Quit
|
# 'ESC'|'q' > Quit
|
||||||
self.end()
|
self.end()
|
||||||
logger.info("Stop Glances client browser")
|
logger.info("Stop Glances client browser")
|
||||||
sys.exit(0)
|
# sys.exit(0)
|
||||||
|
self.is_end = True
|
||||||
elif self.pressedkey == 10:
|
elif self.pressedkey == 10:
|
||||||
# 'ENTER' > Run Glances on the selected server
|
# 'ENTER' > Run Glances on the selected server
|
||||||
self.active_server = self._current_page * self._page_max_lines + self.cursor_position
|
self.active_server = self._current_page * self._page_max_lines + self.cursor_position
|
||||||
@ -288,10 +293,7 @@ class GlancesCursesBrowser(_GlancesCurses):
|
|||||||
self.cursor = len(stats) - 1
|
self.cursor = len(stats) - 1
|
||||||
|
|
||||||
start_line = self._page_max_lines * self._current_page
|
start_line = self._page_max_lines * self._current_page
|
||||||
end_line = start_line + self._page_max_lines
|
end_line = start_line + self.get_pagelines(stats)
|
||||||
if end_line > stats_len:
|
|
||||||
end_line = stats_len
|
|
||||||
|
|
||||||
current_page = stats[start_line:end_line]
|
current_page = stats[start_line:end_line]
|
||||||
|
|
||||||
# Display table
|
# Display table
|
||||||
|
Loading…
Reference in New Issue
Block a user