Class: Sapience::Metrics::Datadog
- Inherits:
-
Sapience::Metrics
- Object
- Sapience::Metrics
- Sapience::Metrics::Datadog
- Defined in:
- lib/sapience/metrics/datadog.rb
Constant Summary collapse
- VALIDATION_MESSAGE =
"Statsd only supports udp. Example: '#{Sapience::DEFAULT_STATSD_URL}'".freeze
Instance Method Summary collapse
- #batch(&block) ⇒ Object
- #count(metric, amount, options = {}) ⇒ Object
- #decrement(metric, options = {}) ⇒ Object
- #dog_options ⇒ Object
- #event(title, text, options = {}) ⇒ Object
- #gauge(metric, amount, options = {}) ⇒ Object
- #histogram(metric, amount, options = {}) ⇒ Object
- #increment(metric, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Datadog
constructor
Create Appender.
- #namespace ⇒ Object
- #provider ⇒ Object
- #time(metric, options = {}, &block) ⇒ Object
- #timing(metric, duration = 0, options = {}) ⇒ Object
- #valid? ⇒ Boolean
Methods included from Descendants
Constructor Details
#initialize(options = {}) ⇒ Datadog
Create Appender
Parameters:
level: :trace
url: [String]
Valid URL to post to.
Example:
udp://localhost:8125
Example, send all metrics to a particular namespace:
udp://localhost:8125/namespace
Default: udp://localhost:8125
tags: [String]
Example:
tag1:true
rubocop:disable AbcSize, CyclomaticComplexity, PerceivedComplexity
32 33 34 35 36 37 |
# File 'lib/sapience/metrics/datadog.rb', line 32 def initialize( = {}) fail("Options should be a Hash") unless .is_a?(Hash) url = .delete(:url) || Sapience::DEFAULT_STATSD_URL @tags = .delete(:tags) @uri = URI.parse(url) end |
Instance Method Details
#batch(&block) ⇒ Object
89 90 91 |
# File 'lib/sapience/metrics/datadog.rb', line 89 def batch(&block) provider.batch(&block) end |
#count(metric, amount, options = {}) ⇒ Object
79 80 81 82 |
# File 'lib/sapience/metrics/datadog.rb', line 79 def count(metric, amount, = {}) return false unless valid? provider.count(metric, amount, ) end |
#decrement(metric, options = {}) ⇒ Object
64 65 66 67 |
# File 'lib/sapience/metrics/datadog.rb', line 64 def decrement(metric, = {}) return false unless valid? provider.decrement(metric, ) end |
#dog_options ⇒ Object
104 105 106 107 108 109 |
# File 'lib/sapience/metrics/datadog.rb', line 104 def { namespace: namespace, tags: @tags, } end |
#event(title, text, options = {}) ⇒ Object
93 94 95 96 |
# File 'lib/sapience/metrics/datadog.rb', line 93 def event(title, text, = {}) return false unless valid? provider.event(title, text, ) end |
#gauge(metric, amount, options = {}) ⇒ Object
74 75 76 77 |
# File 'lib/sapience/metrics/datadog.rb', line 74 def gauge(metric, amount, = {}) return false unless valid? provider.gauge(metric, amount, ) end |
#histogram(metric, amount, options = {}) ⇒ Object
69 70 71 72 |
# File 'lib/sapience/metrics/datadog.rb', line 69 def histogram(metric, amount, = {}) return false unless valid? provider.histogram(metric, amount, ) end |
#increment(metric, options = {}) ⇒ Object
59 60 61 62 |
# File 'lib/sapience/metrics/datadog.rb', line 59 def increment(metric, = {}) return false unless valid? provider.increment(metric, ) end |
#namespace ⇒ Object
98 99 100 101 102 |
# File 'lib/sapience/metrics/datadog.rb', line 98 def namespace ns = Sapience.namify(Sapience.app_name) ns << ".#{Sapience.namify(Sapience.environment)}" if Sapience.environment ns end |
#provider ⇒ Object
39 40 41 |
# File 'lib/sapience/metrics/datadog.rb', line 39 def provider @_provider ||= ::Datadog::Statsd.new(@uri.host, @uri.port, ) end |
#time(metric, options = {}, &block) ⇒ Object
84 85 86 87 |
# File 'lib/sapience/metrics/datadog.rb', line 84 def time(metric, = {}, &block) return false unless valid? provider.time(metric, , &block) end |
#timing(metric, duration = 0, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sapience/metrics/datadog.rb', line 47 def timing(metric, duration = 0, = {}) if block_given? start = Time.now yield return false unless valid? provider.timing(metric, ((Time.now - start) * 1000).floor, ) else return false unless valid? provider.timing(metric, duration, ) end end |
#valid? ⇒ Boolean
43 44 45 |
# File 'lib/sapience/metrics/datadog.rb', line 43 def valid? @uri.scheme == "udp" end |