Last active
March 16, 2017 14:05
-
-
Save timgentry/10b4bb413dddec6368121bb89beb435b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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