arcstat: Add -a and -p options from FreeNAS
Added -a option to automatically print all valid statistics. Added -p option to suppress scaling of printed data. Reviewed-by: George Melikov <mail@gmelikov.ru> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Authored by: Nick Principe <32284693+powernap@users.noreply.github.com> Ported-by: Ryan Moeller <ryan@iXsystems.com> Signed-off-by: Ryan Moeller <ryan@iXsystems.com> Closes #11090
This commit is contained in:
parent
e53d678d4a
commit
2aaab887bb
|
@ -134,12 +134,13 @@ opfile = None
|
||||||
sep = " " # Default separator is 2 spaces
|
sep = " " # Default separator is 2 spaces
|
||||||
version = "0.4"
|
version = "0.4"
|
||||||
l2exist = False
|
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")
|
"[count]]\n")
|
||||||
cur = {}
|
cur = {}
|
||||||
d = {}
|
d = {}
|
||||||
out = None
|
out = None
|
||||||
kstat = None
|
kstat = None
|
||||||
|
pretty_print = True
|
||||||
|
|
||||||
|
|
||||||
if sys.platform.startswith('freebsd'):
|
if sys.platform.startswith('freebsd'):
|
||||||
|
@ -197,6 +198,7 @@ def detailed_usage():
|
||||||
def usage():
|
def usage():
|
||||||
sys.stderr.write("%s\n" % cmd)
|
sys.stderr.write("%s\n" % cmd)
|
||||||
sys.stderr.write("\t -h : Print this help message\n")
|
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"
|
sys.stderr.write("\t -v : List all possible field headers and definitions"
|
||||||
"\n")
|
"\n")
|
||||||
sys.stderr.write("\t -x : Print extended stats\n")
|
sys.stderr.write("\t -x : Print extended stats\n")
|
||||||
|
@ -204,6 +206,7 @@ def usage():
|
||||||
sys.stderr.write("\t -o : Redirect output to the specified file\n")
|
sys.stderr.write("\t -o : Redirect output to the specified file\n")
|
||||||
sys.stderr.write("\t -s : Override default field separator with custom "
|
sys.stderr.write("\t -s : Override default field separator with custom "
|
||||||
"character or string\n")
|
"character or string\n")
|
||||||
|
sys.stderr.write("\t -p : Disable auto-scaling of numerical fields\n")
|
||||||
sys.stderr.write("\nExamples:\n")
|
sys.stderr.write("\nExamples:\n")
|
||||||
sys.stderr.write("\tarcstat -o /tmp/a.log 2 10\n")
|
sys.stderr.write("\tarcstat -o /tmp/a.log 2 10\n")
|
||||||
sys.stderr.write("\tarcstat -s \",\" -o /tmp/a.log 2 10\n")
|
sys.stderr.write("\tarcstat -s \",\" -o /tmp/a.log 2 10\n")
|
||||||
|
@ -262,10 +265,14 @@ def print_values():
|
||||||
global hdr
|
global hdr
|
||||||
global sep
|
global sep
|
||||||
global v
|
global v
|
||||||
|
global pretty_print
|
||||||
|
|
||||||
sys.stdout.write(sep.join(
|
if pretty_print:
|
||||||
prettynum(cols[col][0], cols[col][1], v[col]) for col in hdr))
|
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.write("\n")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
@ -273,9 +280,14 @@ def print_values():
|
||||||
def print_header():
|
def print_header():
|
||||||
global hdr
|
global hdr
|
||||||
global sep
|
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")
|
sys.stdout.write("\n")
|
||||||
|
|
||||||
|
|
||||||
|
@ -312,8 +324,10 @@ def init():
|
||||||
global sep
|
global sep
|
||||||
global out
|
global out
|
||||||
global l2exist
|
global l2exist
|
||||||
|
global pretty_print
|
||||||
|
|
||||||
desired_cols = None
|
desired_cols = None
|
||||||
|
aflag = False
|
||||||
xflag = False
|
xflag = False
|
||||||
hflag = False
|
hflag = False
|
||||||
vflag = False
|
vflag = False
|
||||||
|
@ -322,14 +336,16 @@ def init():
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(
|
opts, args = getopt.getopt(
|
||||||
sys.argv[1:],
|
sys.argv[1:],
|
||||||
"xo:hvs:f:",
|
"axo:hvs:f:p",
|
||||||
[
|
[
|
||||||
|
"all",
|
||||||
"extended",
|
"extended",
|
||||||
"outfile",
|
"outfile",
|
||||||
"help",
|
"help",
|
||||||
"verbose",
|
"verbose",
|
||||||
"separator",
|
"separator",
|
||||||
"columns"
|
"columns",
|
||||||
|
"parsable"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
except getopt.error as msg:
|
except getopt.error as msg:
|
||||||
|
@ -338,6 +354,8 @@ def init():
|
||||||
opts = None
|
opts = None
|
||||||
|
|
||||||
for opt, arg in opts:
|
for opt, arg in opts:
|
||||||
|
if opt in ('-a', '--all'):
|
||||||
|
aflag = True
|
||||||
if opt in ('-x', '--extended'):
|
if opt in ('-x', '--extended'):
|
||||||
xflag = True
|
xflag = True
|
||||||
if opt in ('-o', '--outfile'):
|
if opt in ('-o', '--outfile'):
|
||||||
|
@ -353,6 +371,8 @@ def init():
|
||||||
if opt in ('-f', '--columns'):
|
if opt in ('-f', '--columns'):
|
||||||
desired_cols = arg
|
desired_cols = arg
|
||||||
i += 1
|
i += 1
|
||||||
|
if opt in ('-p', '--parsable'):
|
||||||
|
pretty_print = False
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
argv = sys.argv[i:]
|
argv = sys.argv[i:]
|
||||||
|
@ -397,6 +417,12 @@ def init():
|
||||||
incompat)
|
incompat)
|
||||||
usage()
|
usage()
|
||||||
|
|
||||||
|
if aflag:
|
||||||
|
if l2exist:
|
||||||
|
hdr = cols.keys()
|
||||||
|
else:
|
||||||
|
hdr = [col for col in cols.keys() if not col.startswith("l2")]
|
||||||
|
|
||||||
if opfile:
|
if opfile:
|
||||||
try:
|
try:
|
||||||
out = open(opfile, "w")
|
out = open(opfile, "w")
|
||||||
|
|
|
@ -13,13 +13,13 @@
|
||||||
.\" Copyright (c) 2015 by Delphix. All rights reserved.
|
.\" Copyright (c) 2015 by Delphix. All rights reserved.
|
||||||
.\" Copyright (c) 2020 by AJ Jordan. 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
|
.SH NAME
|
||||||
arcstat \- report ZFS ARC and L2ARC statistics
|
arcstat \- report ZFS ARC and L2ARC statistics
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.LP
|
.LP
|
||||||
.nf
|
.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
|
.fi
|
||||||
|
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
|
@ -510,6 +510,15 @@ May temporarily be negative, in which case the ARC will reduce the target size \
|
||||||
.LP
|
.LP
|
||||||
The following options are supported:
|
The following options are supported:
|
||||||
|
|
||||||
|
.sp
|
||||||
|
.ne 2
|
||||||
|
.na
|
||||||
|
\fB\fB-a\fR\fR
|
||||||
|
.ad
|
||||||
|
.RS 12n
|
||||||
|
Print all possible stats.
|
||||||
|
.RE
|
||||||
|
|
||||||
.sp
|
.sp
|
||||||
.ne 2
|
.ne 2
|
||||||
.na
|
.na
|
||||||
|
@ -537,6 +546,15 @@ Display help message.
|
||||||
Report statistics to a file instead of the standard output.
|
Report statistics to a file instead of the standard output.
|
||||||
.RE
|
.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
|
.sp
|
||||||
.ne 2
|
.ne 2
|
||||||
.na
|
.na
|
||||||
|
|
Loading…
Reference in New Issue