Skip to content

Instantly share code, notes, and snippets.

@russss
Created June 7, 2012 10:46
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save russss/2888158 to your computer and use it in GitHub Desktop.
Save russss/2888158 to your computer and use it in GitHub Desktop.
Quick script to send Jenkins successful build durations to Graphite
#!/usr/bin/env python
""" Sends Jenkins build duration statistics to Graphite. """
import requests
import json
from graphite import Graphite # This is our closed-source library but you get the idea.
JENKINS_URL='http://jenkins'
GRAPHITE_HOST='10.x.x.x'
GRAPHITE_PREFIX='jenkins.main.build_time.'
def get_jobs(host):
response = json.loads(requests.get('%s/api/json' % host).text)
return response['jobs']
def get_build_details(job_url):
return json.loads(requests.get('%s/lastSuccessfulBuild/api/json' % job_url).text)
if __name__ == '__main__':
graphite = Graphite(GRAPHITE_HOST)
for job in get_jobs(JENKINS_URL):
build = get_build_details(job['url'])
graphite.send_metric(GRAPHITE_PREFIX + job['name'],
int(build['duration']) // 1000,
int(build['timestamp']) // 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment