mirror of https://github.com/nicolargo/glances.git
Merge pull request #3285 from bkanuka/issue3979-zfs-cache
Fix ZFS cache math. Add ZFS to Quicklook
This commit is contained in:
commit
ac5c0dcc0b
|
|
@ -173,6 +173,7 @@ class MemPlugin(GlancesPluginModel):
|
|||
|
||||
# Manage ZFS cache (see #3979 for details)
|
||||
if self.zfs_enabled:
|
||||
zfs_size = 0
|
||||
zfs_shrink = 0
|
||||
zfs_cache_stats = zfs_stats()
|
||||
# Uncomment the following line to use the test data
|
||||
|
|
@ -183,23 +184,27 @@ class MemPlugin(GlancesPluginModel):
|
|||
zfs_cmin = zfs_cache_stats['arcstats.c_min']
|
||||
else:
|
||||
zfs_cmin = 0
|
||||
if zfs_size > zfs_cmin:
|
||||
zfs_shrink = zfs_size - zfs_cmin
|
||||
|
||||
zfs_shrink = zfs_size - zfs_cmin
|
||||
# Add the ZFS cache to the 'cached' memory
|
||||
if 'cached' in stats:
|
||||
stats['cached'] += zfs_shrink
|
||||
stats['cached'] += zfs_size
|
||||
else:
|
||||
stats['cached'] = zfs_shrink
|
||||
stats['cached'] = zfs_size
|
||||
|
||||
# Use the 'free'/htop calculation
|
||||
# free=available+buffer+cached
|
||||
stats['free'] = stats['available']
|
||||
if hasattr(stats, 'buffers'):
|
||||
stats['free'] += stats['buffers']
|
||||
if hasattr(stats, 'cached'):
|
||||
stats['free'] += stats['cached']
|
||||
# used=total-free
|
||||
stats['used'] = stats['total'] - stats['free']
|
||||
# Add the amount ZFS cache can shrink to 'available' memory
|
||||
if 'available' in stats:
|
||||
stats['available'] += zfs_shrink
|
||||
else:
|
||||
stats['available'] = zfs_shrink
|
||||
|
||||
# Subtract the amount ZFS cache can shrink from 'used' memory
|
||||
stats['used'] -= zfs_shrink
|
||||
|
||||
# Update percent to reflect new 'available' value
|
||||
stats['percent'] = float((stats['total'] - stats['available']) / stats['total'] * 100)
|
||||
|
||||
stats['used'] = stats['total'] - stats['available']
|
||||
|
||||
return stats
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ from glances.cpu_percent import cpu_percent
|
|||
from glances.logger import logger
|
||||
from glances.outputs.glances_bars import Bar
|
||||
from glances.outputs.glances_sparklines import Sparkline
|
||||
from glances.plugins.fs.zfs import zfs_enable, zfs_stats
|
||||
from glances.plugins.load import get_load_average, get_nb_log_core, get_nb_phys_core
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
|
|
@ -88,6 +89,9 @@ class QuicklookPlugin(GlancesPluginModel):
|
|||
args=args, config=config, items_history_list=items_history_list, fields_description=fields_description
|
||||
)
|
||||
|
||||
# ZFS
|
||||
self.zfs_enabled = zfs_enable()
|
||||
|
||||
# We want to display the stat in the curse interface
|
||||
self.display_curse = True
|
||||
|
||||
|
|
@ -123,7 +127,14 @@ class QuicklookPlugin(GlancesPluginModel):
|
|||
stats['percpu'] = cpu_percent.get_percpu()
|
||||
|
||||
# Get the virtual and swap memory
|
||||
stats['mem'] = psutil.virtual_memory().percent
|
||||
vm_stats = psutil.virtual_memory()
|
||||
mem_total = vm_stats.total
|
||||
mem_available = vm_stats.available
|
||||
if self.zfs_enabled:
|
||||
zfs_cache_stats = zfs_stats()
|
||||
mem_available = mem_available + zfs_cache_stats.get('arcstats.size', 0) - zfs_cache_stats.get('arcstats.c_min', 0)
|
||||
|
||||
stats['mem'] = float((mem_total - mem_available) / mem_total * 100 )
|
||||
try:
|
||||
stats['swap'] = psutil.swap_memory().percent
|
||||
except RuntimeError:
|
||||
|
|
|
|||
Loading…
Reference in New Issue