Sha256: e216d634f88c4abbd7547cd936ddcea8b680ffc8935755db803e0b78d4b48fd4
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 KB
Contents
require "aws-sdk" module Sidewatch class Cloudwatch MAX_BATCH_SIZE = 20 attr_accessor :client def initialize(config = {}) client = config.delete(:client){ Aws::CloudWatch::Client } client = Object.const_get(client) if client.is_a?(String) client = client.new(config) if client.is_a?(Class) self.client = client end def send(metrics) metrics.group_by(&:namespace).each do |ns, ns_metrics| ns_metrics.each_slice(max_batch_size) do |slice| data = metric_data(ns, slice) client.put_metric_data(data) end end end private def max_batch_size MAX_BATCH_SIZE end def metric_data(ns, metrics) { namespace: ns, metric_data: metrics.map{|m| { metric_name: m.name, dimensions: Array(m.dimensions).map{|name, value| {name: name, value: value}}, timestamp: m.timestamp, value: m.value, unit: m.unit } } } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sidewatch-0.0.4 | lib/sidewatch/cloudwatch.rb |