Give atry to Swap Mem used stat but rejected because too high CPU consumption (issue #372)

This commit is contained in:
Nicolargo 2014-07-06 15:14:49 +02:00
parent c104772ca4
commit e0d9fe530d
4 changed files with 31 additions and 12 deletions

View File

@ -17,7 +17,7 @@
# 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/>.
from glances.core.glances_globals import is_bsd, is_mac, is_windows
from glances.core.glances_globals import is_linux, is_bsd, is_mac, is_windows, logger
from glances.core.glances_timer import Timer, getTimeSinceLastUpdate
import psutil
@ -112,7 +112,7 @@ class GlancesProcesses(object):
procstat['cpu_percent'] = proc.cpu_percent(interval=0)
# Process network connections (TCP and UDP) (Experimental)
# !!! High CPU consumption
# REJECTED: Too high CPU consumption
# try:
# procstat['tcp'] = len(proc.connections(kind="tcp"))
# procstat['udp'] = len(proc.connections(kind="udp"))
@ -150,6 +150,14 @@ class GlancesProcesses(object):
# Append the IO tag (for display)
procstat['io_counters'] += [io_tag]
# SWAP memory
# Only on Linux based OS
# http://www.cyberciti.biz/faq/linux-which-process-is-using-swap/
# REJECTED: Too high CPU consumption
# if is_linux:
# logger.debug(proc.memory_maps())
# procstat['memory_swap'] = sum([ v.swap for v in proc.memory_maps() ])
return procstat
def update(self):

View File

@ -422,10 +422,14 @@ class GlancesCurses(object):
return True
def display_plugin(self, plugin_stats, display_optional=True, max_y=65535):
def display_plugin(self, plugin_stats,
display_optional=True,
display_additional=True,
max_y=65535):
"""Display the plugin_stats on the screen.
If display_optional=True display the optional stats.
If display_optional=True display the optional stats
If display_additional=True display additionnal stats
max_y do not display line > max_y
"""
# Exit if:
@ -472,6 +476,9 @@ class GlancesCurses(object):
# If display_optional = False do not display optional stats
if not display_optional and m['optional']:
continue
# If display_additional = False do not display additional stats
if not display_additional and m['additional']:
continue
# Is it possible to display the stat with the current screen size
# !!! Crach if not try/except... Why ???
try:

View File

@ -284,17 +284,19 @@ class GlancesPlugin(object):
if max_width is not None:
ret = {'display': display_curse,
'msgdict': self.msg_curse(args, max_width=max_width),
'align': align_curse}
'msgdict': self.msg_curse(args, max_width=max_width),
'align': align_curse}
else:
ret = {'display': display_curse,
'msgdict': self.msg_curse(args),
'align': align_curse}
'msgdict': self.msg_curse(args),
'align': align_curse}
return ret
def curse_add_line(self, msg, decoration="DEFAULT", optional=False, splittable=False):
"""Return a dict with: { 'msg': msg, 'decoration': decoration, 'optional': False }.
def curse_add_line(self, msg, decoration="DEFAULT",
optional=False, additional=False,
splittable=False):
"""Return a dict with
Where:
msg: string
@ -315,9 +317,10 @@ class GlancesPlugin(object):
CRITICAL: Value is CRITICAL and non logged
CRITICAL_LOG: Value is CRITICAL and logged
optional: True if the stat is optional (display only if space is available)
additional: True if the stat is additional (display only if space is available after optional)
spittable: Line can be splitted to fit on the screen (default is not)
"""
return {'msg': msg, 'decoration': decoration, 'optional': optional, 'splittable': splittable}
return {'msg': msg, 'decoration': decoration, 'optional': optional, 'additional': additional, 'splittable': splittable}
def curse_new_line(self):
"""Go to a new line."""

View File

@ -24,7 +24,7 @@ import os
from datetime import timedelta
# Import Glances libs
from glances.core.glances_globals import glances_processes, is_windows
from glances.core.glances_globals import glances_processes, is_windows, is_linux
from glances.plugins.glances_plugin import GlancesPlugin
@ -216,6 +216,7 @@ class Plugin(GlancesPlugin):
msg = '{0:>6}'.format("?")
ret.append(self.curse_add_line(msg, optional=True))
ret.append(self.curse_add_line(msg, optional=True))
# Command line
# If no command line for the process is available, fallback to
# the bare process name instead