class Lita::Handlers::AwsCloudWatchHandler
Private Instance Methods
convert_datapoints(data, cal)
click to toggle source
# File lib/lita/handlers/aws-cloudwatch.rb, line 65 def convert_datapoints(data, cal) data['Datapoints'].map do |d| unit = unit_name(d['Unit']) value = convert_value(d['Unit'], d[cal]) [ d['Timestamp'], "#{value}#{unit}"] end.sort_by { |d| Time.parse(d[0]).to_i } end
convert_value(unit, value)
click to toggle source
# File lib/lita/handlers/aws-cloudwatch.rb, line 81 def convert_value(unit, value) case unit when 'Percent' then value.round(2) when 'Bytes' then (value / 1024 / 1024 / 1024).round(1) else value end end
get_options_for_cloudwatch(response, defaults = {})
click to toggle source
# File lib/lita/handlers/aws-cloudwatch.rb, line 45 def get_options_for_cloudwatch(response, defaults = {}) results = {} opts = get_options(response) defaults.each { |k, v| results[k] = (opts.delete(k) || v) } if results[:ago] results[:start_time] = (Time.now - (results[:ago].to_i) * (60 * 60 * 24)).utc.strftime("%Y-%m-%dT%H:00") results[:end_time] = Time.now.utc.strftime("%Y-%m-%dT%H:00") end results[:period] = results[:period].to_i if results[:period] results[:cmd_opts] = opts results end
render_cloudwatch_data(response, data, cal = 'Average')
click to toggle source
# File lib/lita/handlers/aws-cloudwatch.rb, line 60 def render_cloudwatch_data(response, data, cal = 'Average') data = convert_datapoints(data, cal) render(response, format_timeline(data)) end
unit_name(unit)
click to toggle source
# File lib/lita/handlers/aws-cloudwatch.rb, line 73 def unit_name(unit) case unit when 'Percent' then '%' when 'Bytes' then 'GB' else '' end end