Skip to content

Commit 3d8a572

Browse files
authored
Update check_purefa_perf.py
1 parent d8d7fc5 commit 3d8a572

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

check_purefa_perf.py

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
## Overview
55
#
66
# This short Nagios/Icinga plugin code shows how to build a simple plugin to monitor Pure Storage FlashArrays.
7-
# The Pure Storage Python REST Client is used to query the FlashArray basic performance counters.
7+
# The Pure Storage Python REST Client is used to query the FlashArray performance counters. An optional parameter
8+
# allow to check a single volume instead than the whole flasharray
89
# Plugin leverages the remarkably helpful nagiosplugin library by Christian Kauhaus.
910
#
1011
## Installation
@@ -31,11 +32,17 @@
3132
3233
Nagios plugin to retrieve the six (6) basic KPIs from a Pure Storage FlashArray.
3334
Bandwidth counters (read/write), IOPs counters (read/write) and latency (read/write) are collected from the
35+
The plugin has two mandatory arguments: 'endpoint', which specifies the target FA and 'apitoken', which
36+
specifies the autentication token for the REST call session. A third optional parameter, 'volname' can
37+
be used to check a specific named volume.
3438
target FA using the REST call.
35-
Plugin accepts multiple warning and critical threshold parameters in a positional fashion
36-
37-
38-
39+
The plugin accepts multiple warning and critical threshold parameters in a positional fashion:
40+
1st threshold refers to write latency
41+
2nd threshold refers to read latency
42+
3rd threshold refers to write bandwidth
43+
4th threshold refers to read bandwidth
44+
5th threshold refers to write IOPS
45+
6th threshold refers to read IOPS
3946
4047
"""
4148

@@ -56,15 +63,26 @@ class PureFAperf(nagiosplugin.Resource):
5663
metric objects
5764
"""
5865

59-
def __init__(self, endpoint, apitoken):
66+
def __init__(self, endpoint, apitoken, volname=None):
6067
self.endpoint = endpoint
6168
self.apitoken = apitoken
69+
self.volname = volname
70+
71+
@property
72+
def name(self):
73+
if (self.volname is None):
74+
return 'PURE_FA_PERF'
75+
else:
76+
return 'PURE_VOL_PERF'
6277

6378
def get_perf(self):
6479
"""Gets performance counters from flasharray."""
6580
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
6681
fa = purestorage.FlashArray(self.endpoint, api_token=self.apitoken)
67-
fainfo = fa.get(action='monitor')[0]
82+
if (self.volname is None):
83+
fainfo = fa.get(action='monitor')[0]
84+
else:
85+
fainfo = fa.get_volume(self.volname, action='monitor')[0]
6886
fa.invalidate_cookie()
6987
return(fainfo)
7088

@@ -78,13 +96,18 @@ def probe(self):
7896
rbw = int(fainfo.get('output_per_sec'))
7997
wiops = int(fainfo.get('writes_per_sec'))
8098
riops = int(fainfo.get('reads_per_sec'))
99+
if (self.volname is None):
100+
mlabel = 'FA '
101+
else:
102+
mlabel = self.volname + ' '
103+
81104
metrics = [
82-
nagiosplugin.Metric('wlat', wlat, 'us', min=0),
83-
nagiosplugin.Metric('rlat', rlat, 'us', min=0),
84-
nagiosplugin.Metric('wbw', wbw, 'B/s', min=0),
85-
nagiosplugin.Metric('rbw', rbw, 'B/s', min=0),
86-
nagiosplugin.Metric('wiops', wiops, 'wr/s', min=0),
87-
nagiosplugin.Metric('riops', riops, 'rd/s', min=0)
105+
nagiosplugin.Metric(mlabel + 'wlat', wlat, 'us', min=0, context='wlat'),
106+
nagiosplugin.Metric(mlabel + 'rlat', rlat, 'us', min=0, context='wlat'),
107+
nagiosplugin.Metric(mlabel + 'wbw', wbw, 'B/s', min=0, context='wbw'),
108+
nagiosplugin.Metric(mlabel + 'rbw', rbw, 'B/s', min=0, context='rbw'),
109+
nagiosplugin.Metric(mlabel + 'wiops', wiops, 'wr/s', min=0, context='wiops'),
110+
nagiosplugin.Metric(mlabel + 'riops', riops, 'rd/s', min=0, context='riops')
88111
]
89112
return metrics
90113

@@ -93,6 +116,7 @@ def parse_args():
93116
argp = argparse.ArgumentParser()
94117
argp.add_argument('endpoint', help="FA hostname or ip address")
95118
argp.add_argument('apitoken', help="FA api_token")
119+
argp.add_argument('--vol', help="FA volme. If omitted the whole FA performance counters are checked")
96120
argp.add_argument('--tw', '--ttot-warning', metavar='RANGE[,RANGE,...]',
97121
type=nagiosplugin.MultiArg, default='',
98122
help="positional thresholds: write_latency, read_latenxy, write_bandwidth, read_bandwidth, write_iops, read_iops")
@@ -109,7 +133,7 @@ def parse_args():
109133
@nagiosplugin.guarded
110134
def main():
111135
args = parse_args()
112-
check = nagiosplugin.Check( PureFAperf(args.endpoint, args.apitoken) )
136+
check = nagiosplugin.Check( PureFAperf(args.endpoint, args.apitoken, args.vol) )
113137
check.add(nagiosplugin.ScalarContext('wlat', args.tw[0], args.tc[0]))
114138
check.add(nagiosplugin.ScalarContext('rlat', args.tw[1], args.tc[1]))
115139
check.add(nagiosplugin.ScalarContext('wbw', args.tw[2], args.tc[2]))

0 commit comments

Comments
 (0)