提交 c2da541c 编写于 作者: N nicolargo

Refactor Mem + MemSwap Curse

上级 73f091f2
......@@ -282,12 +282,12 @@ class Plugin(GlancesPlugin):
if not self.stats or self.args.percpu or self.is_disable():
return ret
# Build the string message
# If user stat is not here, display only idle / total CPU usage (for
# exemple on Windows OS)
idle_tag = 'user' not in self.stats
# Header
# First line
# Total + (idle) + ctx_sw
msg = '{}'.format('CPU')
ret.append(self.curse_add_line(msg, "TITLE"))
trend_user = self.get_trend('user')
......@@ -303,50 +303,46 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(
msg, self.get_views(key='total', option='decoration')))
# 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=' '))
# ctx_switches
if 'ctx_switches' in self.stats:
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())
# User CPU
if 'user' in self.stats:
if not idle_tag:
ret.extend(self.curse_add_stat('user', width=15))
elif 'idle' in self.stats:
ret.extend(self.curse_add_stat('idle', width=15))
# IRQ CPU
if 'irq' in self.stats:
ret.extend(self.curse_add_stat('irq', width=15, header=' '))
# interrupts
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())
# System CPU
if 'system' in self.stats and not idle_tag:
if not idle_tag:
ret.extend(self.curse_add_stat('system', width=15))
else:
ret.extend(self.curse_add_stat('core', width=15))
# Nice CPU
if 'nice' in self.stats:
ret.extend(self.curse_add_stat('nice', width=15, header=' '))
# soft_interrupts
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())
# IOWait CPU
if 'iowait' in self.stats:
ret.extend(self.curse_add_stat('iowait', width=15))
# Steal CPU usage
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)
if 'syscalls' in self.stats and not LINUX:
if not LINUX:
ret.extend(self.curse_add_stat('syscalls', width=15, header=' '))
# Return the message with decoration
......
......@@ -32,15 +32,15 @@ fields_description = {
'min1': {'description': 'Average sum of the number of processes \
waiting in the run-queue plus the number currently executing \
over 1 minute.',
'unit': 'number'},
'unit': 'float'},
'min5': {'description': 'Average sum of the number of processes \
waiting in the run-queue plus the number currently executing \
over 5 minutes.',
'unit': 'number'},
'unit': 'float'},
'min15': {'description': 'Average sum of the number of processes \
waiting in the run-queue plus the number currently executing \
over 15 minutes.',
'unit': 'number'},
'unit': 'float'},
'cpucore': {'description': 'Total number of CPU core.',
'unit': 'number'},
}
......
......@@ -2,7 +2,7 @@
#
# 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
# it under the terms of the GNU Lesser General Public License as published by
......@@ -28,32 +28,42 @@ import psutil
# Fields description
fields_description = {
'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 \
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) \
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.',
'unit': 'percent'},
'used': {'description': 'Memory used, calculated differently depending on the platform and \
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; \
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.',
'unit': 'bytes'},
'unit': 'bytes',
'min_symbol': 'K'},
'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.',
'unit': 'bytes'},
'unit': 'bytes',
'min_symbol': 'K'},
'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.',
'unit': 'bytes'},
'unit': 'bytes',
'min_symbol': 'K'},
'shared': {'description': '*(BSD)*: memory that may be simultaneously accessed by multiple processes.',
'unit': 'bytes'},
'unit': 'bytes',
'min_symbol': 'K'},
}
# SNMP OID
......@@ -214,8 +224,8 @@ class Plugin(GlancesPlugin):
if not self.stats or self.is_disable():
return ret
# Build the string message
# Header
# First line
# total% + active
msg = '{}'.format('MEM')
ret.append(self.curse_add_line(msg, "TITLE"))
msg = ' {:2}'.format(self.trend_msg(self.get_trend('percent')))
......@@ -225,50 +235,30 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(
msg, self.get_views(key='percent', option='decoration')))
# Active memory usage
if 'active' in self.stats:
msg = ' {:9}'.format('active:')
ret.append(self.curse_add_line(msg, optional=self.get_views(key='active', option='optional')))
msg = '{:>7}'.format(self.auto_unit(self.stats['active']))
ret.append(self.curse_add_line(msg, optional=self.get_views(key='active', option='optional')))
# New line
ret.extend(self.curse_add_stat('active', width=18, header=' '))
# Second line
# total + inactive
ret.append(self.curse_new_line())
# Total memory usage
msg = '{:6}'.format('total:')
ret.append(self.curse_add_line(msg))
msg = '{:>7}'.format(self.auto_unit(self.stats['total']))
ret.append(self.curse_add_line(msg))
ret.extend(self.curse_add_stat('total', width=15))
# Inactive memory usage
if 'inactive' in self.stats:
msg = ' {:9}'.format('inactive:')
ret.append(self.curse_add_line(msg, optional=self.get_views(key='inactive', option='optional')))
msg = '{:>7}'.format(self.auto_unit(self.stats['inactive']))
ret.append(self.curse_add_line(msg, optional=self.get_views(key='inactive', option='optional')))
# New line
ret.extend(self.curse_add_stat('inactive', width=18, header=' '))
# Third line
# used + buffers
ret.append(self.curse_new_line())
# Used memory usage
msg = '{:6}'.format('used:')
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')))
ret.extend(self.curse_add_stat('used', width=15))
# Buffers memory usage
if 'buffers' in self.stats:
msg = ' {:9}'.format('buffers:')
ret.append(self.curse_add_line(msg, optional=self.get_views(key='buffers', option='optional')))
msg = '{:>7}'.format(self.auto_unit(self.stats['buffers']))
ret.append(self.curse_add_line(msg, optional=self.get_views(key='buffers', option='optional')))
# New line
ret.extend(self.curse_add_stat('buffers', width=18, header=' '))
# Fourth line
# free + cached
ret.append(self.curse_new_line())
# Free memory usage
msg = '{:6}'.format('free:')
ret.append(self.curse_add_line(msg))
msg = '{:>7}'.format(self.auto_unit(self.stats['free']))
ret.append(self.curse_add_line(msg))
ret.extend(self.curse_add_stat('free', width=15))
# 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')))
ret.extend(self.curse_add_stat('cached', width=18, header=' '))
return ret
......@@ -28,17 +28,22 @@ import psutil
# Fields description
fields_description = {
'total': {'description': 'Total swap memory.',
'unit': 'bytes'},
'unit': 'bytes',
'min_symbol': 'K'},
'used': {'description': 'Used swap memory.',
'unit': 'bytes'},
'unit': 'bytes',
'min_symbol': 'K'},
'free': {'description': 'Free swap memory.',
'unit': 'bytes'},
'unit': 'bytes',
'min_symbol': 'K'},
'percent': {'description': 'Used swap memory in percentage.',
'unit': 'percent'},
'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).',
'unit': 'bytes'},
'unit': 'bytes',
'min_symbol': 'K'},
'time_since_update': {'description': 'Number of seconds since last update.',
'unit': 'seconds'},
}
......@@ -175,8 +180,8 @@ class Plugin(GlancesPlugin):
if not self.stats or self.is_disable():
return ret
# Build the string message
# Header
# First line
# total%
msg = '{}'.format('SWAP')
ret.append(self.curse_add_line(msg, "TITLE"))
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)
ret.append(self.curse_add_line(
msg, self.get_views(key='percent', option='decoration')))
# New line
# Second line
# total
ret.append(self.curse_new_line())
# Total memory usage
msg = '{:8}'.format('total:')
ret.append(self.curse_add_line(msg))
msg = '{:>6}'.format(self.auto_unit(self.stats['total']))
ret.append(self.curse_add_line(msg))
# New line
ret.extend(self.curse_add_stat('total', width=16))
# Third line
# used
ret.append(self.curse_new_line())
# Used memory usage
msg = '{:8}'.format('used:')
ret.append(self.curse_add_line(msg))
msg = '{:>6}'.format(self.auto_unit(self.stats['used']))
ret.append(self.curse_add_line(
msg, self.get_views(key='used', option='decoration')))
# New line
ret.extend(self.curse_add_stat('used', width=16))
# Fourth line
# free
ret.append(self.curse_new_line())
# Free memory usage
msg = '{:8}'.format('free:')
ret.append(self.curse_add_line(msg))
msg = '{:>6}'.format(self.auto_unit(self.stats['free']))
ret.append(self.curse_add_line(msg))
ret.extend(self.curse_add_stat('free', width=16))
return ret
......@@ -43,8 +43,17 @@ fields_unit_short = {
fields_unit_type = {
'percent': 'float',
'percents': 'float',
'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=' '))
"""
if key not in self.stats:
return []
# Check if a shortname is defined
if 'short_name' in self.fields_description[key]:
key_name = self.fields_description[key]['short_name']
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册