Mackerelã«ç»é²ãã¦ãããã¹ãã®æ å ±ããCapistrano 3.xã®ãããã¤å¯¾è±¡ãã¹ã群ã¨ãã¦å©ç¨ãããµã³ãã«ã§ãã
mackerel-client Gem ãå©ç¨ãã¾ãã
Gemfileã«è¿½è¨:
gem 'mackerel-client'
Capistrano ããå©ç¨ãã
config/{environment}.rb :
require 'mackerel/client' set :mackerel_api_key, MACKEREL_API_KEY set :service, SERVICE_NAME @client = Mackerel::Client.new(mackerel_api_key: mackerel_api_key) def host_ip_addrs(role) hosts = @client.get_hosts(service: service, roles: role).select do |host| host.status === 'standby' || host.status === 'working' end.map do |host| interface = host.interfaces.find { |i| /^eth/ === i['name'] } interface['ipAddress'] if interface end.select {|ipaddr| ipaddr != nil } end role :app, host_ip_addrs(:app) role :db, host_ip_addrs(:db)
SERVICE_NAMEã«ã¯Mackerelã«ç»é²ãã¦ãããµã¼ãã¹ã®ååãæå®ãã¦ãã ããã{environment}
ã«ã¯ production
staging
ãªã©ãå
¥ãã¾ãã
Capistranoã®ãã¼ã«ã¨ãã¦ãMackerelã§ãµã¼ãã¹ã«æå±ãã¦ãããã¹ã群ãæå®ã§ãã¾ãã
- ã¹ãã¼ã¿ã¹ã working ã¾ã㯠standby ã«ãªã£ã¦ãããã¹ããä¸è¦§ã§ãã¾ãã
- ãã¹ãã®IPã¢ãã¬ã¹ã¯ã¨ã¼ã¸ã§ã³ããåéãããã®ã使ç¨ããã¾ãã
ãããæµç¨ããã¿ã¹ã¯å®ç¾©ã®ãµã³ãã«ã以ä¸ã«ç¤ºãã¾ãã
desc "Mackerel integration test" namespace :deploy do desc "echo message" task :echo do on roles(:app) do |host| execute "echo \"Integration Test\" : #{host}" end end end
ãã®ã¿ã¹ã¯ãå®è¡ããã¨æ¬¡ã®ãããªçµæã¨ãªãã¾ãã
# bundle exec cap <environment> deploy:echo 00:00 deploy:echo 01 echo "Integration Test" : 127.0.0.1 01 Integration Test : 127.0.0.1 â 01 127.0.0.1 0.338s