Module: RubyAemAws::MetricVerifier
- Includes:
- AbstractCloudwatch, CloudwatchClient
- Included in:
- Component::AuthorDispatcher, Component::AuthorPrimary, Component::AuthorPublishDispatcher, Component::AuthorStandby, Component::ChaosMonkey, Component::Orchestrator, Component::Publish, Component::PublishDispatcher, Component::StackManagerResources, FullSetStack
- Defined in:
- lib/ruby_aem_aws/mixins/metric_verifier.rb
Overview
Mixin for checking that an instance has associated CloudWatch metrics.
Instance Method Summary collapse
-
#alarm?(alarm_name) ⇒ Boolean
True if Cloudwatch alarm exists.
-
#component_alarm?(alarm_name) ⇒ Boolean
True if Cloudwatch alarm exists for component.
-
#component_ec2_metric?(metric_name) ⇒ Boolean
True if Cloudwatch EC2 metric exists for all component instances.
-
#component_log_event?(log_stream_name, log_message) ⇒ Boolean
True if log message exists in Cloudwatch log stream for all component instances.
-
#component_log_stream?(log_stream_name) ⇒ Boolean
True if Cloudwatch log stream exists for all component instances.
-
#component_loggroup?(log_stream_name) ⇒ Boolean
True if Cloudwatch loggroup exists for component.
-
#component_metric?(namespace, metric_name) ⇒ Boolean
True if Cloudwatch metric exists for component.
-
#log_event?(loggroup_name, log_stream_name, log_message) ⇒ Boolean
True if Cloudwatch log event exists.
-
#log_stream?(loggroup_name, log_stream_name) ⇒ Boolean
True if Cloudwatch log stream exists.
-
#loggroup?(loggroup_name) ⇒ Boolean
True if Cloudwatch loggroup exists.
-
#metric?(namespace, metric_name, dimensions_name, dimensions_value) ⇒ Boolean
True if Cloudwatch metric exists.
Methods included from CloudwatchClient
#get_alarm, #get_log_event, #get_log_streams, #get_metrics
Instance Method Details
#alarm?(alarm_name) ⇒ Boolean
Returns True if Cloudwatch alarm exists.
123 124 125 126 127 |
# File 'lib/ruby_aem_aws/mixins/metric_verifier.rb', line 123 def alarm?(alarm_name) response = get_alarm(alarm_name) return true unless response.metric_alarms.empty? end |
#component_alarm?(alarm_name) ⇒ Boolean
Returns True if Cloudwatch alarm exists for component.
26 27 28 |
# File 'lib/ruby_aem_aws/mixins/metric_verifier.rb', line 26 def component_alarm?(alarm_name) alarm?(alarm_name) end |
#component_ec2_metric?(metric_name) ⇒ Boolean
Returns True if Cloudwatch EC2 metric exists for all component instances.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ruby_aem_aws/mixins/metric_verifier.rb', line 42 def component_ec2_metric?(metric_name) namespace = 'AWS/EC2' dimensions_name = 'InstanceId' instances_with_metric = [] instances = get_all_instances instances_found = instances.count instances.each do |instance| next if instance.nil? instance_id = instance.instance_id dimensions_value = instance.instance_id response = metric?(namespace, metric_name, dimensions_name, dimensions_value) instances_with_metric.push(instance_id) if response.eql? true end instances_with_metric = instances_with_metric.count return true unless instances_with_metric < instances_found end |
#component_log_event?(log_stream_name, log_message) ⇒ Boolean
Returns True if log message exists in Cloudwatch log stream for all component instances.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ruby_aem_aws/mixins/metric_verifier.rb', line 67 def component_log_event?(log_stream_name, ) instances_with_log_stream = [] loggroup_name = "#{@descriptor.stack_prefix_in}#{log_stream_name}" instances = get_all_instances instances_found = instances.count instances.each do |instance| next if instance.nil? instance_id = instance.instance_id log_stream_name = "#{@descriptor.ec2.component}/#{instance_id}" response = log_event?(loggroup_name, log_stream_name, ) instances_with_log_stream.push(instance_id) if response.eql? true end instances_with_log_stream = instances_with_log_stream.count return true unless instances_with_log_stream < instances_found end |
#component_log_stream?(log_stream_name) ⇒ Boolean
Returns True if Cloudwatch log stream exists for all component instances.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ruby_aem_aws/mixins/metric_verifier.rb', line 100 def component_log_stream?(log_stream_name) instances_with_log_stream = [] loggroup_name = "#{@descriptor.stack_prefix_in}#{log_stream_name}" instances = get_all_instances instances_found = instances.count instances.each do |instance| next if instance.nil? instance_id = instance.instance_id log_stream_name = "#{@descriptor.ec2.component}/#{instance_id}" response = log_stream?(loggroup_name, log_stream_name) instances_with_log_stream.push(instance_id) if response.eql? true end instances_with_log_stream = instances_with_log_stream.count return true unless instances_with_log_stream < instances_found end |
#component_loggroup?(log_stream_name) ⇒ Boolean
Returns True if Cloudwatch loggroup exists for component.
90 91 92 93 94 95 96 |
# File 'lib/ruby_aem_aws/mixins/metric_verifier.rb', line 90 def component_loggroup?(log_stream_name) loggroup_name = "#{@descriptor.stack_prefix_in}#{log_stream_name}" response = loggroup?(loggroup_name) return true if response.eql? true end |
#component_metric?(namespace, metric_name) ⇒ Boolean
Returns True if Cloudwatch metric exists for component.
33 34 35 36 37 38 |
# File 'lib/ruby_aem_aws/mixins/metric_verifier.rb', line 33 def component_metric?(namespace, metric_name) dimensions_name = 'FixedDimension' dimensions_value = "#{@descriptor.stack_prefix_in}-#{@descriptor.ec2.component}" response = metric?(namespace, metric_name, dimensions_name, dimensions_value) return true if response.eql? true end |
#log_event?(loggroup_name, log_stream_name, log_message) ⇒ Boolean
Returns True if Cloudwatch log event exists.
159 160 161 162 163 164 165 166 167 168 |
# File 'lib/ruby_aem_aws/mixins/metric_verifier.rb', line 159 def log_event?(loggroup_name, log_stream_name, ) response = loggroup?(loggroup_name) return false unless response.eql? true response = log_stream?(loggroup_name, log_stream_name) return false unless response.eql? true response = get_log_event(loggroup_name, log_stream_name, ) return true unless response.events.empty? end |
#log_stream?(loggroup_name, log_stream_name) ⇒ Boolean
Returns True if Cloudwatch log stream exists.
146 147 148 149 150 151 152 153 |
# File 'lib/ruby_aem_aws/mixins/metric_verifier.rb', line 146 def log_stream?(loggroup_name, log_stream_name) response = loggroup?(loggroup_name) return false unless response.eql? true response = get_log_streams(loggroup_name, log_stream_name) return true unless response.log_streams.empty? end |
#loggroup?(loggroup_name) ⇒ Boolean
Returns True if Cloudwatch loggroup exists.
172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/ruby_aem_aws/mixins/metric_verifier.rb', line 172 def loggroup?(loggroup_name) namespace = 'AWS/Logs' metric_name = 'IncomingLogEvents' dimensions_name = 'LogGroupName' dimensions_value = loggroup_name dimension_values = dimensions_value_filter_for_cloudwatch_metric(dimensions_name, dimensions_value) dimension_filter = dimensions_filter_for_cloudwatch_metric(dimension_values) response = get_metrics(namespace, metric_name, dimension_filter) return true unless response.metrics.empty? end |
#metric?(namespace, metric_name, dimensions_name, dimensions_value) ⇒ Boolean
Returns True if Cloudwatch metric exists.
134 135 136 137 138 139 140 141 |
# File 'lib/ruby_aem_aws/mixins/metric_verifier.rb', line 134 def metric?(namespace, metric_name, dimensions_name, dimensions_value) dimension_values = dimensions_value_filter_for_cloudwatch_metric(dimensions_name, dimensions_value) dimension_filter = dimensions_filter_for_cloudwatch_metric(dimension_values) response = get_metrics(namespace, metric_name, dimension_filter) return true unless response.metrics.empty? end |