Skip to content

Instantly share code, notes, and snippets.

@stefansundin
Last active May 1, 2016 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefansundin/fcef4e824f7747d07d1453ef2011afea to your computer and use it in GitHub Desktop.
Save stefansundin/fcef4e824f7747d07d1453ef2011afea to your computer and use it in GitHub Desktop.
Plot GitHub API rate limit usage with gnuplot.
#!/usr/bin/env ruby
# gem install httparty
require "httparty"
trap "SIGINT" do
STDERR.write "\nBye!"
exit 1
end
while true
begin
r = HTTParty.get("https://gh-rss.herokuapp.com/ratelimit", format: :json)
if r.success?
data = r.parsed_response
remaining = data["remaining"] || "5000"
puts "#{Time.now.to_i} #{remaining}"
STDOUT.flush
end
sleep 10
rescue => e
STDERR.puts "Error: #{e}."
sleep 10
end
end
#!/bin/bash
# empty line to indicate a break in the data
echo "" >> github.dat
./github.rb >> github.dat
#!/usr/bin/env gnuplot
set terminal png size 900, 300
set output "github.png"
set xdata time
set timefmt "%s"
set grid
set xtics 3600
plot [:][:] "github.dat" using 1:2 title "GitHub API Limit" with lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment