Refactor Mem + MemSwap Curse

pull/1927/head
nicolargo 2021-08-29 19:26:43 +02:00
parent 73f091f2d2
commit c2da541c0a
5 changed files with 103 additions and 104 deletions

View File

@ -282,12 +282,12 @@ class Plugin(GlancesPlugin):
if not self.stats or self.args.percpu or self.is_disable(): if not self.stats or self.args.percpu or self.is_disable():
return ret return ret
# Build the string message
# If user stat is not here, display only idle / total CPU usage (for # If user stat is not here, display only idle / total CPU usage (for
# exemple on Windows OS) # exemple on Windows OS)
idle_tag = 'user' not in self.stats idle_tag = 'user' not in self.stats
# Header # First line
# Total + (idle) + ctx_sw
msg = '{}'.format('CPU') msg = '{}'.format('CPU')
ret.append(self.curse_add_line(msg, "TITLE")) ret.append(self.curse_add_line(msg, "TITLE"))
trend_user = self.get_trend('user') trend_user = self.get_trend('user')
@ -303,50 +303,46 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line( ret.append(self.curse_add_line(
msg, self.get_views(key='total', option='decoration'))) msg, self.get_views(key='total', option='decoration')))
# Idle CPU # Idle CPU
if 'idle' in self.stats and not idle_tag: if not idle_tag:
ret.extend(self.curse_add_stat('idle', width=15, header=' ')) ret.extend(self.curse_add_stat('idle', width=15, header=' '))
# ctx_switches # ctx_switches
if 'ctx_switches' in self.stats: ret.extend(self.curse_add_stat('ctx_switches', width=15, header=' '))
ret.extend(self.curse_add_stat('ctx_switches', width=15, header=' '))
# New line # Second line
# user|idle + irq + interrupts
ret.append(self.curse_new_line()) ret.append(self.curse_new_line())
# User CPU # User CPU
if 'user' in self.stats: if not idle_tag:
ret.extend(self.curse_add_stat('user', width=15)) ret.extend(self.curse_add_stat('user', width=15))
elif 'idle' in self.stats: elif 'idle' in self.stats:
ret.extend(self.curse_add_stat('idle', width=15)) ret.extend(self.curse_add_stat('idle', width=15))
# IRQ CPU # IRQ CPU
if 'irq' in self.stats: ret.extend(self.curse_add_stat('irq', width=15, header=' '))
ret.extend(self.curse_add_stat('irq', width=15, header=' ')) # interrupts
# interrupts ret.extend(self.curse_add_stat('interrupts', width=15, header=' '))
if 'interrupts' in self.stats:
ret.extend(self.curse_add_stat('interrupts', width=15, header=' '))
# New line # Third line
# system|core + nice + sw_int
ret.append(self.curse_new_line()) ret.append(self.curse_new_line())
# System CPU # System CPU
if 'system' in self.stats and not idle_tag: if not idle_tag:
ret.extend(self.curse_add_stat('system', width=15)) ret.extend(self.curse_add_stat('system', width=15))
else: else:
ret.extend(self.curse_add_stat('core', width=15)) ret.extend(self.curse_add_stat('core', width=15))
# Nice CPU # Nice CPU
if 'nice' in self.stats: ret.extend(self.curse_add_stat('nice', width=15, header=' '))
ret.extend(self.curse_add_stat('nice', width=15, header=' ')) # soft_interrupts
# soft_interrupts ret.extend(self.curse_add_stat('soft_interrupts', width=15, header=' '))
if 'soft_interrupts' in self.stats:
ret.extend(self.curse_add_stat('soft_interrupts', width=15, header=' '))
# New line # Fourth line
# iowat + steal + syscalls
ret.append(self.curse_new_line()) ret.append(self.curse_new_line())
# IOWait CPU # IOWait CPU
if 'iowait' in self.stats: ret.extend(self.curse_add_stat('iowait', width=15))
ret.extend(self.curse_add_stat('iowait', width=15)) # Steal CPU usage
# Steal CPU usage ret.extend(self.curse_add_stat('steal', width=15, header=' '))
if 'steal' in self.stats:
ret.extend(self.curse_add_stat('steal', width=15, header=' '))
# syscalls: number of system calls since boot. Always set to 0 on Linux. (do not display) # syscalls: number of system calls since boot. Always set to 0 on Linux. (do not display)
if 'syscalls' in self.stats and not LINUX: if not LINUX:
ret.extend(self.curse_add_stat('syscalls', width=15, header=' ')) ret.extend(self.curse_add_stat('syscalls', width=15, header=' '))
# Return the message with decoration # Return the message with decoration

View File

