as-combined-metrics 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87337b3355528621a41b176c53446558e81ed5b5
4
- data.tar.gz: a50a19f111920635d6a98c3533ec073af3cbc9cc
3
+ metadata.gz: 860f7bd0212371eb68b2b88c4848fbce9abb6b74
4
+ data.tar.gz: e3b13e84240628a148855adbfb3db42e71113015
5
5
  SHA512:
6
- metadata.gz: f5a47ede4391c655c1c96f2c3f70bb24df963794c55b99c4d4e7ae132aee9af3273b91d89c496cd25058a7236a77f323dc709d9114803440b0def6b69fd1be07
7
- data.tar.gz: a5c4cddc166fdcdcc264e2c41ccebae77342b81b0dbae4f628f2bd658d1f42582ea7d2867196005e845f134a780ba36cad1c781a8aadefdbf727104799385d49
6
+ metadata.gz: e60393b591a44e014bcae4516aa3c3f79de1c6e60d1369153fbef7eb7ed63a5be4505acf2a785979e27fff1790ac6831d5d4e5f77b586a2d0d4a46881bba9029
7
+ data.tar.gz: eb2e60d5c85f5d1ad9a5fbc627ed62e8acdee918437252e6943dc26064d891dbc50589df3c78e70b9fcf0285ee21e223afc38a079093ff06a74db61d751fc53f
@@ -5,7 +5,8 @@ cloudformation:
5
5
  logical_resource_ids:
6
6
  - CloudFormation_RESOURCE_ID
7
7
 
8
- autoscale_group_name: GROUP_NAME-X
8
+ autoscale_group_name:
9
+ - GROUP_NAME-X
9
10
 
10
11
  ScaleIn:
11
12
  - metric_name: CPUUtilization
@@ -1,5 +1,5 @@
1
1
  module AsCombinedMetrics
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  ABOUT = "as-combined-metrics v#{VERSION} (c) #{Time.now.strftime("2015-%Y")} @innovia"
4
4
 
5
5
  $:.unshift File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib]))
@@ -35,7 +35,7 @@ module AsCombinedMetrics::Cli::Aws
35
35
  logger.info { set_color "STACK_NAME was found in the config file #{@config[:cloudformation][:stack_name]}", :cyan }
36
36
  @stack_name = @config[:cloudformation][:stack_name]
37
37
  else
38
- logger.fatal { set_color "verify_stack_name_env Env variable STACK_NAME was not found or does not have a value, exiting now...", :red }
38
+ logger.fatal { set_color "verify_stack_name_env Can't find Env variable STACK_NAME or a setting (stack_name: STACK_NAME_X) in the config file , exiting now...", :red }
39
39
  exit 1
40
40
  end
41
41
  end
@@ -16,7 +16,8 @@ module AsCombinedMetrics::Cli::CloudFormation
16
16
 
17
17
  if !stack_info.nil?
18
18
  @autoscale_group_name = stack_info.stack_resource_detail.physical_resource_id
19
- @config["autoscale_group_name"] = @autoscale_group_name
19
+ @config[:autoscale_group_name] ||= []
20
+ @config[:autoscale_group_name] << @autoscale_group_name
20
21
  File.open(options[:config_file], "w") { |f| f.write(@config.to_yaml) }
21
22
  logger.info { set_color "AutoScale Group Name: #{@autoscale_group_name}", :cyan }
22
23
  end
@@ -27,7 +28,7 @@ module AsCombinedMetrics::Cli::CloudFormation
27
28
  end
28
29
 
29
30
  if @print_log
30
- logger.error { set_color "Unable to find the resource - #{e}", :yellow }
31
+ logger.error { set_color "Unable to find the resource - #{e}, maybe wrong region or wrong AWS account?", :yellow }
31
32
  logger.info { "Will retry every 5 seconds up to maximum of #{options[:timeout]} seconds" }
32
33
  end
33
34
 
@@ -42,7 +42,7 @@ module AsCombinedMetrics::Cli::CloudWatch
42
42
  end
43
43
  end
44
44
 
45
- def publish_metric(mode, combined_metric_value)
45
+ def publish_metric(mode, asg, combined_metric_value)
46
46
  logger.progname = "#{Module.nesting.first.to_s} #{__method__}"
47
47
 
