Skip to content

Instantly share code, notes, and snippets.

@tpoland
Forked from crigor/connect.rb
Last active September 28, 2016 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpoland/892d8bc1609015d55f4d9aa970e896c6 to your computer and use it in GitHub Desktop.
Save tpoland/892d8bc1609015d55f4d9aa970e896c6 to your computer and use it in GitHub Desktop.
Modified version of tpol's script. Uses mysql2 gem.
#!/usr/bin/ruby
# gem install mysql2 -v 0.3.12b6
require 'rubygems'
require 'json'
#require 'mysql'
require 'mysql2'
def usage
puts "USAGE: connect.rb <connections> [<runtime>]"
exit
end
usage unless ARGV.length >= 1
connections, runtime = ARGV
runtime = runtime.nil? ? 100 : runtime.to_i
conn_arry = []
node = JSON.parse(IO.read('/etc/chef/dna.json'))
database = node['engineyard']['environment']['apps'].first['database_name']
db_pass = node['engineyard']['environment']['ssh_password']
db_user = node['users'].first['username']
db_host = node['db_host']
# override db_host to reference first replica
db_host = node['db_slaves'].first
(1..connections.to_i).each do |n|
begin
conn_arry[n - 1] = Mysql2::Client.new( :host => db_host, :username => db_user, :password => db_pass, :database => database)
puts "Progress: #{n} connections" if n % 2000 == 0
rescue Exception => e
puts e.message
break
end
end
puts "Reached #{conn_arry.length} of #{connections}"
sleep (runtime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment