Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Get rid of Java and Cloudwatch API tools...

Use right_aws for creating alarms too.
  • Loading branch information...
commit d0415427fb30a3fbcdbfde1541868e2b1b83324e 1 parent 41f1a8b
@samstokes samstokes authored
View
2  Gemfile
@@ -1,4 +1,4 @@
source 'http://rubygems.org'
gem 'thor'
gem 'open4'
-gem 'right_aws'
+gem 'right_aws', '~> 2.2.2', :git => 'git://github.com/rapportive-oss/right_aws.git'
View
11 Gemfile.lock
@@ -1,9 +1,14 @@
+GIT
+ remote: git://github.com/rapportive-oss/right_aws.git
+ revision: 6b3ead71d1424da196eb5f251b49489541295264
+ specs:
+ right_aws (2.2.2)
+ right_http_connection (>= 1.2.5)
+
GEM
remote: http://rubygems.org/
specs:
open4 (1.0.1)
- right_aws (2.1.0)
- right_http_connection (>= 1.2.5)
right_http_connection (1.3.0)
thor (0.14.6)
@@ -12,5 +17,5 @@ PLATFORMS
DEPENDENCIES
open4
- right_aws
+ right_aws (~> 2.2.2)!
thor
View
9 bin/rediscator
@@ -24,10 +24,13 @@ RUBY=$(which ruby)
BUNDLE=$(which bundle)
[ $? = 0 ] || { echo "Bundler is missing! Run '$0 --setup-ruby'." >&2; exit 3; }
-pushd "$(dirname $0)/.." && "$BUNDLE" install --quiet; popd
+sudo apt-get install -y git-core # for gems
-exec "$RUBY" \
+export BUNDLE_GEMFILE="$(dirname $0)/../Gemfile"
+"$BUNDLE" install --quiet
+
+exec "$BUNDLE" exec "$RUBY" \
-rubygems \
-I"$(dirname $0)/../lib" \
- -e 'require "bundler/setup"; require "rediscator"; $0 = "rediscator"; Rediscator::App.start' \
+ -e 'require "rediscator"; $0 = "rediscator"; Rediscator::App.start' \
"$@"
View
69 lib/rediscator/app.rb
@@ -19,21 +19,15 @@ class App < Thor
build-essential
pwgen
s3cmd
- openjdk-6-jre-headless
- unzip
postfix
heirloom-mailx
git-core
)
- OPENJDK_JAVA_HOME = '/usr/lib/jvm/java-6-openjdk'
-
REDIS_USER = 'redis'
REDIS_LOG = '/var/log/redis.log'
CLOUDWATCH_USER = 'cloudwatch'
- CLOUDWATCH_TOOLS_ZIP = 'CloudWatch-2010-08-01.zip'
- CLOUDWATCH_TOOLS_URL = "http://ec2-downloads.s3.amazonaws.com/#{CLOUDWATCH_TOOLS_ZIP}"
RIGHT_AWS_REPO = 'git://github.com/rapportive-oss/right_aws.git'
@@ -125,7 +119,7 @@ def setup
props[:CLOUDWATCH_USER] = CLOUDWATCH_USER
create_user props[:CLOUDWATCH_USER], :description => 'Amazon Cloudwatch monitor'
- install_cloudwatch_tools :cloudwatch_access_key_id => aws_access_key, :cloudwatch_secret_key => aws_secret_key
+ install_cloudwatch_gems :cloudwatch_access_key_id => aws_access_key, :cloudwatch_secret_key => aws_secret_key
setup_monitors_and_alarms :cloudwatch_namespace => options[:cloudwatch_namespace],
:cloudwatch_access_key_id => aws_access_key,
@@ -403,7 +397,7 @@ def setup_redis_backups(opts)
end
- def install_cloudwatch_tools(opts)
+ def install_cloudwatch_gems(opts)
cloudwatch_access_key_id = opts[:cloudwatch_access_key_id] or raise ArgumentError, 'must specify :cloudwatch_access_key_id'
cloudwatch_secret_key = opts[:cloudwatch_secret_key] or raise ArgumentError, 'must specify :cloudwatch_secret_key'
@@ -416,48 +410,11 @@ def install_cloudwatch_tools(opts)
GEMFILE
run! *%w(bundle install)
- run! *%w(mkdir -p opt)
- inside 'opt' do
- if Dir.glob('CloudWatch-*/bin/mon-put-data').empty?
- run! :wget, '-q', CLOUDWATCH_TOOLS_URL unless File.exists? CLOUDWATCH_TOOLS_ZIP
- run! :unzip, CLOUDWATCH_TOOLS_ZIP
- end
- cloudwatch_dirs = Dir.glob('CloudWatch-*').select {|dir| File.directory? dir }
- case cloudwatch_dirs.size
- when 1; cloudwatch_dir = cloudwatch_dirs[0]
- when 0; raise 'Failed to install CloudWatch tools!'
- else; raise 'Multiple versions of CloudWatch tools installed; confused.'
- end
-
- props[:CLOUDWATCH_TOOLS_PATH] = "#{Dir.pwd}/#{cloudwatch_dir}"
- end
-
props[:CLOUDWATCH_AWS_CREDENTIALS_PATH] = "#{Dir.pwd}/.aws-credentials"
create_file! props[:CLOUDWATCH_AWS_CREDENTIALS_PATH], <<-CREDS, :permissions => '600'
AWSAccessKeyId=#{cloudwatch_access_key_id}
AWSSecretKey=#{cloudwatch_secret_key}
CREDS
-
- run! *%w(mkdir -p bin)
-
- env_vars = [
- [:JAVA_HOME, OPENJDK_JAVA_HOME],
- [:AWS_CLOUDWATCH_HOME, props[:CLOUDWATCH_TOOLS_PATH]],
- [:PATH, %w($PATH $AWS_CLOUDWATCH_HOME/bin).join(':')],
- [:AWS_CREDENTIAL_FILE, props[:CLOUDWATCH_AWS_CREDENTIALS_PATH]],
- ]
- env_vars_script = (%w(#!/bin/sh) + env_vars.map do |var, value|
- "#{var}=#{value}; export #{var}"
- end).join("\n")
- props[:CLOUDWATCH_ENV] = env_vars.map do |var, value|
- # run! doesn't expand $SHELL_VARIABLES, so we have to do it.
- expanded = value.
- gsub('$PATH', ENV['PATH']).
- gsub('$AWS_CLOUDWATCH_HOME', props[:CLOUDWATCH_TOOLS_PATH])
- [var, expanded]
- end
-
- create_file! 'bin/aws-cloudwatch-env-vars.sh', env_vars_script, :permissions => '+rwx'
end
end
end
@@ -525,21 +482,18 @@ def system!(*args)
instance_id = system!(*%w(curl -s http://169.254.169.254/latest/meta-data/instance-id)).strip
custom_metric_dimensions[:InstanceId] = builtin_metric_dimensions[:InstanceId] = instance_id
end
- props[:CLOUDWATCH_DIMENSIONS] = cloudwatch_dimensions(custom_metric_dimensions)
- shared_alarm_options = {
- :cloudwatch_tools_path => props[:CLOUDWATCH_TOOLS_PATH],
- :env_vars => props[:CLOUDWATCH_ENV],
+ acw = RightAws::AcwInterface.new(cloudwatch_access_key_id, cloudwatch_secret_key)
+ shared_alarm_options = {
:dimensions => custom_metric_dimensions,
+ :period => 60,
+ :evaluation_periods => 5,
}
if topic
props[:SNS_TOPIC] = topic
shared_alarm_options.merge!({
- :actions_enabled => true,
- :ok_actions => topic,
- :alarm_actions => topic,
- :insufficient_data_actions => topic,
+ :actions => {:ok => topic, :alarm => topic, :insufficient_data => topic},
})
else
props[:SNS_TOPIC] = "<WARNING: No SNS topic specified. You will not get notified of alarm states.>"
@@ -594,19 +548,18 @@ def system!(*args)
when :<, :<=; 'low'
end
alarm_options = shared_alarm_options.merge({
- :alarm_name => "#{props[:MACHINE_NAME]}: #{friendly}",
- :alarm_description => "Alerts if #{props[:MACHINE_ROLE]} machine #{props[:MACHINE_NAME]} has #{symptom} #{friendly}.",
+ :description => "Alerts if #{props[:MACHINE_ROLE]} machine #{props[:MACHINE_NAME]} has #{symptom} #{friendly}.",
:namespace => namespace,
:metric_name => metric,
:dimensions => dimensions,
- :comparison_operator => comparison,
- :threshold => threshold,
:unit => unit,
})
- setup_cloudwatch_alarm! alarm_options
+ acw.put_metric_alarm "#{props[:MACHINE_NAME]}: #{friendly}",
+ comparison, threshold,
+ alarm_options
end
end
View
32 lib/rediscator/util.rb
@@ -180,37 +180,5 @@ def assert_valid_keys!(opts, *keys)
invalid_opts = opts.keys - keys
raise ArgumentError, "unknown options: #{invalid_opts.map(&:inspect).join(' ')}", caller unless invalid_opts.empty?
end
-
- def setup_cloudwatch_alarm!(options = {})
- cloudwatch_tools_path = options.delete(:cloudwatch_tools_path) or raise ArgumentError, 'must specify :cloudwatch_tools_path'
- env_vars = options.delete(:env_vars) || []
- env_vars_for_env = env_vars.map {|var, value| "#{var}=#{value}" }
-
- options[:comparison_operator] = case options[:comparison_operator]
- when :>; :GreaterThanThreshold
- when :>=; :GreaterThanOrEqualToThreshold
- when :<; :LessThanThreshold
- when :<=; :LessThanOrEqualToThreshold
- else options[:comparison_operator]
- end
- options[:dimensions] = cloudwatch_dimensions(options[:dimensions])
-
- options = {
- :statistic => :Average,
- :comparison_operator => :LessThanThreshold,
- :period => 60,
- :evaluation_periods => 5,
- }.merge(options)
-
- alarm_options = options.map do |key, value|
- ["--" + key.to_s.gsub('_', '-'), value.to_s]
- end.flatten
-
- run! :env, *(env_vars_for_env + %W(#{cloudwatch_tools_path}/bin/mon-put-metric-alarm) + alarm_options)
- end
-
- def cloudwatch_dimensions(dimensions)
- dimensions.map {|k, v| "#{k}=#{v}" }.join(',') if dimensions
- end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.