Skip to content

Instantly share code, notes, and snippets.

@timgentry
Last active March 16, 2017 14:05
Show Gist options
  • Save timgentry/10b4bb413dddec6368121bb89beb435b to your computer and use it in GitHub Desktop.
Save timgentry/10b4bb413dddec6368121bb89beb435b to your computer and use it in GitHub Desktop.
# Usage: $ REDMINE_API_KEY=1234567890 ruby planio.rb
require 'json'
require 'open-uri'
require 'statsd-ruby'
def parse_api_json(relative_path)
include OpenURI
# TODO: check the relative path is a json endpoint
open("https://ncr.plan.io#{relative_path}",
'X-Redmine-API-Key' => ENV['REDMINE_API_KEY']) do |f|
json = f.read
json == '' ? {} : JSON.parse(json)
end
end
statsd = Statsd.new '127.0.0.1', 8125
raise 'Environment variable REDMINE_API_KEY not defined' if ENV['REDMINE_API_KEY'].nil?
loop do
total_count = parse_api_json('/issues.json?offset=0&limit=1')['total_count']
statsd.gauge('dev.planio.open_issues', total_count)
print '.'
sleep 60
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment