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}'"
Instance Method Summary collapse
- #batch(&block) ⇒ Object
- #count(metric, amount, options = {}) ⇒ Object
- #decrement(metric, options = {}) ⇒ Object
- #dog_options ⇒ Object
- #error(module_name, action, opts = {}) ⇒ Object
-
#event(title, text = "", opts = {}) ⇒ Object
rubocop:disable CyclomaticComplexity, PerceivedComplexity.
- #exception(module_name, action, opts = {}) ⇒ Object
- #gauge(metric, amount, options = {}) ⇒ Object
- #histogram(metric, amount, options = {}) ⇒ Object
- #increment(metric, options = {}) ⇒ Object
-
#initialize(opts = {}) ⇒ Datadog
constructor
Create Appender.
- #namespace ⇒ Object
- #provider ⇒ Object
-
#success(module_name, action, opts = {}) ⇒ Object
rubocop:enable CyclomaticComplexity, PerceivedComplexity.
- #time(metric, options = {}, &block) ⇒ Object
- #timing(metric, duration = 0, options = {}) ⇒ Object
- #valid? ⇒ Boolean
Methods included from Descendants
Constructor Details
#initialize(opts = {}) ⇒ Datadog
Create Appender
Parameters:
level: :trace
url: [String]
Valid URL to postdogstatsd-ruby 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
32 33 34 35 36 37 38 |
# File 'lib/sapience/metrics/datadog.rb', line 32 def initialize(opts = {}) = opts.dup 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
90 91 92 |
# File 'lib/sapience/metrics/datadog.rb', line 90 def batch(&block) provider.batch(&block) end |
#count(metric, amount, options = {}) ⇒ Object
80 81 82 83 |
# File 'lib/sapience/metrics/datadog.rb', line 80 def count(metric, amount, = {}) return false unless valid? provider.count(metric, amount, ) end |
#decrement(metric, options = {}) ⇒ Object
65 66 67 68 |
# File 'lib/sapience/metrics/datadog.rb', line 65 def decrement(metric, = {}) return false unless valid? provider.decrement(metric, ) end |
#dog_options ⇒ Object
159 160 161 162 163 164 |
# File 'lib/sapience/metrics/datadog.rb', line 159 def { namespace: namespace, tags: @tags, } end |
#error(module_name, action, opts = {}) ⇒ Object
145 146 147 |
# File 'lib/sapience/metrics/datadog.rb', line 145 def error(module_name, action, opts = {}) increment("error", (module_name, action, opts)) end |
#event(title, text = "", opts = {}) ⇒ Object
rubocop:disable CyclomaticComplexity, PerceivedComplexity
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/sapience/metrics/datadog.rb', line 123 def event(title, text = "", opts = {}) return false unless valid? fail ArgumentError "Title must be provided" unless title opts ||= {} namespaced_keys = opts.delete(:namespaced_keys) || [] namespace_prefix = opts.delete(:namespace_prefix) || namespace if namespaced_keys.include?(:aggregation_key) aggregation_key = opts[:aggregation_key] || title opts[:aggregation_key] = "#{namespace_prefix}.#{aggregation_key}" end title = "#{namespace_prefix}.#{title}" if namespaced_keys.include?(:title) provider.event(title, text, opts) end |
#exception(module_name, action, opts = {}) ⇒ Object
149 150 151 |
# File 'lib/sapience/metrics/datadog.rb', line 149 def exception(module_name, action, opts = {}) increment("exception", (module_name, action, opts)) end |
#gauge(metric, amount, options = {}) ⇒ Object
75 76 77 78 |
# File 'lib/sapience/metrics/datadog.rb', line 75 def gauge(metric, amount, = {}) return false unless valid? provider.gauge(metric, amount, ) end |
#histogram(metric, amount, options = {}) ⇒ Object
70 71 72 73 |
# File 'lib/sapience/metrics/datadog.rb', line 70 def histogram(metric, amount, = {}) return false unless valid? provider.histogram(metric, amount, ) end |
#increment(metric, options = {}) ⇒ Object
60 61 62 63 |
# File 'lib/sapience/metrics/datadog.rb', line 60 def increment(metric, = {}) return false unless valid? provider.increment(metric, ) end |
#namespace ⇒ Object
153 154 155 156 157 |
# File 'lib/sapience/metrics/datadog.rb', line 153 def namespace ns = Sapience.namify(Sapience.app_name) ns += ".#{Sapience.namify(Sapience.environment)}" if Sapience.environment ns end |
#provider ⇒ Object
40 41 42 |
# File 'lib/sapience/metrics/datadog.rb', line 40 def provider @provider ||= ::Datadog::Statsd.new(@uri.host, @uri.port, ) end |
#success(module_name, action, opts = {}) ⇒ Object
rubocop:enable CyclomaticComplexity, PerceivedComplexity
141 142 143 |
# File 'lib/sapience/metrics/datadog.rb', line 141 def success(module_name, action, opts = {}) increment("success", (module_name, action, opts)) end |
#time(metric, options = {}, &block) ⇒ Object
85 86 87 88 |
# File 'lib/sapience/metrics/datadog.rb', line 85 def time(metric, = {}, &block) return false unless valid? provider.time(metric, , &block) end |
#timing(metric, duration = 0, options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sapience/metrics/datadog.rb', line 48 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
44 45 46 |
# File 'lib/sapience/metrics/datadog.rb', line 44 def valid? @uri.scheme == "udp" end |