Skip to content

Commit

Permalink
pass pep8
Browse files Browse the repository at this point in the history
This patch make the script pass pep8. No logical changes, it is mostly
whitespaces tweaks.

pep8 ignores E501 'lines too long' though.
  • Loading branch information
hashar committed May 11, 2013
1 parent af83ef6 commit 11c470c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .pep8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pep8]
# Ignore 'line too long'
ignore = E501
30 changes: 17 additions & 13 deletions jenkins-to-graphite.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@
# this should be available in any python 2.6 or newer
import json
except:
try:
# simplejson is a good replacement on 2.5 installs
import simplejson as json
except:
print "FATAL ERROR: can't find any json library for python"
print "Please install simplejson, json, or upgrade to python 2.6+"
sys.exit(1)
try:
# simplejson is a good replacement on 2.5 installs
import simplejson as json
except:
print "FATAL ERROR: can't find any json library for python"
print "Please install simplejson, json, or upgrade to python 2.6+"
sys.exit(1)
#end json import


class JenkinsServer(object):
def __init__(self, base_url, user, password):
self.base_url = base_url
Expand Down Expand Up @@ -68,14 +69,15 @@ def get_raw_data(self, url):
f.close()
data = json.loads(response)
except Exception, e:
logging.warn("Unable to get jenkins response for url %s: %s" %(url, e))
logging.warn("Unable to get jenkins response for url %s: %s" % (url, e))
return {}

return data

def get_data(self, url):
return self.get_raw_data("%s/api/json" % url)


class GraphiteServer(object):
def __init__(self, server, port, prefix):
self.server = server
Expand All @@ -85,7 +87,7 @@ def __init__(self, server, port, prefix):
self.data = {}

def add_data(self, key, value):
self.data["%s.%s" %( self.prefix, key)] = value
self.data["%s.%s" % (self.prefix, key)] = value

def _data_as_msg(self):
msg = ""
Expand All @@ -107,14 +109,15 @@ def send(self):

return True


def parse_args():
parser = optparse.OptionParser()
parser.add_option("", "--graphite-server",
help="Host name of the server running graphite")
parser.add_option("", "--graphite-port",
default="2003")
parser.add_option("", "--jenkins-url",
help="Base url of your jenkins server (ex http://jenkins.example.com")
help="Base url of your jenkins server (ex http://jenkins.example.com")
parser.add_option("", "--jenkins-user",
help="User to authenticate with for jenkins")
parser.add_option("", "--jenkins-password",
Expand All @@ -135,6 +138,7 @@ def parse_args():

return opts


def main():
opts = parse_args()
jenkins = JenkinsServer(opts.jenkins_url, opts.jenkins_user,
Expand All @@ -144,8 +148,8 @@ def main():

executor_info = jenkins.get_data("computer")
queue_info = jenkins.get_data("queue")
build_info_min = jenkins.get_raw_data("view/All/timeline/data?min=%d&max=%d" % ((time.time() - 60)*1000, time.time()*1000))
build_info_hour = jenkins.get_raw_data("view/All/timeline/data?min=%d&max=%d" % ((time.time() - 3600)*1000, time.time()*1000))
build_info_min = jenkins.get_raw_data("view/All/timeline/data?min=%d&max=%d" % ((time.time() - 60) * 1000, time.time() * 1000))
build_info_hour = jenkins.get_raw_data("view/All/timeline/data?min=%d&max=%d" % ((time.time() - 3600) * 1000, time.time() * 1000))

graphite.add_data("queue.size", len(queue_info.get("items", [])))

Expand All @@ -158,7 +162,7 @@ def main():
executor_info.get("totalExecutors", 0) -
executor_info.get("busyExecutors", 0))

nodes_total = executor_info.get("computer", []);
nodes_total = executor_info.get("computer", [])
nodes_offline = [j for j in nodes_total if j.get("offline")]
graphite.add_data("nodes.total", len(nodes_total))
graphite.add_data("nodes.offline", len(nodes_offline))
Expand Down

0 comments on commit 11c470c

Please sign in to comment.