Skip to content

Instantly share code, notes, and snippets.

@tomquas
Created June 30, 2014 14:17
Show Gist options
  • Save tomquas/d13ffcff91d03e987b1c to your computer and use it in GitHub Desktop.
Save tomquas/d13ffcff91d03e987b1c to your computer and use it in GitHub Desktop.
fill influxdb w/ semi-random data
require 'socket'
require 'json'
total = ARGV.first.to_i || 1_000
packets_per_run = 1_000
def send_bulk(socket, packets)
packets.times do
socket.send [{name:"udp", columns:["v"], points:[[rand]]}].to_json, 0
end
sleep 1.0/8.0 # w/o this pause, we lose udp packets...
end
db = UDPSocket.new
db.connect '127.0.0.1', 4444
(total / packets_per_run).to_i.times { send_bulk(db, packets_per_run) }
send_bulk(db, total % packets_per_run)
db.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment