#
# If you are having troubles when using this script from cron(8) please try
# adjusting your PATH before reporting problems.
-#
-# /usr/bin & /sbin
-#
-# Binaries used are:
-#
-# dc(1), kldstat(8), sed(1), sysctl(8) & vmstat(8)
-#
-# Binaries that I am working on phasing out are:
-#
-# dc(1) & sed(1)
+"""Print statistics on the ZFS Adjustable Replacement Cache (ARC)
+
+Provides basic information on the ARC, its efficiency, the L2ARC (if present),
+the Data Management Unit (DMU), Virtual Devices (VDEVs), and tunables. See the
+in-source documentation and code at
+https://github.com/zfsonlinux/zfs/blob/master/module/zfs/arc.c for details.
+"""
import sys
import time
import getopt
import re
+
from os import listdir
from subprocess import Popen, PIPE
from decimal import Decimal as D
-
-usetunable = True
show_tunable_descriptions = False
alternate_tunable_layout = False
kstat_pobj = re.compile("^([^:]+):\s+(.+)\s*$", flags=re.M)
def get_Kstat():
+ """Collect information on the ZFS subsystem from the /proc virtual
+ file system. The name "kstat" is a holdover from the Solaris utility
+ of the same name.
+ """
+
def load_proc_kstats(fn, namespace):
+ """Collect information on a specific subsystem of the ARC"""
+
kstats = [line.strip() for line in open(fn)]
del kstats[0:2]
for kstat in kstats:
def fPerc(lVal=0, rVal=0, Decimal=2):
+ """Calculate percentage value and return in human-readable format"""
+
if rVal > 0:
return str("%0." + str(Decimal) + "f") % (100 * (lVal / rVal)) + "%"
else:
def get_arc_summary(Kstat):
+ """Collect general data on the ARC"""
output = {}
memory_throttle_count = Kstat[
def _arc_summary(Kstat):
+ """Print information on the ARC"""
+
# ARC Sizing
arc = get_arc_summary(Kstat)
def get_arc_efficiency(Kstat):
+ """Collect information on the efficiency of the ARC"""
+
output = {}
arc_hits = Kstat["kstat.zfs.misc.arcstats.hits"]
def _arc_efficiency(Kstat):
+ """Print information on the efficiency of the ARC"""
+
arc = get_arc_efficiency(Kstat)
sys.stdout.write("ARC Total accesses:\t\t\t\t\t%s\n" %
def get_l2arc_summary(Kstat):
+ """Collection information on the L2ARC"""
+
output = {}
l2_abort_lowmem = Kstat["kstat.zfs.misc.arcstats.l2_abort_lowmem"]
def _l2arc_summary(Kstat):
+ """Print information on the L2ARC"""
arc = get_l2arc_summary(Kstat)
def get_dmu_summary(Kstat):
+ """Collect information on the DMU"""
+
output = {}
zfetch_hits = Kstat["kstat.zfs.misc.zfetchstats.hits"]
def _dmu_summary(Kstat):
+ """Print information on the DMU"""
arc = get_dmu_summary(Kstat)
def get_vdev_summary(Kstat):
+ """Collect information on the VDEVs"""
+
output = {}
vdev_cache_delegations = \
def _vdev_summary(Kstat):
+ """Print information on the VDEVs"""
+
arc = get_vdev_summary(Kstat)
if arc['vdev_cache_total'] > 0:
def _tunable_summary(Kstat):
+ """Print information on tunables"""
+
global show_tunable_descriptions
global alternate_tunable_layout
def zfs_header():
- """Print title string with date
- """
+ """Print title string with date"""
+
daydate = time.strftime('%a %b %d %H:%M:%S %Y')
sys.stdout.write('\n'+'-'*72+'\n')
def usage():
+ """Print usage information"""
+
sys.stdout.write("Usage: arc_summary.py [-h] [-a] [-d] [-p PAGE]\n\n")
sys.stdout.write("\t -h, --help : "
"Print this help message and exit\n")
def main():
+ """Main function"""
+
global show_tunable_descriptions
global alternate_tunable_layout