Class: ClearSkies::AWS::CloudWatch::ELBGauge
- Inherits:
-
Gauge
- Object
- GreekFire::Gauge
- Gauge
- ClearSkies::AWS::CloudWatch::ELBGauge
show all
- Defined in:
- lib/clear_skies/aws/cloud_watch/elb_gauge.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Gauge
#aws_metrics, cloudwatch_client, #metrics, register
Constructor Details
#initialize(metric_name, dimension, statistics, description: nil, &block) ⇒ ELBGauge
Returns a new instance of ELBGauge.
9
10
11
|
# File 'lib/clear_skies/aws/cloud_watch/elb_gauge.rb', line 9
def initialize(metric_name, dimension, statistics, description: nil, &block)
super("AWS/ELB", metric_name, dimension, statistics, description: description, &block)
end
|
Class Method Details
.elb_client ⇒ Object
6
7
8
|
# File 'lib/clear_skies/aws/cloud_watch/elb_gauge.rb', line 6
def self.elb_client
@elb_client ||= Aws::ElasticLoadBalancing::Client.new
end
|
Instance Method Details
#labels_from_metric(metric) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/clear_skies/aws/cloud_watch/elb_gauge.rb', line 26
def labels_from_metric(metric)
labels = super(metric)
if labels.has_key?( "load_balancer_name") && !(Rails.cache.fetch("#{labels["load_balancer_name"]}_skip"))
labels["vpc_id"] = Rails.cache.fetch("#{labels["load_balancer_name"]}_vpc_id_") do
ELBGauge.elb_client.describe_load_balancers(load_balancer_names: [labels["load_balancer_name"]]).load_balancer_descriptions.first.vpc_id
end
labels.merge!(Rails.cache.fetch("#{labels["load_balancer_name"]}_tags_", expires_in: 1.hour, race_condition_ttl: 60.seconds) do
tags(labels["load_balancer_name"])
end)
end
labels
rescue Aws::ElasticLoadBalancing::Errors::LoadBalancerNotFound
Rails.cache.write("#{labels["load_balancer_name"]}_skip", true, expires_in: 1.hour, race_condition_ttl: 60.seconds)
return labels
end
|
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/clear_skies/aws/cloud_watch/elb_gauge.rb', line 13
def tags(load_balancer_name)
labels = {}
ELBGauge.elb_client.
describe_tags({load_balancer_names: [load_balancer_name]}).
tag_descriptions.
select {|doc| doc.load_balancer_name == load_balancer_name}.each do |tag_description|
tag_description.tags.each do |tag|
labels[tag.key.downcase] = tag.value
end
end
labels
end
|