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)
|
# Manage ZFS cache (see #3979 for details)
|
||||||
if self.zfs_enabled:
|
if self.zfs_enabled:
|
||||||
|
zfs_size = 0
|
||||||
zfs_shrink = 0
|
zfs_shrink = 0
|
||||||
zfs_cache_stats = zfs_stats()
|
zfs_cache_stats = zfs_stats()
|
||||||
# Uncomment the following line to use the test data
|
# Uncomment the following line to use the test data
|
||||||
|
|
@ -183,23 +184,27 @@ class MemPlugin(GlancesPluginModel):
|
||||||
zfs_cmin = zfs_cache_stats['arcstats.c_min']
|
zfs_cmin = zfs_cache_stats['arcstats.c_min']
|
||||||
else:
|
else:
|
||||||
zfs_cmin = 0
|
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
|
# Add the ZFS cache to the 'cached' memory
|
||||||
if 'cached' in stats:
|
if 'cached' in stats:
|
||||||
stats['cached'] += zfs_shrink
|
stats['cached'] += zfs_size
|
||||||
else:
|
else:
|
||||||
stats['cached'] = zfs_shrink
|
stats['cached'] = zfs_size
|
||||||
|
|
||||||
# Use the 'free'/htop calculation
|
# Add the amount ZFS cache can shrink to 'available' memory
|
||||||
# free=available+buffer+cached
|
if 'available' in stats:
|
||||||
stats['free'] = stats['available']
|
stats['available'] += zfs_shrink
|
||||||
if hasattr(stats, 'buffers'):
|
else:
|
||||||
stats['free'] += stats['buffers']
|
stats['available'] = zfs_shrink
|
||||||
if hasattr(stats, 'cached'):
|
|
||||||
stats['free'] += stats['cached']
|
# Subtract the amount ZFS cache can shrink from 'used' memory
|
||||||
# used=total-free
|
stats['used'] -= zfs_shrink
|
||||||
stats['used'] = stats['total'] - stats['free']
|
|
||||||
|
# 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
|
return stats
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ from glances.cpu_percent import cpu_percent
|
||||||
from glances.logger import logger
|
from glances.logger import logger
|
||||||
from glances.outputs.glances_bars import Bar
|
from glances.outputs.glances_bars import Bar
|
||||||
from glances.outputs.glances_sparklines import Sparkline
|
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.load import get_load_average, get_nb_log_core, get_nb_phys_core
|
||||||
from glances.plugins.plugin.model import GlancesPluginModel
|
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
|
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
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
|
||||||
|
|
@ -123,7 +127,14 @@ class QuicklookPlugin(GlancesPluginModel):
|
||||||
stats['percpu'] = cpu_percent.get_percpu()
|
stats['percpu'] = cpu_percent.get_percpu()
|
||||||
|
|
||||||
# Get the virtual and swap memory
|
# 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:
|
try:
|
||||||
stats['swap'] = psutil.swap_memory().percent
|
stats['swap'] = psutil.swap_memory().percent
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue