Module: ElasticDynamoDb::Cli::CloudWatch

Included in:
ElasticDynamoDb::Cli
Defined in:
lib/elasticDynamoDb/cloudwatch.rb

Instance Method Summary collapse

Instance Method Details

#put_metric_alarm(table_options, mode, threshold, arn) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/elasticDynamoDb/cloudwatch.rb', line 13

def put_metric_alarm(table_options, mode, threshold, arn)
  cw_options = {
    alarm_name: "#{table_options[:table_name]}-#{mode.capitalize}CapacityUnitsLimit-BasicAlarm",
    alarm_description: "Consumed#{mode.capitalize}Capacity",
    actions_enabled: true,
    ok_actions: [arn],
    alarm_actions: [arn],
    metric_name: "Consumed#{mode.capitalize}CapacityUnits",
    namespace: "AWS/DynamoDB",
    statistic: "Sum",
    dimensions: [
      {
        name: "TableName",
        value: table_options[:table_name]
      }
    ],
    period: 300,
    unit: "Count",
    threshold: threshold,
    evaluation_periods: 1,
    comparison_operator: "GreaterThanOrEqualToThreshold"
  }
  self.cw.put_metric_alarm(cw_options)
end

#set_cloudwatch_alarms(table_options) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/elasticDynamoDb/cloudwatch.rb', line 38

def set_cloudwatch_alarms(table_options)
  arn = set_default_options(table_options, :sns_topic_arn)   
  reads_upper_alarm_threshold = set_default_options(table_options, :reads_upper_alarm_threshold)      
  writes_upper_alarm_threshold = set_default_options(table_options, :writes_upper_alarm_threshold)

	say  "Setting CloudWatch alarms thresholds for #{table_options[:table_name]} with upper read threshold of #{reads_upper_alarm_threshold}% and upper writes of #{writes_upper_alarm_threshold}%", color = :magenta
  
  if !arn.nil? && !reads_upper_alarm_threshold.nil? && !writes_upper_alarm_threshold.nil?
    put_metric_alarm(table_options, 'read', (table_options[:provisioned_throughput][:read_capacity_units] * 300) * reads_upper_alarm_threshold.to_i/100, arn)
    put_metric_alarm(table_options, 'write', (table_options[:provisioned_throughput][:write_capacity_units] * 300) * writes_upper_alarm_threshold.to_i/100, arn)
	else
    say "unable to find sns topic in config file - skipping cloudwatch alerts", color = :yellow
  end
end

#set_default_options(hash, member) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/elasticDynamoDb/cloudwatch.rb', line 5

def set_default_options(hash, member)
  if hash[member] && !hash[member].nil?
    default = hash[member]
  else
    default =  self.config["default_options"][member.to_s.gsub("_", "-")] if !self.config["default_options"][member.to_s.gsub("_", "-")].nil?
  end
end