Last active
August 29, 2015 14:05
-
-
Save simondean/db276ce4ae1dae344dce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require 'json' | |
require 'socket' | |
require 'time' | |
# Create a string containing 1 megabyte of data | |
output = 'A' * ((1 * 1024 * 1024) + 1) | |
sensu_events = 2.times.map do |i| | |
{ | |
:name => "long_event_#{i}", | |
:handlers => ['null'], | |
:output => output, | |
:status => 2 | |
} | |
end | |
sensu_events.each do |sensu_event| | |
puts "#{Time.now.utc.iso8601} Sending event #{sensu_event[:name]}" | |
data = sensu_event.to_json | |
start_time = Time.now | |
socket = TCPSocket.new('127.0.0.1', 3030) | |
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) | |
index = 0 | |
length = data.length | |
while index < length | |
bytes_sent = socket.send data[index..-1], 0 | |
puts "#{Time.now.utc.iso8601} bytes_sent: #{bytes_sent}" | |
break if bytes_sent < 0 | |
index += bytes_sent | |
end | |
socket.close | |
puts "#{Time.now.utc.iso8601} Done" | |
end_time = Time.now | |
duration = end_time - start_time | |
puts "#{Time.now.utc.iso8601} duration: #{duration} seconds" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment