class Cli

Public Instance Methods

start() click to toggle source
# 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
version() click to toggle source
# File lib/as-combined-metrics/cli.rb, line 87
def version
  say AsCombinedMetrics::ABOUT, color = :green
end