提交 f811fb84 编写于 作者: N Nicolas Hennion

Add enable/disable processes stats with z key

上级 c00f48d5
......@@ -49,7 +49,7 @@ class GlancesMain(object):
# hddtemp_flag = True
# network_tag = True
# sensors_tag = True
process_tag = True
# process_tag = True
# Display property
use_bold = True
percpu_tag = False
......@@ -206,7 +206,7 @@ class GlancesMain(object):
# self.fs_tag = args.disable_mount
# self.hddtemp_flag = args.disable_hddtemp
# self.network_tag = args.disable_network
self.process_tag = args.disable_process
# self.process_tag = args.disable_process
# self.sensors_tag = args.disable_sensors and is_Linux # and sensors_lib_tag
self.use_bold = args.no_bold
self.percpu_tag = args.percpu
......
......@@ -39,18 +39,38 @@ class glancesProcesses:
# See: https://code.google.com/p/psutil/issues/detail?id=462
self.username_cache = {}
self.cmdline_cache = {}
# The internals caches will be cleaned each 'cache_timeout' seconds
self.cache_timeout = cache_timeout
self.cache_timer = Timer(self.cache_timeout)
# Init the io dict
# key = pid
# value = [ read_bytes_old, write_bytes_old ]
self.io_old = {}
# Init
# Init stats
self.processsort = 'cpu_percent'
self.processlist = []
self.processcount = {'total': 0, 'running': 0, 'sleeping': 0, 'thread': 0}
# Tag to enable/disable the processes stats (to reduce the Glances CPU comsumption)
# Default is to enable the processes stats
self.disable_tag = False
def enable(self):
"""
Enable process stats
"""
self.disable_tag = False
self.update()
def disable(self):
"""
Enable process stats
"""
self.disable_tag = True
def __get_process_stats(self, proc):
"""
Get process statistics
......@@ -139,9 +159,18 @@ class glancesProcesses:
return procstat
def update(self):
"""
Update the processes sats
"""
# Reset the stats
self.processlist = []
self.processcount = {'total': 0, 'running': 0, 'sleeping': 0, 'thread': 0}
# Do not process if disable tag is set
if (self.disable_tag):
return
# Get the time since last update
time_since_update = getTimeSinceLastUpdate('process_disk')
......
......@@ -29,7 +29,7 @@ except ImportError:
# Import Glances lib
from glances.core.glances_timer import Timer
from glances.core.glances_globals import glances_logs
from glances.core.glances_globals import glances_logs, glances_processes
class glancesCurses:
......@@ -228,7 +228,15 @@ class glancesCurses:
elif self.pressedkey == ord('x'):
# 'x' > Delete finished warning and critical logs
glances_logs.clean(critical=True)
elif self.pressedkey == ord('z'):
# 'z' > Enable/Disable processes stats (count + list + monitor)
# Enable/Disable display
self.args.disable_process = not self.args.disable_process
# Enable/Disable update
if (self.args.disable_process):
glances_processes.disable()
else:
glances_processes.enable()
# Return the key code
return self.pressedkey
......
......@@ -113,7 +113,7 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_new_line())
msg = msg_col.format(_("s"), _("Show/hide sensors stats"))
ret.append(self.curse_add_line(msg))
msg = msg_col2.format(_("z"), _("Disable all processes stats"))
msg = msg_col2.format(_("z"), _("Enable/Disable processes stats"))
ret.append(self.curse_add_line(msg))
ret.append(self.curse_new_line())
msg = msg_col.format(_("q"), _("Quit (Esc and Ctrl-C also work)"))
......
......@@ -94,8 +94,8 @@ class Plugin(GlancesPlugin):
# Init the return message
ret = []
# Stats exist ?
if (self.stats == []):
# Only process if stats exist and display plugin enable...
if ((self.stats == []) or (args.disable_process)):
return ret
# Build the string message
......
......@@ -17,6 +17,10 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
I am your father...
For all Glances plugins
"""
# Import system libs
import json
......
......@@ -65,6 +65,18 @@ class Plugin(GlancesPlugin):
# Init the return message
ret = []
# Only process if stats exist and display plugin enable...
# if ((self.stats == {}) or (args.disable_process)):
# return ret
if (args.disable_process):
msg = "{0} ".format(_("PROCESSES DISABLED (press 'z' to display)"))
ret.append(self.curse_add_line(msg))
return ret
if (self.stats == {}):
return ret
# Build the string message
# Header
msg = "{0} ".format(_("TASKS"))
......
......@@ -67,6 +67,10 @@ class Plugin(GlancesPlugin):
# Init the return message
ret = []
# Only process if stats exist and display plugin enable...
if ((self.stats == []) or (args.disable_process)):
return ret
# Compute the sort key
if (args.process_sorted_by == 'auto'):
process_sort_key = glances_processes.getsortkey()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册