Skip to content

Instantly share code, notes, and snippets.

@ronbee
Last active January 3, 2016 02:29
Show Gist options
  • Save ronbee/8396324 to your computer and use it in GitHub Desktop.
Save ronbee/8396324 to your computer and use it in GitHub Desktop.
a poor man's (REST'ful service) monitoring
require 'json'
require 'net/http'
class Service_Status_Monitor
TEST_SERVICES = [ 'http://111.111.111.111:8001/status' ] # this IS our config file..
def run outf
out = File.new( "#{File.dirname(__FILE__)}/#{outf}", "w" )
out.puts "1..#{TEST_SERVICES.size}"
TEST_SERVICES.each_with_index do |ustr,ii|
begin
reply = Net::HTTP.get_response( URI( ustr ) )
body = JSON.parse( reply.body ) rescue { "status" => "no content / http code #{reply.code}" }
out.puts "#{ ( reply.code == '200' and body["status"] == 'ok' ) ? "ok" : "not ok" } #{ii+1} - #{body}"
rescue => err
out.puts "not ok #{ii+1} - info: #{err}"
end
end
out.close
end
end
Service_Status_Monitor.new.run "monitor_status.out"

A Poor Man's Monitoring

Say you wanna monitor that your REST'ful service is up & working.

  1. treat gitted-file as a TAP unit-test
  2. define a TAP output project in Jenkins (that runs every xx minutes and sends email notifications)
  3. you're done

(in case of need, define more tests)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment