Skip to content

Commit

Permalink
Adding -R option to pmiostat.
Browse files Browse the repository at this point in the history
The -R option will allow users to provide a regular expression
pattern to match the device names. Only devices matching the
pattern will be displayed.
  • Loading branch information
Nikhil Kshirsagar committed Apr 25, 2016
1 parent fdfedc3 commit 6c492cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/pcp/iostat/pcp-iostat.1
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
[\f3\-T\f1 \f2endtime\f1 \f3--finish=\f2TIME\f1]
[\f3\-t\f1 \f2interval\f1 \f3--interval=\f2DELTA\f1]
[\f3\-P\f1 \f2precision\f1 \f3--precision=\f2N\f1]
[\f3\-R\f1 \f2pattern\f1 \f3--regex=\f2pattern\f1]
[\f3\-u\f1 \f3--no-interpolate\f1]
[\f3\-Z\f1 \f2timezone\f1 \f3--timezone=\f2TZ\f1]
[\f3\-z\f1 \f3--hostzone\f1]
Expand Down Expand Up @@ -121,6 +122,11 @@ the reporting interval (unless the
.B \-u
option is specified, see below).
.TP
.B \-R
This indicates the pattern to search in the device name. The pattern is searched as a perl style
regular expression.
For eg. 'sd[a-zA-Z]+' will match all device names starting with sd followed by one or more alphabets.
.TP
.B \-P
This indicates the number of decimals to print. The default precision \f2N\f1
may be set to something other than the default 2 decimals.
Expand Down
13 changes: 11 additions & 2 deletions src/pcp/iostat/pcp-iostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# pylint: disable=C0103,R0914,R0902
""" Display disk and device-mapper I/O statistics """

import re
import sys
import signal
from pcp import pmapi, pmcc
Expand Down Expand Up @@ -54,6 +55,7 @@ def prevVals(self, group, name):
return dict(map(lambda x: (x[1], x[2]), group[name].netPrevValues))

def report(self, manager):
regex = IostatOptions.Rflag
precision = IostatOptions.Pflag
if precision < 0 or precision > 10 :
print("Precision value must be between 0 and 10")
Expand Down Expand Up @@ -210,6 +212,8 @@ def report(self, manager):
if "noidle" in IostatOptions.xflag:
if rrqm == 0 and wrqm == 0 and r == 0 and w == 0 :
continue
if IostatOptions.Rflag and re.search(regex,device) == None:
continue
print(valfmt % (timestamp, device,rrqmspace, precision, rrqm,wrqmspace,precision, wrqm,precision+5,precision,\
r,precision+4,precision, w,precision+6,precision, rkb,precision+6,precision, wkb, avgrqszspace,precision+1 ,avgrqsz,\
avgrqszspace,precision+1, avgqsz,precision+5,precision, await,awaitspace,precision, r_await,awaitspace,precision,\
Expand All @@ -222,6 +226,8 @@ def report(self, manager):
if "noidle" in IostatOptions.xflag:
if rrqm == 0 and wrqm == 0 and r == 0 and w == 0 :
continue
if IostatOptions.Rflag and re.search(regex,device) == None:
continue
print(valfmt % (device,rrqmspace, precision, rrqm,wrqmspace,precision, wrqm,precision+5,precision, r,precision+4,\
precision, w,precision+6,precision, rkb,precision+6,precision, wkb,\
avgrqszspace,precision+1 ,avgrqsz,avgrqszspace,precision+1, avgqsz,precision+5,precision, await,awaitspace,precision,\
Expand All @@ -236,7 +242,7 @@ class IostatOptions(pmapi.pmOptions):
xflag = []
uflag = None
Pflag = 2

Rflag = ""
def checkOptions(self, manager):
if IostatOptions.uflag:
if manager._options.pmGetOptionInterval():
Expand All @@ -254,9 +260,11 @@ def extraOptions(self, opt, optarg, index):
IostatOptions.uflag = True
elif opt == "P":
IostatOptions.Pflag = int(optarg)
elif opt == "R":
IostatOptions.Rflag = optarg

def __init__(self):
pmapi.pmOptions.__init__(self, "A:a:D:h:O:P:S:s:T:t:uVZ:z?x:")
pmapi.pmOptions.__init__(self, "A:a:D:h:O:P:R:S:s:T:t:uVZ:z?x:")
self.pmSetOptionCallback(self.extraOptions)
self.pmSetLongOptionHeader("General options")
self.pmSetLongOptionAlign()
Expand All @@ -265,6 +273,7 @@ def __init__(self):
self.pmSetLongOptionHost()
self.pmSetLongOptionOrigin()
self.pmSetLongOption("precision", 1, "P", "N", "N digits after the decimal separator")
self.pmSetLongOption("regex", 1, "R", "pattern", "only report for devices names matching pattern, e.g. 'sd[a-zA-Z]+'")
self.pmSetLongOptionStart()
self.pmSetLongOptionSamples()
self.pmSetLongOptionFinish()
Expand Down

0 comments on commit 6c492cc

Please sign in to comment.