Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I attempted to use the check_graphite.py plugin but was not successful.
Can anyone point out where I am going wrong?

xxx@xxx-Aspire-5738:/usr/lib/nagios/plugins$ python check_graphite.py -u (http://127.0.0.1:8080/render/?width=586&height=308&_salt=1349434980.323&from=-10minutes&target=system.loadavg_1min) -w 2.25 -c 2.5  
[1] 11103  
[2] 11104  
[3] 11105  
[4] 11106  
Status Unknown: Graphite returned an empty list of values  
-w: command not found  
[1]   Exit 3 ....                 python check_graphite.py -u (http://127.0.0.1:8080/render/?width=586)   
[2]   Done       .....             height=308  
[3]-  Done            .....        _salt=1349434980.323  
[4]+  Done                 .....  from=-10minutes 

and thus it ends. Any ideas?

check_graphite.py

from NagAconda import Plugin
import urllib2

def f_avg(values):
  return sum(values)/len(values);

def f_last(values):
  return values[-1]

def f_min(values):
  return min(values)

def f_max(values):
  return max(values)

functionmap = {
  "avg":{  "label": "average", "function": f_avg },
  "last":{ "label": "last",    "function": f_last },
  "min":{  "label": "minimum", "function": f_min },
  "max":{  "label": "maximum", "function": f_max },
}

graphite = Plugin("Plugin to retrieve data from graphite", "1.0")
graphite.add_option("u", "url", "URL to query for data", required=True)
graphite.add_option("U", "username", "User for authentication")
graphite.add_option("P", "password", "Password for authentication")
graphite.add_option("H", "hostname", "Host name to use in the URL")
graphite.add_option("n", "none", "Ignore None values: 'yes' or 'no' (default no)")
graphite.add_option("f", "function", "Function to run on retrieved values: avg/min/max/last (default 'avg')",
  default="avg")

graphite.enable_status("warning")
graphite.enable_status("critical")
graphite.start()

if graphite.options.username and graphite.options.password:
    password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
    password_mgr.add_password(None,uri=graphite.options.url,
                            user=graphite.options.username,
                            passwd=graphite.options.password)
    auth_handler =urllib2.HTTPBasicAuthHandler(password_mgr)
    opener = urllib2.build_opener(auth_handler)
    urllib2.install_opener(opener)

if graphite.options.hostname:
  graphite.options.url = graphite.options.url.replace('@HOSTNAME@', 
    graphite.options.hostname.replace('.','_'))

usock = urllib2.urlopen(graphite.options.url)
data = usock.read()
usock.close()

if graphite.options.function not in functionmap:
  graphite.unknown_error("Bad function name given to -f/--function option: '%s'" % graphite.options.function)

pieces = data.split("|")
counter = pieces[0].split(",")[0]
values = pieces[1].split(",")[:-1]

if graphite.options.none == 'yes':
  values = map(lambda x: float(x), filter(lambda x: x != 'None', values))
else:
  values = map(lambda x: 0.0 if x == 'None' else float(x), values)
if len(values) == 0:
  graphite.unknown_error("Graphite returned an empty list of values")
else:
  value = functionmap[graphite.options.function]["function"](values)

graphite.set_value(counter, value)
graphite.set_status_message("%s value of %s: %f" % (functionmap[graphite.options.function]["label"], counter, value))

graphite.finish()
share|improve this question
    
Exo, the script you pasted above appears to be the check plugin available at: github.com/datacratic/check_graphite but you have removed the copyright notice at the top, which is REQUIRED under the terms of the license. Please edit and comply with the law. –  Jason Antman Oct 22 '12 at 20:42
    
Just as a test, you may want to download the latest version of the script and try that... –  Jason Antman Oct 22 '12 at 20:42

1 Answer 1

Instead of enclosing your render URL with parentheses, try the following instead.

python check_graphite.py -u "http://127.0.0.1:8080/render/?width=586&height=308&_salt=1349434980.323&from=-10minutes&target=system.loadavg_1min" -w 2.25 -c 2.5
share|improve this answer
    
I have placed the parenthesis in this post only, i executed the command in terminal without them...sorry forgot to mention that before :( –  exo Oct 9 '12 at 6:21
    
You need to add the " or escape some of the characters. –  pkhamre Oct 9 '12 at 6:27
    
I got the following error: Traceback (most recent call last): File "check_graphite.py", line 63, in <module> values = map(lambda x: 0.0 if x == 'None' else float(x), values) File "check_graphite.py", line 63, in <lambda> values = map(lambda x: 0.0 if x == 'None' else float(x), values) ValueError: could not convert string to float: ��P�:� –  exo Oct 10 '12 at 10:46
    
I have edited the question & pasted the check_graphite.py script i'm using. –  exo Oct 11 '12 at 6:11
    
I will take a look. Edited your question to improve the formatting btw. –  pkhamre Oct 11 '12 at 6:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.