Skip to content

Instantly share code, notes, and snippets.

@defHLT
Created March 30, 2013 10:51
Show Gist options
  • Save defHLT/5276299 to your computer and use it in GitHub Desktop.
Save defHLT/5276299 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# encoding: utf-8
# Created: 2013-03-30 11:49:19 +0200
# How often to check in seconds:
TIMEOUT = 10
# Alert when lag is greates then in seconds:
LAG_MAX = 0.05
STDOUT.sync = true
%w{
net/http
json
}.each { |r| require r}
def goxlag
begin
uri_raw = 'https://data.mtgox.com/api/1/generic/order/lag'
uri = URI.parse uri_raw
https = Net::HTTP.new uri.host, uri.port
https.use_ssl = true
request = Net::HTTP::Get.new uri.request_uri
response = https.request request
res = JSON.parse response.body
cur_lag = res["return"]['lag'].to_f
if cur_lag >= LAG_MAX*1e6
puts "ALERT"
end
puts "#{Time.now.to_s} lag: #{res["return"]["lag_secs"]} secs"
rescue Exception => e
puts "ERROR #{e.class} #{e.message}. Will retry"
end
end
if __FILE__ == $0
loop do
goxlag
sleep TIMEOUT
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment