Class: Inventory::Cloudwatch

Inherits:
Base
  • Object
show all
Includes:
ActionView::Helpers::DateHelper
Defined in:
lib/inventory/cloudwatch.rb

Instance Method Summary collapse

Methods inherited from Base

eager_load!, inherited, #initialize, #report, #show, #sort, subclasses, #test_mode

Methods included from AwsServices

#acm, #cfn, #cw, #eb, #ec2, #ecs, #elbv1, #elbv2, #iam, #pricing, #rds, #route53

Methods included from Shared

#instances, #security_groups

Constructor Details

This class inherits a constructor from Inventory::Base

Instance Method Details

#alarmsObject



35
36
37
# File 'lib/inventory/cloudwatch.rb', line 35

def alarms
  @alarms ||= cw.describe_alarms.metric_alarms
end

#compare_mapObject



26
27
28
29
30
31
32
33
# File 'lib/inventory/cloudwatch.rb', line 26

def compare_map
  {
    "GreaterThanOrEqualToThreshold" => ">=",
    "GreaterThanThreshold" => ">",
    "LessThanOrEqualToThreshold" => "<=",
    "LessThanThreshold" => "<",
  }
end

#dataObject



10
11
12
13
14
15
16
17
# File 'lib/inventory/cloudwatch.rb', line 10

def data
  alarms.map do |alarm|
    [
      alarm.alarm_name,
      threshold_desc(alarm)
    ]
  end
end

#headerObject



6
7
8
# File 'lib/inventory/cloudwatch.rb', line 6

def header
  ["Alarm Name", "Threshold"]
end

#threshold_desc(alarm) ⇒ Object



19
20
21
22
23
24
# File 'lib/inventory/cloudwatch.rb', line 19

def threshold_desc(alarm)
  a = alarm
  total_period = a.period * a.evaluation_periods
  time_in_words = distance_of_time_in_words(total_period)
  "#{a.metric_name} #{compare_map[a.comparison_operator]} #{a.threshold} for #{a.evaluation_periods} datapoints within #{time_in_words}"
end