Class: AsCombinedMetrics::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/as-combined-metrics/cli.rb

Defined Under Namespace

Modules: Aws, CloudFormation, CloudWatch, Config, Logging, Poller, Stats, Utils

Instance Method Summary collapse

Instance Method Details

#startObject

Raises:

  • (Thor::RequiredArgumentMissingError)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/as-combined-metrics/cli.rb', line 33

def start
  %w(INT TERM USR1 USR2 TTIN).each do |sig|
    trap sig do
      puts "Got Singnal #{sig} Exiting..."
      exit 0
    end
  end

  raise Thor::RequiredArgumentMissingError, 'missing config file location [-f / --config-file]' if options[:config_file].nil?

  extend Logging
  extend Utils
  extend Config
  extend Stats
  extend Aws
  extend CloudFormation
  extend CloudWatch
  extend Poller

  logger.info { set_color "Dry Run - will not published metrics to CloudWatch", :yellow } if options[:dryrun]
  logger.info "Starting Combined Metrics on #{options[:region]} region"
  @region = options[:region]
  init_aws_sdk
  load_config
  poll(options[:interval])
  <<-INFO
      1) in this loop (poll) we overwrite a hash of combined metrics as follow:

         for every metric in the config file use fetch_metric(metric) to get it's current reading

         if metric has a key of aggregate_as_group,
            get all instances of the AutoScale group and for each instance fetch metric
            then push the result to an array, from that array get the average result and push it to the combined_metrics hash

         if one of the metrics fails to get datapoints (result => empty datapoints set) then set the result to -1
         the check_combined_metrics will see that the value is -1 and automatically false the result


      Combined metrics:
      { "CPUUtilization" => {"measure"=>7.08, "threshold"=>30, "comparison_operator"=>">="},
        "NetworkIn" => {"measure"=>43765341.0, "threshold"=>943718400, "comparison_operator"=>">="},
        "memory_usage.heapUsed.average"=>{"measure"=> 67844551, "threshold"=>600000, "comparison_operator"=>">="}
      }

      2) we then call check_combined_metrics to check if the measure is under or above the threshold and the result (true/false) to array

      3) if all elements of that array are true we set the value of self.combined_metric_value to 1 (Scale OK) else we set it to 0 (Do not Scale)

      4) last step -> publish that value to CloudWatch
  INFO
end

#versionObject



87
88
89
# File 'lib/as-combined-metrics/cli.rb', line 87

def version
  say AsCombinedMetrics::ABOUT, color = :green
end