Sha256: 28d89b11b95a3923f667328f43094cbc9c3d5605085f825ade13f02fcb6b5c95

Contents?: true

Size: 899 Bytes

Versions: 2

Compression:

Stored size: 899 Bytes

Contents

require 'aws-sdk-cloudwatch'

class Cloudwatch
  NAMESPACE = 'Deployments'.freeze

  def initialize(context)
    @context = context
  end

  def put
    client.put_metric_data(
      namespace: NAMESPACE,
      metric_data: metric_data,
    )
  end

  private
  def metric_data
    [
      {
        metric_name: fetch(:application),
        timestamp: Time.now.utc,
        value: 1.0,
        dimensions: dimensions,
        unit: 'None',
        storage_resolution: 60,
      },
    ]
  end

  def dimensions
    dimensions = [
      {
        name: 'environment',
        value: fetch(:rails_env),
      },
    ]
    project = fetch(:project)
    dimensions.push({
      name: 'project',
      value: fetch(:project),
    }) if project
    dimensions
  end

  def client
    @client ||= ::Aws::CloudWatch::Client.new
  end

  def fetch(*args, &block)
    @context.fetch(*args, &block)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
capistrano-cloudwatch-1.0.1 lib/cloudwatch.rb
capistrano-cloudwatch-1.0.0 lib/cloudwatch.rb