Class: Radiosonde::Client

Inherits:
Object
  • Object
show all
Includes:
Logger::Helper, Utils
Defined in:
lib/radiosonde/client.rb

Instance Method Summary collapse

Methods included from Utils

collect_to_hash, diff, #matched?

Methods included from Logger::Helper

#log

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



5
6
7
8
# File 'lib/radiosonde/client.rb', line 5

def initialize(options = {})
  @options = options
  @cloud_watch = AWS::CloudWatch.new
end

Instance Method Details

#apply(file) ⇒ Object



57
58
59
# File 'lib/radiosonde/client.rb', line 57

def apply(file)
  AWS.memoize { walk(file) }
end

#export(opts = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/radiosonde/client.rb', line 10

def export(opts = {})
  exported = nil

  AWS.memoize do
    exported = Radiosonde::Exporter.export(@cloud_watch, @options.merge(opts))
  end

  Radiosonde::DSL.convert(exported, @options.merge(opts))
end

#metrics(opts = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/radiosonde/client.rb', line 20

def metrics(opts = {})
  namespaces = {}

  AWS.memoize do
    ms = @cloud_watch.metrics

    [:namespace, :metric_name].each do |name|
      if (value = opts[name])
        ms = ms.filter(name.to_s, value)
      end
    end

    ms.sort_by {|m| [m.namespace, m.metric_name] }.each do |m|
      if opts[:with_statistics]
        namespaces[m.namespace] ||= {}
        statistics_ops = {}
        [:start_time, :end_time, :statistics].each do |name|
          statistics_ops[name] = opts[name] if opts[name]
        end
        statistics = m.statistics(statistics_ops)
        namespaces[m.namespace][m.metric_name] = {
          :label => statistics.label,
          :datapoints => statistics.datapoints
        }
      elsif opts[:with_dimensions]
        namespaces[m.namespace] ||= {}
        namespaces[m.namespace][m.metric_name] = m.dimensions
      else
        namespaces[m.namespace] ||= []
        namespaces[m.namespace] << m.metric_name
      end
    end
  end

  return namespaces
end