Skip to content

Instantly share code, notes, and snippets.

@ohadlevy
Created October 2, 2014 19:27
Show Gist options
  • Save ohadlevy/9083a02817be50fb516f to your computer and use it in GitHub Desktop.
Save ohadlevy/9083a02817be50fb516f to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'graphite-api'
require 'graphite-api/core_ext/numeric'
require './pull_request_stats'
# Or use the built-in one
GraphiteAPI::Logger.init(
:level => :debug,
:std => STDOUT
)
PROJECTS = %w{foreman smart-proxy foreman-installer hammer-cli hammer-cli-foreman staypuft community-templates foreman}
client = GraphiteAPI.new(
graphite: "0.0.0.0:2003", # required argument
prefix: %w(github theforeman), # add example.prefix to each key
slice: 60, # results are aggregated in 60 seconds slices
interval: 60, # send to graphite every 60 seconds
# default is 0 ( direct send )
cache: 4 * 60 * 60 # set the max age in seconds for records reanimation
)
metrics = {}
while true do
PROJECTS.each do |project|
begin
stats = PullRequestStat.new("theforeman/#{project}")
metrics["#{project}.pull_requests"] = stats.pull_requests
stats.labels.each do |label, value|
name = "#{project}.#{label.gsub(/(\s+|\.)/,'_').downcase}"
metrics[name] = value
end
rescue => e
warn e
end
end
client.metrics(metrics)
sleep 60
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment