Class: Yabeda::Cloudwatch::Adapter

Inherits:
BaseAdapter
  • Object
show all
Defined in:
lib/yabeda/cloudwatch/adapter.rb

Overview

Yabeda AWS Cloudwatch adapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection:) ⇒ Adapter

Returns a new instance of Adapter.



10
11
12
13
14
# File 'lib/yabeda/cloudwatch/adapter.rb', line 10

def initialize(connection:)
  super()

  @connection = connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



8
9
10
# File 'lib/yabeda/cloudwatch/adapter.rb', line 8

def connection
  @connection
end

Instance Method Details

#perform_counter_increment!(counter, tags, increment) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/yabeda/cloudwatch/adapter.rb', line 20

def perform_counter_increment!(counter, tags, increment)
  connection.put_metric_data(
    namespace: counter.group.to_s,
    metric_data: [
      {
        metric_name: counter.name.to_s,
        timestamp: Time.now,
        dimensions: tags.map { |tag_name, tag_value| { name: tag_name.to_s, value: tag_value } },
        unit: (counter.unit || :count).to_s.camelcase,
        value: increment,
      },
    ],
  )
end

#perform_gauge_set!(gauge, tags, value) ⇒ Object



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

def perform_gauge_set!(gauge, tags, value)
  connection.put_metric_data(
    namespace: gauge.group.to_s,
    metric_data: [
      {
        metric_name: gauge.name.to_s,
        timestamp: Time.now,
        dimensions: tags.map { |tag_name, tag_value| { name: tag_name.to_s, value: tag_value } },
        unit: (gauge.unit || :count).to_s.camelcase,
        value: value,
      },
    ],
  )
end

#perform_histogram_measure!(histogram, tags, value) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/yabeda/cloudwatch/adapter.rb', line 58

def perform_histogram_measure!(histogram, tags, value)
  connection.put_metric_data(
    namespace: histogram.group.to_s,
    metric_data: [
      {
        metric_name: histogram.name.to_s,
        timestamp: Time.now,
        dimensions: tags.map { |tag_name, tag_value| { name: tag_name.to_s, value: tag_value } },
        unit: (histogram.unit || :seconds).to_s.camelcase,
        value: value,
      },
    ],
  )
end

#register_counter!(counter) ⇒ Object



16
17
18
# File 'lib/yabeda/cloudwatch/adapter.rb', line 16

def register_counter!(counter)
  # We don't need to register metric
end

#register_gauge!(gauge) ⇒ Object



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

def register_gauge!(gauge)
  # We don't need to register metric
end

#register_histogram!(histogram) ⇒ Object



54
55
56
# File 'lib/yabeda/cloudwatch/adapter.rb', line 54

def register_histogram!(histogram)
  # We don't need to register metric
end