├── LICENSE ├── README.md └── check_graphite /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Recoset 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ##No longer maintained... 2 | 3 | We no longer use this script internally so we are no longer maintaining it. Unfortunately, that means we won't accept any pull requests, but if you make some improvements, we would be happy to link to your repo. 4 | 5 | Here are some forks which have useful improvements: 6 | 7 | * Support for multiple lines: https://github.com/olivierHa/check_graphite 8 | 9 | ##Nagios plugin to poll Graphite 10 | 11 | ###What does it do? How does it work? How do I run it? 12 | 13 | This is a Nagios plugin, so you install it and configure a service check in Nagios and it runs whenever Nagios calls it and reports back on the status of whatever it's monitoring. It takes one parameter (`-u`) which tells it the Graphite URL to monitor, for example `http://server/render?target=stats.auctionStart&from=-1minutes&rawData=true`. When run, it will query that URL and treat the average of the values returned as the 'value' to be compared against the warning/critical thresholds, and return this value to Nagios as performance data. See Graphite's URL API documentation to generate the URL parameter. 14 | 15 | ###Dependencies 16 | 17 | Python 2.6+ 18 | 19 | You'll need to have NagAconda installed (e.g. `easy_install nagaconda`) 20 | -------------------------------------------------------------------------------- /check_graphite: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright (c) 2011 Recoset 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | 23 | from NagAconda import Plugin 24 | import urllib2 25 | 26 | def f_avg(values): 27 | return sum(values)/len(values); 28 | 29 | def f_last(values): 30 | return values[-1] 31 | 32 | def f_min(values): 33 | return min(values) 34 | 35 | def f_max(values): 36 | return max(values) 37 | 38 | def f_sum(values): 39 | return sum(values) 40 | 41 | functionmap = { 42 | "avg":{ "label": "average", "function": f_avg }, 43 | "last":{ "label": "last", "function": f_last }, 44 | "min":{ "label": "minimum", "function": f_min }, 45 | "max":{ "label": "maximum", "function": f_max }, 46 | "sum":{ "label": "sum", "function": f_sum }, 47 | } 48 | 49 | graphite = Plugin("Plugin to retrieve data from graphite", "1.0") 50 | graphite.add_option("u", "url", "URL to query for data", required=True) 51 | graphite.add_option("U", "username", "User for authentication") 52 | graphite.add_option("P", "password", "Password for authentication") 53 | graphite.add_option("H", "hostname", "Host name to use in the URL") 54 | graphite.add_option("n", "none", "Ignore None values: 'yes' or 'no' (default no)") 55 | graphite.add_option("f", "function", "Function to run on retrieved values: avg/min/max/last/sum (default 'avg')", 56 | default="avg") 57 | 58 | graphite.enable_status("warning") 59 | graphite.enable_status("critical") 60 | graphite.start() 61 | 62 | if graphite.options.username and graphite.options.password: 63 | password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() 64 | password_mgr.add_password(None,uri=graphite.options.url, 65 | user=graphite.options.username, 66 | passwd=graphite.options.password) 67 | auth_handler =urllib2.HTTPBasicAuthHandler(password_mgr) 68 | opener = urllib2.build_opener(auth_handler) 69 | urllib2.install_opener(opener) 70 | 71 | if graphite.options.hostname: 72 | graphite.options.url = graphite.options.url.replace('@HOSTNAME@', 73 | graphite.options.hostname.replace('.','_')) 74 | 75 | usock = urllib2.urlopen(graphite.options.url) 76 | data = usock.read() 77 | usock.close() 78 | 79 | if graphite.options.function not in functionmap: 80 | graphite.unknown_error("Bad function name given to -f/--function option: '%s'" % graphite.options.function) 81 | 82 | try: 83 | pieces = data.split("|") 84 | counter = pieces[0].split(",")[0] 85 | values = pieces[1].split(",")[:-1] 86 | if len(data.strip().split('\n')) > 1: 87 | raise 'Graphite returned multiple lines' 88 | except: 89 | graphite.unknown_error("Graphite returned bad data") 90 | 91 | if graphite.options.none == 'yes': 92 | values = map(lambda x: float(x), filter(lambda x: x != 'None', values)) 93 | else: 94 | values = map(lambda x: 0.0 if x == 'None' else float(x), values) 95 | if len(values) == 0: 96 | graphite.unknown_error("Graphite returned an empty list of values") 97 | else: 98 | value = functionmap[graphite.options.function]["function"](values) 99 | 100 | graphite.set_value(counter, value) 101 | graphite.set_status_message("%s value of %s: %f" % (functionmap[graphite.options.function]["label"], counter, value)) 102 | 103 | graphite.finish() 104 | --------------------------------------------------------------------------------