Sha256: 60a601bcaae46d3fd735bd5bedc71fd8a57a17b4f2176d212786668862ba8c31

Contents?: true

Size: 684 Bytes

Versions: 11

Compression:

Stored size: 684 Bytes

Contents

# frozen_string_literal: true

require 'dogapi'

module Providers
  class Datadog
    def initialize
      @pending = {}
      @metric_prefix = ENV['DATADOG_PREFIX'] || 'codemonitor.'
      @datadog_client = Dogapi::Client.new(ENV['DATADOG_API_KEY'])
    end

    def emit(metrics)
      @pending = pending.merge(metrics)
    end

    def send
      datadog_client.batch_metrics do
        pending.each do |metric, value|
          metric = "#{metric_prefix}#{metric}"
          puts "#{metric}: #{value}"
          datadog_client.emit_point(metric, value, type: 'gauge')
        end
      end
    end

    private

    attr_reader :pending, :metric_prefix, :datadog_client
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
codemonitor-0.6.4 providers/datadog.rb
codemonitor-0.6.3 providers/datadog.rb
codemonitor-0.6.2 providers/datadog.rb
codemonitor-0.6.1 providers/datadog.rb
codemonitor-0.6.0 providers/datadog.rb
codemonitor-0.5.0 providers/datadog.rb
codemonitor-0.4.0 providers/datadog.rb
codemonitor-0.3.6 providers/datadog.rb
codemonitor-0.3.5 providers/datadog.rb
codemonitor-0.3.4 providers/datadog.rb
codemonitor-0.3.3 providers/datadog.rb