@ -32,15 +32,15 @@ fields_description = {
'min1': {'description': 'Average sum of the number of processes \ 'min1': {'description': 'Average sum of the number of processes \
waiting in the run-queue plus the number currently executing \ waiting in the run-queue plus the number currently executing \
over 1 minute.', over 1 minute.',
'unit': 'number'}, 'unit': 'float'},
'min5': {'description': 'Average sum of the number of processes \ 'min5': {'description': 'Average sum of the number of processes \
waiting in the run-queue plus the number currently executing \ waiting in the run-queue plus the number currently executing \
over 5 minutes.', over 5 minutes.',
'unit': 'number'}, 'unit': 'float'},
'min15': {'description': 'Average sum of the number of processes \ 'min15': {'description': 'Average sum of the number of processes \
waiting in the run-queue plus the number currently executing \ waiting in the run-queue plus the number currently executing \
over 15 minutes.', over 15 minutes.',
'unit': 'number'}, 'unit': 'float'},
'cpucore': {'description': 'Total number of CPU core.', 'cpucore': {'description': 'Total number of CPU core.',
'unit': 'number'}, 'unit': 'number'},
} }

View File

@ -2,7 +2,7 @@
# #
# This file is part of Glances. # This file is part of Glances.
# #
# Copyright (C) 2019 Nicolargo <nicolas@nicolargo.com> # Copyright (C) 2021 Nicolargo <nicolas@nicolargo.com>
# #
# Glances is free software; you can redistribute it and/or modify # Glances is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by # it under the terms of the GNU Lesser General Public License as published by
@ -28,32 +28,42 @@ import psutil
# Fields description # Fields description
fields_description = { fields_description = {
'total': {'description': 'Total physical memory available.', 'total': {'description': 'Total physical memory available.',
'unit': 'bytes'}, 'unit': 'bytes',
'min_symbol': 'K'},
'available': {'description': 'The actual amount of available memory that can be given instantly \ 'available': {'description': 'The actual amount of available memory that can be given instantly \
to processes that request more memory in bytes; this is calculated by summing \ to processes that request more memory in bytes; this is calculated by summing \
different memory values depending on the platform (e.g. free + buffers + cached on Linux) \ different memory values depending on the platform (e.g. free + buffers + cached on Linux) \
and it is supposed to be used to monitor actual memory usage in a cross platform fashion.', and it is supposed to be used to monitor actual memory usage in a cross platform fashion.',
'unit': 'bytes'}, 'unit': 'bytes',
'min_symbol': 'K'},
'percent': {'description': 'The percentage usage calculated as (total - available) / total * 100.', 'percent': {'description': 'The percentage usage calculated as (total - available) / total * 100.',
'unit': 'percent'}, 'unit': 'percent'},
'used': {'description': 'Memory used, calculated differently depending on the platform and \ 'used': {'description': 'Memory used, calculated differently depending on the platform and \
designed for informational purposes only.', designed for informational purposes only.',
'unit': 'bytes'}, 'unit': 'bytes',
'min_symbol': 'K'},
'free': {'description': 'Memory not being used at all (zeroed) that is readily available; \ 'free': {'description': 'Memory not being used at all (zeroed) that is readily available; \
note that this doesn\'t reflect the actual memory available (use \'available\' instead).', note that this doesn\'t reflect the actual memory available (use \'available\' instead).',
'unit': 'bytes'}, 'unit': 'bytes',
'min_symbol': 'K'},
'active': {'description': '*(UNIX)*: memory currently in use or very recently used, and so it is in RAM.', 'active': {'description': '*(UNIX)*: memory currently in use or very recently used, and so it is in RAM.',
'unit': 'bytes'}, 'unit': 'bytes',
'min_symbol': 'K'},
'inactive': {'description': '*(UNIX)*: memory that is marked as not used.', 'inactive': {'description': '*(UNIX)*: memory that is marked as not used.',
'unit': 'bytes'}, 'unit': 'bytes',
'min_symbol': 'K'},
'buffers': {'description': '*(Linux, BSD)*: cache for things like file system metadata.', 'buffers': {'description': '*(Linux, BSD)*: cache for things like file system metadata.',
'unit': 'bytes'}, 'unit': 'bytes',
'min_symbol': 'K'},
'cached': {'description': '*(Linux, BSD)*: cache for various things.', 'cached': {'description': '*(Linux, BSD)*: cache for various things.',
'unit': 'bytes'}, 'unit': 'bytes',
'min_symbol': 'K'},
'wired': {'description': '*(BSD, macOS)*: memory that is marked to always stay in RAM. It is never moved to disk.', 'wired': {'description': '*(BSD, macOS)*: memory that is marked to always stay in RAM. It is never moved to disk.',
'unit': 'bytes'}, 'unit': 'bytes',
'min_symbol': 'K'},
'shared': {'description': '*(BSD)*: memory that may be simultaneously accessed by multiple processes.', 'shared': {'description': '*(BSD)*: memory that may be simultaneously accessed by multiple processes.',
'unit': 'bytes'}, 'unit': 'bytes',
'min_symbol': 'K'},
} }
# SNMP OID # SNMP OID
@ -214,8 +224,8 @@ class Plugin(GlancesPlugin):
if not self.stats or self.is_disable(): if not self.stats or self.is_disable():
return ret return ret
# Build the string message # First line
# Header # total% + active
msg = '{}'.format('MEM') msg = '{}'.format('MEM')
ret.append(self.curse_add_line(msg, "TITLE")) ret.append(self.curse_add_line(msg, "TITLE"))
msg = ' {:2}'.format(self.trend_msg(self.get_trend('percent'))) msg = ' {:2}'.format(self.trend_msg(self.get_trend('percent')))
@ -225,50 +235,30 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line( ret.append(self.curse_add_line(
msg, self.get_views(key='percent', option='decoration'))) msg, self.get_views(key='percent', option='decoration')))
# Active memory usage # Active memory usage
if 'active' in self.stats: ret.extend(self.curse_add_stat('active', width=18, header=' '))
msg = ' {:9}'.format('active:')
ret.append(self.curse_add_line(msg, optional=self.get_views(key='active', option='optional'))) # Second line
msg = '{:>7}'.format(self.auto_unit(self.stats['active'])) # total + inactive
ret.append(self.curse_add_line(msg, optional=self.get_views(key='active', option='optional')))
# New line
ret.append(self.curse_new_line()) ret.append(self.curse_new_line())
# Total memory usage # Total memory usage
msg = '{:6}'.format('total:') ret.extend(self.curse_add_stat('total', width=15))
ret.append(self.curse_add_line(msg))
msg = '{:>7}'.format(self.auto_unit(self.stats['total']))
ret.append(self.curse_add_line(msg))
# Inactive memory usage # Inactive memory usage
if 'inactive' in self.stats: ret.extend(self.curse_add_stat('inactive', width=18, header=' '))
msg = ' {:9}'.format('inactive:')
ret.append(self.curse_add_line(msg, optional=self.get_views(key='inactive', option='optional'))) # Third line
msg = '{:>7}'.format(self.auto_unit(self.stats['inactive'])) # used + buffers
ret.append(self.curse_add_line(msg, optional=self.get_views(key='inactive', option='optional')))
# New line
ret.append(self.curse_new_line()) ret.append(self.curse_new_line())
# Used memory usage # Used memory usage
msg = '{:6}'.format('used:') ret.extend(self.curse_add_stat('used', width=15))
ret.append(self.curse_add_line(msg))
msg = '{:>7}'.format(self.auto_unit(self.stats['used']))
ret.append(self.curse_add_line(
msg, self.get_views(key='used', option='decoration')))
# Buffers memory usage # Buffers memory usage
if 'buffers' in self.stats: ret.extend(self.curse_add_stat('buffers', width=18, header=' '))
msg = ' {:9}'.format('buffers:')
ret.append(self.curse_add_line(msg, optional=self.get_views(key='buffers', option='optional'))) # Fourth line
msg = '{:>7}'.format(self.auto_unit(self.stats['buffers'])) # free + cached
ret.append(self.curse_add_line(msg, optional=self.get_views(key='buffers', option='optional')))
# New line
ret.append(self.curse_new_line()) ret.append(self.curse_new_line())
# Free memory usage # Free memory usage
msg = '{:6}'.format('free:') ret.extend(self.curse_add_stat('free', width=15))
ret.append(self.curse_add_line(msg)) # Cached memory usage
msg = '{:>7}'.format(self.auto_unit(self.stats['free'])) ret.extend(self.curse_add_stat('cached', width=18, header=' '))
ret.append(self.curse_add_line(msg))
# Cached memory usage
if 'cached' in self.stats:
msg = ' {:9}'.format('cached:')
ret.append(self.curse_add_line(msg, optional=self.get_views(key='cached', option='optional')))
msg = '{:>7}'.format(self.auto_unit(self.stats['cached']))
ret.append(self.curse_add_line(msg, optional=self.get_views(key='cached', option='optional')))
return ret return ret

