class CloudwatchToGraphite::LoadMetrics
Load metrics from a file and parse them into a CloudwatchToGraphite::MetricDefinition
object
Public Class Methods
from_json_file(filename)
click to toggle source
# File lib/cloudwatchtographite/loadmetrics.rb, line 23 def self.from_json_file(filename) if not File.readable?(filename) warn "Unable to read %s" % filename [] else File.open(filename, 'r') do |f| begin contents = JSON.load(f) load_content(contents) rescue Exception warn "Failed to parse %s" % filename [] end end end end
from_yaml_file(filename)
click to toggle source
# File lib/cloudwatchtographite/loadmetrics.rb, line 40 def self.from_yaml_file(filename) if not File.readable?(filename) warn "Unable to read %s" % filename [] else begin contents = YAML.load_file(filename) load_content(contents) rescue Exception warn "Failed to parse %s" % filename [] end end end
Private Class Methods
load_content(contents, strict=false)
click to toggle source
# File lib/cloudwatchtographite/loadmetrics.rb, line 56 def self.load_content(contents, strict=false) metrics = [] Validator::hash_with_key_of_type(contents,'metrics',Array) contents['metrics'].each do |m| parsed = MetricDefinition::create_and_fill m if (parsed != false) metrics.push(parsed) else warn "Failed to parse #{m}." end end metrics end