Class: Deimos::Metrics::Datadog
- Defined in:
- lib/deimos/metrics/datadog.rb
Overview
A Metrics wrapper class for Datadog.
Instance Method Summary collapse
-
#gauge(metric_name, count, options = {}) ⇒ Object
:nodoc:.
-
#histogram(metric_name, count, options = {}) ⇒ Object
:nodoc:.
-
#increment(metric_name, options = {}) ⇒ Object
:nodoc:.
-
#initialize(config, logger) ⇒ Datadog
constructor
A new instance of Datadog.
- #setup_karafka(config = {}) ⇒ Object
- #setup_waterdrop(config) ⇒ Object
-
#time(metric_name, options = {}) ⇒ Object
:nodoc:.
Constructor Details
#initialize(config, logger) ⇒ Datadog
Returns a new instance of Datadog.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/deimos/metrics/datadog.rb', line 14 def initialize(config, logger) raise 'Metrics config must specify host_ip' if config[:host_ip].nil? raise 'Metrics config must specify host_port' if config[:host_port].nil? raise 'Metrics config must specify namespace' if config[:namespace].nil? logger.info("DatadogMetricsProvider configured with: #{config}") @client = ::Datadog::Statsd.new( config[:host_ip], config[:host_port], tags: config[:tags], namespace: config[:namespace] ) setup_karafka(config) setup_waterdrop(config) end |
Instance Method Details
#gauge(metric_name, count, options = {}) ⇒ Object
:nodoc:
70 71 72 |
# File 'lib/deimos/metrics/datadog.rb', line 70 def gauge(metric_name, count, ={}) @client.gauge(metric_name, count, ) end |
#histogram(metric_name, count, options = {}) ⇒ Object
:nodoc:
75 76 77 |
# File 'lib/deimos/metrics/datadog.rb', line 75 def histogram(metric_name, count, ={}) @client.histogram(metric_name, count, ) end |
#increment(metric_name, options = {}) ⇒ Object
:nodoc:
65 66 67 |
# File 'lib/deimos/metrics/datadog.rb', line 65 def increment(metric_name, ={}) @client.increment(metric_name, ) end |
#setup_karafka(config = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/deimos/metrics/datadog.rb', line 31 def setup_karafka(config={}) karafka_listener = ::Karafka::Instrumentation::Vendors::Datadog::MetricsListener.new do |karafka_config| karafka_config.client = @client if config[:karafka_namespace] karafka_config.namespace = config[:karafka_namespace] end if config[:karafka_distribution_mode] karafka_config.distribution_mode = config[:karafka_distribution_mode] end if config[:rd_kafka_metrics] karafka_config.rd_kafka_metrics = config[:rd_kafka_metrics] end end Karafka.monitor.subscribe(karafka_listener) end |
#setup_waterdrop(config) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/deimos/metrics/datadog.rb', line 47 def setup_waterdrop(config) waterdrop_listener = ::WaterDrop::Instrumentation::Vendors::Datadog::MetricsListener.new do |waterdrop_config| waterdrop_config.client = @client if config[:karafka_namespace] waterdrop_config.namespace = config[:karafka_namespace] end if config[:karafka_distribution_mode] waterdrop_config.distribution_mode = config[:karafka_distribution_mode] end if config[:rd_kafka_metrics] karafka_config.rd_kafka_metrics = [] # handled in Karafka end end Karafka::Setup::Config.setup if Karafka.producer.nil? Karafka.producer.monitor.subscribe(waterdrop_listener) end |
#time(metric_name, options = {}) ⇒ Object
:nodoc:
80 81 82 83 84 |
# File 'lib/deimos/metrics/datadog.rb', line 80 def time(metric_name, ={}) @client.time(metric_name, ) do yield end end |