View File

@ -28,17 +28,22 @@ import psutil
# Fields description # Fields description
fields_description = { fields_description = {
'total': {'description': 'Total swap memory.', 'total': {'description': 'Total swap memory.',
'unit': 'bytes'}, 'unit': 'bytes',
'min_symbol': 'K'},
'used': {'description': 'Used swap memory.', 'used': {'description': 'Used swap memory.',
'unit': 'bytes'}, 'unit': 'bytes',
'min_symbol': 'K'},
'free': {'description': 'Free swap memory.', 'free': {'description': 'Free swap memory.',
'unit': 'bytes'}, 'unit': 'bytes',
'min_symbol': 'K'},
'percent': {'description': 'Used swap memory in percentage.', 'percent': {'description': 'Used swap memory in percentage.',
'unit': 'percent'}, 'unit': 'percent'},
'sin': {'description': 'The number of bytes the system has swapped in from disk (cumulative).', 'sin': {'description': 'The number of bytes the system has swapped in from disk (cumulative).',
'unit': 'bytes'}, 'unit': 'bytes',
'min_symbol': 'K'},
'sout': {'description': 'The number of bytes the system has swapped out from disk (cumulative).', 'sout': {'description': 'The number of bytes the system has swapped out from disk (cumulative).',
'unit': 'bytes'}, 'unit': 'bytes',
'min_symbol': 'K'},
'time_since_update': {'description': 'Number of seconds since last update.', 'time_since_update': {'description': 'Number of seconds since last update.',
'unit': 'seconds'}, 'unit': 'seconds'},
} }
@ -175,8 +180,8 @@ class Plugin(GlancesPlugin):
if not self.stats or self.is_disable(): if not self.stats or self.is_disable():
return ret return ret
# Build the string message # First line
# Header # total%
msg = '{}'.format('SWAP') msg = '{}'.format('SWAP')
ret.append(self.curse_add_line(msg, "TITLE")) ret.append(self.curse_add_line(msg, "TITLE"))
msg = ' {:3}'.format(self.trend_msg(self.get_trend('percent'))) msg = ' {:3}'.format(self.trend_msg(self.get_trend('percent')))
@ -185,27 +190,23 @@ class Plugin(GlancesPlugin):
msg = '{:>6.1%}'.format(self.stats['percent'] / 100) msg = '{:>6.1%}'.format(self.stats['percent'] / 100)
ret.append(self.curse_add_line( ret.append(self.curse_add_line(
msg, self.get_views(key='percent', option='decoration'))) msg, self.get_views(key='percent', option='decoration')))
# New line
# Second line
# total
ret.append(self.curse_new_line()) ret.append(self.curse_new_line())
# Total memory usage # Total memory usage
msg = '{:8}'.format('total:') ret.extend(self.curse_add_stat('total', width=16))
ret.append(self.curse_add_line(msg))
msg = '{:>6}'.format(self.auto_unit(self.stats['total'])) # Third line
ret.append(self.curse_add_line(msg)) # used
# New line
ret.append(self.curse_new_line()) ret.append(self.curse_new_line())
# Used memory usage # Used memory usage
msg = '{:8}'.format('used:') ret.extend(self.curse_add_stat('used', width=16))
ret.append(self.curse_add_line(msg))
msg = '{:>6}'.format(self.auto_unit(self.stats['used'])) # Fourth line
ret.append(self.curse_add_line( # free
msg, self.get_views(key='used', option='decoration')))
# New line
ret.append(self.curse_new_line()) ret.append(self.curse_new_line())
# Free memory usage # Free memory usage
msg = '{:8}'.format('free:') ret.extend(self.curse_add_stat('free', width=16))
ret.append(self.curse_add_line(msg))
msg = '{:>6}'.format(self.auto_unit(self.stats['free']))
ret.append(self.curse_add_line(msg))
return ret return ret

View File

@ -43,8 +43,17 @@ fields_unit_short = {
fields_unit_type = { fields_unit_type = {
'percent': 'float', 'percent': 'float',
'percents': 'float',
'number': 'int', 'number': 'int',
'seconds': 'int' 'numbers': 'int',
'int': 'int',
'ints': 'int',
'float': 'float',
'floats': 'float',
'second': 'int',
'seconds': 'int',
'byte': 'int',
'bytes': 'int'
} }
@ -992,6 +1001,9 @@ class GlancesPlugin(object):
ret.extend(self.curse_add_stat('idle', width=15, header=' ')) ret.extend(self.curse_add_stat('idle', width=15, header=' '))
""" """
if key not in self.stats:
return []
# Check if a shortname is defined # Check if a shortname is defined
if 'short_name' in self.fields_description[key]: if 'short_name' in self.fields_description[key]:
key_name = self.fields_description[key]['short_name'] key_name = self.fields_description[key]['short_name']