Skip to content

Commit e03dc2c

Browse files
authored
Create check_purefa_perf.py
1 parent 536cf56 commit e03dc2c

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

check_purefa_perf.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2018 Pure Storage, Inc.
3+
#
4+
## Overview
5+
#
6+
# 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.
8+
# Plugin leverages the remarkably helpful nagiosplugin library by Christian Kauhaus.
9+
#
10+
## Installation
11+
#
12+
# The scripo should be copied to the Nagios plugins directory on the machine hosting the Nagios server or the NRPE
13+
# for example the /usr/lib/nagios/plugins folder.
14+
# Change the execution rights of the program to allow the execution to 'all' (usually chmod 0755).
15+
#
16+
## Dependencies
17+
#
18+
# nagiosplugin helper Python class library for Nagios plugins by Christian Kauhaus (http://pythonhosted.org/nagiosplugin)
19+
# purestorage Pure Storage Python REST Client (https://github.com/purestorage/rest-client)
20+
21+
__author__ = "Eugenio Grosso"
22+
__copyright__ = "Copyright 2018, Pure Storage Inc."
23+
__credits__ = "Christian Kauhaus"
24+
__license__ = "Apache v2.0"
25+
__version__ = "1.0"
26+
__maintainer__ = "Eugenio Grosso"
27+
__email__ = "geneg@purestorage.com"
28+
__status__ = "Production"
29+
30+
"""Pure Storage FlashArray performance indicators
31+
32+
Nagios plugin to retrieve the six (6) basic KPIs from a Pure Storage FlashArray.
33+
Bandwidth counters (read/write), IOPs counters (read/write) and latency (read/write) are collected from the
34+
target FA using the REST call.
35+
Plugin accepts multiple warning and critical threshold parameters in a positional fashion
36+
37+
38+
39+
40+
"""
41+
42+
import argparse
43+
import logging
44+
import nagiosplugin
45+
import purestorage
46+
import urllib3
47+
48+
49+
_log = logging.getLogger('nagiosplugin')
50+
51+
52+
class PureFAperf(nagiosplugin.Resource):
53+
"""Pure Storage FlashArray performance indicators
54+
55+
Gets the six global KPIs of the flasharray and stores them in the
56+
metric objects
57+
"""
58+
59+
def __init__(self, endpoint, apitoken):
60+
self.endpoint = endpoint
61+
self.apitoken = apitoken
62+
63+
def get_perf(self):
64+
"""Gets performance counters from flasharray."""
65+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
66+
fa = purestorage.FlashArray(self.endpoint, api_token=self.apitoken)
67+
fainfo = fa.get(action='monitor')[0]
68+
fa.invalidate_cookie()
69+
return(fainfo)
70+
71+
def probe(self):
72+
73+
fainfo = self.get_perf()
74+
_log.debug('FA REST call returned "%s" ', fainfo)
75+
wlat = int(fainfo.get('usec_per_write_op'))
76+
rlat = int(fainfo.get('usec_per_read_op'))
77+
wbw = int(fainfo.get('input_per_sec'))
78+
rbw = int(fainfo.get('output_per_sec'))
79+
wiops = int(fainfo.get('writes_per_sec'))
80+
riops = int(fainfo.get('reads_per_sec'))
81+
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)
88+
]
89+
return metrics
90+
91+
92+
def parse_args():
93+
argp = argparse.ArgumentParser()
94+
argp.add_argument('endpoint', help="FA hostname or ip address")
95+
argp.add_argument('apitoken', help="FA api_token")
96+
argp.add_argument('--tw', '--ttot-warning', metavar='RANGE[,RANGE,...]',
97+
type=nagiosplugin.MultiArg, default='',
98+
help="positional thresholds: write_latency, read_latenxy, write_bandwidth, read_bandwidth, write_iops, read_iops")
99+
argp.add_argument('--tc', '--ttot-critical', metavar='RANGE[,RANGE,...]',
100+
type=nagiosplugin.MultiArg, default='',
101+
help="positional thresholds: write_latency, read_latenxy, write_bandwidth, read_bandwidth, write_iops, read_iops")
102+
argp.add_argument('-v', '--verbose', action='count', default=0,
103+
help='increase output verbosity (use up to 3 times)')
104+
argp.add_argument('-t', '--timeout', default=30,
105+
help='abort execution after TIMEOUT seconds')
106+
return argp.parse_args()
107+
108+
109+
@nagiosplugin.guarded
110+
def main():
111+
args = parse_args()
112+
check = nagiosplugin.Check( PureFAperf(args.endpoint, args.apitoken) )
113+
check.add(nagiosplugin.ScalarContext('wlat', args.tw[0], args.tc[0]))
114+
check.add(nagiosplugin.ScalarContext('rlat', args.tw[1], args.tc[1]))
115+
check.add(nagiosplugin.ScalarContext('wbw', args.tw[2], args.tc[2]))
116+
check.add(nagiosplugin.ScalarContext('rbw', args.tw[3], args.tc[3]))
117+
check.add(nagiosplugin.ScalarContext('wiops', args.tw[4], args.tc[4]))
118+
check.add(nagiosplugin.ScalarContext('riops', args.tw[5], args.tc[5]))
119+
check.main(args.verbose, args.timeout)
120+
121+
if __name__ == '__main__':
122+
main()

0 commit comments

Comments
 (0)