Skip to content

Instantly share code, notes, and snippets.

@msonnabaum
Created October 12, 2012 07:01
Show Gist options
  • Save msonnabaum/3877707 to your computer and use it in GitHub Desktop.
Save msonnabaum/3877707 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'bundler/setup'
require 'socket'
require 'eventmachine'
require 'tire'
require 'json'
require 'securerandom'
$stdout.sync = true
$stderr.sync = true
Tire.configure do
url "192.168.3.20:9200"
end
module XHProfServer
def receive_data(data)
@buffer = '' if @buffer.nil?
@buffer << data
@buffer = process_whole_messages(@buffer)
end
def process_whole_messages(data)
return data if data !~ /\n/
messages = data.split("\n")
data = data =~ /\n$/ ? '' : messages.pop
messages.each {|message| process_message(message.strip)}
data
end
def process_message(mess)
run = JSON.parse(mess)
run[:id] = SecureRandom.base64
runs = [run]
Tire.index 'xhprofwtf' do
import runs
end
end
end
EM.run do
EM.open_datagram_socket '0.0.0.0', 8866, XHProfServer
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment