Module: AwsReporting::Plan
- Defined in:
- lib/aws-reporting/plan.rb
Constant Summary collapse
- DEFAULT_STATISTICS =
['Maximum', 'Minimum', 'Average']
Class Method Summary collapse
- .build_template(yaml) ⇒ Object
- .create_plan(template, metrics) ⇒ Object
- .generate ⇒ Object
- .metrics_file_path ⇒ Object
- .to_array(yaml_array) ⇒ Object
Class Method Details
.build_template(yaml) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/aws-reporting/plan.rb', line 11 def self.build_template(yaml) template = Hash.new{|h, k| h[k] = {}} yaml.each{|d| template[d["namespace"]][d["metric_name"]] = to_array(d["statistics"]) } template end |
.create_plan(template, metrics) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/aws-reporting/plan.rb', line 21 def self.create_plan(template, metrics) plan = [] metrics.map{|m| namespace = m[:namespace] metric_name = m[:metric_name] dimensions = m[:dimensions] statiestics = nil if template[namespace][metric_name] statistics = template[namespace][metric_name] else $stderr.puts "Warning: Metric #{namespace} #{metric_name} is not defined. Default statistics are used." statistics = DEFAULT_STATISTICS end region = m[:region] {:namespace => namespace, :metric_name => metric_name, :dimensions => dimensions, :statistics => statistics, :region => region} } end |
.generate ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/aws-reporting/plan.rb', line 44 def self.generate() yaml = YAML.load(open(metrics_file_path()){|f| f.read }) template = build_template(yaml) metrics = [] AWS.regions.each{|r| AwsReporting::Config.update_region(r.name) AWS::CloudWatch::MetricCollection.new.each{|m| metrics << {:namespace => m.namespace, :metric_name => m.metric_name, :dimensions => m.dimensions, :region => r.name}} } plan = create_plan(template, metrics) end |
.metrics_file_path ⇒ Object
40 41 42 |
# File 'lib/aws-reporting/plan.rb', line 40 def self.metrics_file_path() File.('../../../metrics/metrics.yaml', __FILE__) end |
.to_array(yaml_array) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/aws-reporting/plan.rb', line 3 def self.to_array(yaml_array) array = [] yaml_array.each{|i| array << i.to_s } array end |