Skip to content

Instantly share code, notes, and snippets.

@netshade
Created February 2, 2012 20:07
Show Gist options
  • Save netshade/1725469 to your computer and use it in GitHub Desktop.
Save netshade/1725469 to your computer and use it in GitHub Desktop.
Agent fork test
#!/usr/bin/env ruby
require 'rubygems'
require 'logger'
require 'instrumental_agent'
Instrumental::Agent.logger = Logger.new(STDOUT)
a = Instrumental::Agent.new('YOUR_API_KEY')
t = Time.now.to_i
forked = nil
a.increment("fork.start")
sleep(5)
main = fork do # Phusion fork
loop do
a.increment("main.loop")
if !forked && (Time.now.to_i - t) > 10
child = fork do # App fork
loop do
a.increment("forked.loop")
puts "FORK SEND!"
sleep 1
end
end
Process.detach(child)
forked = true
end
puts "MAIN SEND"
sleep 1
end
end
Process.wait(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment