Created
August 20, 2015 20:19
-
-
Save gregbuehler/51c6747e269a9cd4fdfe to your computer and use it in GitHub Desktop.
Github contributor stats to influxdb
This file contains 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
require 'octokit' | |
require 'influxdb' | |
require 'yaml' | |
influxdb_config_file = File.dirname(File.expand_path(__FILE__)) + '/../config/influxdb.yml' | |
influxdb_config = YAML::load(File.open(influxdb_config_file)) | |
influxdb = InfluxDB::Client.new influxdb_config['database'], | |
username: influxdb_config['username'], | |
password: influxdb_config['password'], | |
async: true | |
github_config_file = File.dirname(File.expand_path(__FILE__)) + '/../config/github.yml' | |
github_config = YAML::load(File.open(github_config_file)) | |
gh_client = Octokit::Client.new( | |
:login => github_config['username'], | |
:password => github_config['username'], | |
:auto_paginate => true | |
) | |
repos = gh_client.org_repos(github_config['organization']) | |
unless repos.nil? | |
repos.each do |repo| | |
puts "Gathering stats for #{repo.full_name}" | |
data = [] | |
stats = gh_client.contributor_stats(repo.full_name) | |
unless stats.nil? or stats.is_a? string | |
stats.each do |stat| | |
puts "Gathering status for #{stat.author.login}@#{repo.full_name}" | |
stat.weeks.each do |week| | |
point = { | |
series: 'github', | |
tags: { | |
repository: repo.name, | |
author: stat.author.login | |
}, | |
values: { | |
additions: week.a, | |
deletions: week.d, | |
commits: week.c | |
}, | |
timestamp: week.w | |
} | |
data << point | |
end | |
end | |
end | |
precision = 'h' | |
influxdb.write_points(data, precision) | |
puts "wrote #{data.length} data points to influx" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment