Skip to content

Commit

Permalink
arcstat: Add -a and -p options from FreeNAS
Browse files Browse the repository at this point in the history
Added -a option to automatically print all valid statistics.
Added -p option to suppress scaling of printed data.

Reviewed-by: George Melikov <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Authored by: Nick Principe <[email protected]>
Ported-by: Ryan Moeller <[email protected]>
Signed-off-by: Ryan Moeller <[email protected]>
Closes #11090
  • Loading branch information
Ryan Moeller authored and behlendorf committed Oct 30, 2020
1 parent 4df31aa commit 3b79394
Showing 2 changed files with 52 additions and 8 deletions.
38 changes: 32 additions & 6 deletions cmd/arcstat/arcstat.in
Original file line number Diff line number Diff line change
@@ -118,12 +118,13 @@ opfile = None
sep = " " # Default separator is 2 spaces
version = "0.4"
l2exist = False
cmd = ("Usage: arcstat [-hvx] [-f fields] [-o file] [-s string] [interval "
cmd = ("Usage: arcstat [-havxp] [-f fields] [-o file] [-s string] [interval "
"[count]]\n")
cur = {}
d = {}
out = None
kstat = None
pretty_print = True


if sys.platform.startswith('freebsd'):
@@ -181,13 +182,15 @@ def detailed_usage():
def usage():
sys.stderr.write("%s\n" % cmd)
sys.stderr.write("\t -h : Print this help message\n")
sys.stderr.write("\t -a : Print all possible stats\n")
sys.stderr.write("\t -v : List all possible field headers and definitions"
"\n")
sys.stderr.write("\t -x : Print extended stats\n")
sys.stderr.write("\t -f : Specify specific fields to print (see -v)\n")
sys.stderr.write("\t -o : Redirect output to the specified file\n")
sys.stderr.write("\t -s : Override default field separator with custom "
"character or string\n")
sys.stderr.write("\t -p : Disable auto-scaling of numerical fields\n")
sys.stderr.write("\nExamples:\n")
sys.stderr.write("\tarcstat -o /tmp/a.log 2 10\n")
sys.stderr.write("\tarcstat -s \",\" -o /tmp/a.log 2 10\n")
@@ -246,20 +249,29 @@ def print_values():
global hdr
global sep
global v
global pretty_print

sys.stdout.write(sep.join(
prettynum(cols[col][0], cols[col][1], v[col]) for col in hdr))
if pretty_print:
fmt = lambda col: prettynum(cols[col][0], cols[col][1], v[col])
else:
fmt = lambda col: v[col]

sys.stdout.write(sep.join(fmt(col) for col in hdr))
sys.stdout.write("\n")
sys.stdout.flush()


def print_header():
global hdr
global sep
global pretty_print

sys.stdout.write(sep.join("%*s" % (cols[col][0], col) for col in hdr))
if pretty_print:
fmt = lambda col: "%*s" % (cols[col][0], col)
else:
fmt = lambda col: col

sys.stdout.write(sep.join(fmt(col) for col in hdr))
sys.stdout.write("\n")


@@ -296,8 +308,10 @@ def init():
global sep
global out
global l2exist
global pretty_print

desired_cols = None
aflag = False
xflag = False
hflag = False
vflag = False
@@ -306,14 +320,16 @@ def init():
try:
opts, args = getopt.getopt(
sys.argv[1:],
"xo:hvs:f:",
"axo:hvs:f:p",
[
"all",
"extended",
"outfile",
"help",
"verbose",
"separator",
"columns"
"columns",
"parsable"
]
)
except getopt.error as msg:
@@ -322,6 +338,8 @@ def init():
opts = None

for opt, arg in opts:
if opt in ('-a', '--all'):
aflag = True
if opt in ('-x', '--extended'):
xflag = True
if opt in ('-o', '--outfile'):
@@ -337,6 +355,8 @@ def init():
if opt in ('-f', '--columns'):
desired_cols = arg
i += 1
if opt in ('-p', '--parsable'):
pretty_print = False
i += 1

argv = sys.argv[i:]
@@ -381,6 +401,12 @@ def init():
incompat)
usage()

if aflag:
if l2exist:
hdr = cols.keys()
else:
hdr = [col for col in cols.keys() if not col.startswith("l2")]

if opfile:
try:
out = open(opfile, "w")
22 changes: 20 additions & 2 deletions man/man1/arcstat.1
Original file line number Diff line number Diff line change
@@ -13,13 +13,13 @@
.\" Copyright (c) 2015 by Delphix. All rights reserved.
.\" Copyright (c) 2020 by AJ Jordan. All rights reserved.
.\"
.TH ARCSTAT 1 "Aug 24, 2020" OpenZFS
.TH ARCSTAT 1 "Oct 20, 2020" OpenZFS
.SH NAME
arcstat \- report ZFS ARC and L2ARC statistics
.SH SYNOPSIS
.LP
.nf
\fBarcstat\fR [\fB-hvx\fR] [\fB-f field[,field]...\fR] [\fB-o file\fR] [\fB-s string\fR] [\fBinterval\fR [\fBcount\fR]]
\fBarcstat\fR [\fB-havxp\fR] [\fB-f field[,field]...\fR] [\fB-o file\fR] [\fB-s string\fR] [\fBinterval\fR [\fBcount\fR]]
.fi

.SH DESCRIPTION
@@ -420,6 +420,15 @@ May temporarily be negative, in which case the ARC will reduce the target size \
.LP
The following options are supported:

.sp
.ne 2
.na
\fB\fB-a\fR\fR
.ad
.RS 12n
Print all possible stats.
.RE

.sp
.ne 2
.na
@@ -447,6 +456,15 @@ Display help message.
Report statistics to a file instead of the standard output.
.RE

.sp
.ne 2
.na
\fB\fB-p\fR\fR
.ad
.RS 12n
Disable auto-scaling of numerical fields (for raw, machine-parsable values).
.RE

.sp
.ne 2
.na

0 comments on commit 3b79394

Please sign in to comment.