AppDynamics and Capistrano Tricks
December 5, 2012 1 Comment
We stood up a new performance environment last week and took some lessons learned and assistance that allowed us to get this up and running in record time. We did have a series of one off tasks (that will get added into the kick off process) but that we needed to solve now… Capistrano to the rescue!
Except of course we had the original definition of the environment, plus all the changes and add-ons were in Jira somewhere and we set of to scrape together the complete server list until we remembered that all of our hosts were instrumented with AppDynamics (and incidentally GLU or even Graphite can be used for this if they have app/server info)
# Capfile using AppDynamics
require ‘rubygems’
require ‘json’
require ‘open-uri’
default_run_options[:pty] = true
set :sshkey, “id_rsa”
ssh_options[:keys] = [File.join(ENV[“HOME”], “.ssh”, “#{sshkey}”)]
doc = open(‘http://appdynamics.server.com/controller/rest/applications/new_perf_env/nodes?&output=JSON‘, :http_basic_authentication=>[‘User@Customer1′,’Password’]).read
parsed = JSON.parse(doc)
mname = Hash.new
parsed.each do |hash|
if hash.has_key? ‘machineName’
mname[hash[‘machineName’]] = 1
end
end
mname.each do |name,value|
server “#{name}”, :server
end
desc “get hostname as root for no reason whatsoever”
task :hostname, :max_hosts => 100,:on_error => :continue do
run “#{sudo} hostname”
end