class CloudwatchToGraphite::MetricDefinition
A hashable representation of an AWS CloudWatch metric
Attributes
MetricName[R]
Namespace[R]
Period[R]
Statistics[R]
Unit[R]
Public Class Methods
create_and_fill(definition)
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 163 def self.create_and_fill(definition) md = MetricDefinition.new definition.each_key do |k| populate_metric_definition( md, k, definition[k] ) end raise ParseError unless md.valid? return md end
new()
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 71 def initialize @Unit = UNITS[0] @Dimensions = [] @Statistics = [] @Period = 60 end
populate_dimensions_from_hashes(md, dimensions)
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 199 def self.populate_dimensions_from_hashes(md, dimensions) Array(dimensions).each do |dimension| md.add_dimension(MetricDimension.create_from_hash(dimension)) end end
populate_metric_definition(md, key, value)
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 174 def self.populate_metric_definition(md, key, value) case key when 'namespace', 'metricname', 'period', 'unit' md.send(SETTER_MAPPINGS[key], value) when 'starttime', 'endtime' begin md.send(SETTER_MAPPINGS[key], Time.parse(value)) rescue ArgumentTypeError raise ParseError end when 'statistics' populate_statistics(md, value) when 'dimensions' populate_dimensions_from_hashes(md, value) else raise ParseError end end
populate_statistics(md, statistics)
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 193 def self.populate_statistics(md, statistics) Array(statistics).each do |stat| md.add_statistic(stat) end end
Public Instance Methods
Dimensions()
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 124 def Dimensions @Dimensions.map(&:to_h) end
EndTime()
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 106 def EndTime if @EndTime.nil? Time.now.iso8601 else @EndTime.iso8601 end end
EndTime=(time)
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 101 def EndTime=(time) raise ArgumentTypeError unless time.kind_of?(Time) @EndTime=time end
MetricName=(n)
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 83 def MetricName=(n) Validator::string_shorter_than(n, 256) @MetricName=n end
Namespace=(n)
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 78 def Namespace=(n) Validator::string_shorter_than(n, 256) @Namespace=n end
Period=(n)
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 114 def Period=(n) raise ArgumentTypeError unless n.kind_of? Integer @Period = n end
StartTime()
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 93 def StartTime if @StartTime.nil? (Time.now-600).iso8601 else @StartTime.iso8601 end end
StartTime=(time)
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 88 def StartTime=(time) raise ArgumentTypeError unless time.kind_of?(Time) @StartTime=time end
Unit=(n)
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 119 def Unit=(n) raise ArgumentTypeError unless UNITS.include? n @Unit = n end
add_dimension(n)
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 135 def add_dimension(n) if not n.kind_of?(MetricDimension) raise ArgumentTypeError elsif @Dimensions.length >= 10 raise TooManyDimensionError end @Dimensions.push(n) end
add_statistic(n)
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 128 def add_statistic(n) raise ArgumentTypeError unless STATISTICS.include? n if not @Statistics.include? n @Statistics.push(n) end end
graphite_path(stat)
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 153 def graphite_path(stat) path = "%s.%s.%s.%s" % [ self.Namespace, self.MetricName, stat, @Dimensions.join('.') ] path.gsub('/', '.').downcase end
valid?()
click to toggle source
# File lib/cloudwatchtographite/metricdefinition.rb, line 144 def valid? if @Namespace.nil? or @MetricName.nil? or @Statistics.empty? \ or @Dimensions.empty? or @Unit.nil? false else true end end