48
48
  cw_options = {
@@ -51,7 +51,7 @@ module AsCombinedMetrics::Cli::CloudWatch
51
51
  metric_name: combined_metrics_name(mode),
52
52
  dimensions: [{
53
53
  name: 'AutoScalingGroupName',
54
- value: @config[:autoscale_group_name]
54
+ value: asg
55
55
  }],
56
56
  value: combined_metric_value,
57
57
  unit: 'None'
@@ -60,8 +60,12 @@ module AsCombinedMetrics::Cli::CloudWatch
60
60
  logger.info { set_color "Options to be sent to cloudwatch: #{cw_options}", :white }
61
61
 
62
62
  begin
63
- logger.info { set_color "Publishing Combined Metrics to CloudWatch...", :white }
64
- @cw.put_metric_data(cw_options)
63
+ if options[:dryrun]
64
+ logger.info { set_color "DryRun! Not Publishing Combined Metrics to CloudWatch...", :white }
65
+ else
66
+ logger.info { set_color "Publishing Combined Metrics to CloudWatch...", :white }
67
+ @cw.put_metric_data(cw_options)
68
+ end
65
69
  rescue Exception => e
66
70
  logger.error { set_color "An error occured #{e}, SDK will retry up to 3 times", :red }
67
71
  end
@@ -1,5 +1,4 @@
1
1
  require 'digest/sha1'
2
-
3
2
  class ConfigError < StandardError
4
3
  end
5
4
 
@@ -49,9 +48,8 @@ module AsCombinedMetrics::Cli::Config
49
48
 
50
49
  def process
51
50
  logger.progname = "#{Module.nesting.first.to_s} #{__method__}"
52
-
53
51
  if @config.has_key?(:autoscale_group_name)
54
- validate_as_group(@config[:autoscale_group_name])
52
+ @config[:autoscale_group_name].each {|g| validate_as_group(g)}
55
53
  elsif @config[:cloudformation][:enabled]
56
54
  verify_stack_name
57
55
 
@@ -13,31 +13,32 @@ module AsCombinedMetrics::Cli::Poller
13
13
 
14
14
  loop do
15
15
  modes.each do |mode|
16
- logger.info "Polling metrics for #{mode}"
17
-
18
- @config[mode].each do |metric|
19
- logger.debug "Getting stats for metric #{metric}"
20
- @combined_metrics[metric[:metric_name]] ||= {}
16
+ @config[:autoscale_group_name].each do |autoscale_group|
17
+ logger.info "Polling metrics for #{autoscale_group} AutoScale Group on #{mode}"
18
+ @config[mode].each do |metric|
19
+ logger.debug "Getting stats for #{autoscale_group} AutoScale Group on metric #{metric}"
20
+ @combined_metrics[metric[:metric_name]] ||= {}
21
21
 
22
- if metric.has_key?(:aggregate_as_group)
23
- logger.debug "Aggregating autoscale group metrics"
24
- @combined_metrics[metric[:metric_name]][:measure] = aggregate_instances_per_as_group(metric)
25
- else
26
- metric[:dimensions] = [{ name: "AutoScalingGroupName", value: @config[:autoscale_group_name]}]
27
- @combined_metrics[metric[:metric_name]][:measure] = fetch_metric(metric) unless @combined_metrics[metric[:metric_name]].has_key?(:measure)
28
- end
22
+ if metric.has_key?(:aggregate_as_group)
23
+ logger.debug "Aggregating autoscale group metrics"
24
+ @combined_metrics[metric[:metric_name]][:measure] = aggregate_instances_per_as_group(metric)
25
+ else
26
+ metric[:dimensions] = [{ name: "AutoScalingGroupName", value: autoscale_group}]
27
+ @combined_metrics[metric[:metric_name]][:measure] = fetch_metric(metric) unless @combined_metrics[metric[:metric_name]].has_key?(:measure)
28
+ end
29
29
 
30
- @combined_metrics[metric[:metric_name]][:threshold] = metric[:threshold]
31
- @combined_metrics[metric[:metric_name]][:comparison_operator] = metric[:comparison_operator]
32
- end
30
+ @combined_metrics[metric[:metric_name]][:threshold] = metric[:threshold]
31
+ @combined_metrics[metric[:metric_name]][:comparison_operator] = metric[:comparison_operator]
32
+ end
33
33
 
34
- logger.info { set_color "Combined metrics attributes for #{mode}: #{@combined_metrics}", :cyan }
35
- combined_metric_value = check_combined_metrics(mode)
34
+ logger.info { set_color "Combined metrics attributes for #{autoscale_group} AutoScale Group on #{mode}: #{@combined_metrics}", :cyan }
35
+ combined_metric_value = check_combined_metrics(mode)
36
36
 
37
- logger.info { set_color "Combined metrics value: #{combined_metric_value} => [0 = Do Not #{mode}, 1 = OK To #{mode}]" }
37
+ logger.info { set_color "Combined metrics value for #{autoscale_group} AutoScale Group: #{combined_metric_value} => [0 = Do Not #{mode}, 1 = OK To #{mode}]", :yellow, :bold }
38
38
 
39
- publish_metric(mode, combined_metric_value) unless options[:dryrun]
39
+ publish_metric(mode, autoscale_group, combined_metric_value)
40
40
  end
41
+ end
41
42
 
42
43
  if options[:once]
43
44
  logger.info { set_color "Ran Once - Exiting now..." }
@@ -31,7 +31,7 @@ module AsCombinedMetrics::Cli::Stats
31
31
  exit
32
32
  end
33
33
 
34
- logger.info { set_color "Combined results of #{results_array} for #{mode} is: #{combined_metric_value}", :yellow, :bold }
34
+ logger.info { set_color "Combined results of #{results_array} for #{mode} is: #{combined_metric_value}", :magenta }
35
35
 
36
36
  return combined_metric_value
37
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: as-combined-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ami Mahloof
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-14 00:00:00.000000000 Z
11
+ date: 2015-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor