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
Create Event.
- #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
- #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
rubocop:disable CyclomaticComplexity, PerceivedComplexity
33 34 35 36 37 38 39 |
# File 'lib/sapience/metrics/datadog.rb', line 33 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
91 92 93 |
# File 'lib/sapience/metrics/datadog.rb', line 91 def batch(&block) provider.batch(&block) end |
#count(metric, amount, options = {}) ⇒ Object
81 82 83 84 |
# File 'lib/sapience/metrics/datadog.rb', line 81 def count(metric, amount, = {}) return false unless valid? provider.count(metric, amount, ) end |
#decrement(metric, options = {}) ⇒ Object
66 67 68 69 |
# File 'lib/sapience/metrics/datadog.rb', line 66 def decrement(metric, = {}) return false unless valid? provider.decrement(metric, ) end |
#dog_options ⇒ Object
157 158 159 160 161 162 |
# File 'lib/sapience/metrics/datadog.rb', line 157 def { namespace: namespace, tags: @tags, } end |
#error(module_name, action, opts = {}) ⇒ Object
143 144 145 |
# File 'lib/sapience/metrics/datadog.rb', line 143 def error(module_name, action, opts = {}) increment("error", (module_name, action, opts)) end |
#event(title, text = "", opts = {}) ⇒ Object
Create Event
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/sapience/metrics/datadog.rb', line 122 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
147 148 149 |
# File 'lib/sapience/metrics/datadog.rb', line 147 def exception(module_name, action, opts = {}) increment("exception", (module_name, action, opts)) end |
#gauge(metric, amount, options = {}) ⇒ Object
76 77 78 79 |
# File 'lib/sapience/metrics/datadog.rb', line 76 def gauge(metric, amount, = {}) return false unless valid? provider.gauge(metric, amount, ) end |
#histogram(metric, amount, options = {}) ⇒ Object
71 72 73 74 |
# File 'lib/sapience/metrics/datadog.rb', line 71 def histogram(metric, amount, = {}) return false unless valid? provider.histogram(metric, amount, ) end |
#increment(metric, options = {}) ⇒ Object
61 62 63 64 |
# File 'lib/sapience/metrics/datadog.rb', line 61 def increment(metric, = {}) return false unless valid? provider.increment(metric, ) end |
#namespace ⇒ Object
151 152 153 154 155 |
# File 'lib/sapience/metrics/datadog.rb', line 151 def namespace ns = Sapience.namify(Sapience.app_name) ns += ".#{Sapience.namify(Sapience.environment)}" if Sapience.environment ns end |
#provider ⇒ Object
41 42 43 |
# File 'lib/sapience/metrics/datadog.rb', line 41 def provider @_provider ||= ::Datadog::Statsd.new(@uri.host, @uri.port, ) end |
#success(module_name, action, opts = {}) ⇒ Object
139 140 141 |
# File 'lib/sapience/metrics/datadog.rb', line 139 def success(module_name, action, opts = {}) increment("success", (module_name, action, opts)) end |
#time(metric, options = {}, &block) ⇒ Object
86 87 88 89 |
# File 'lib/sapience/metrics/datadog.rb', line 86 def time(metric, = {}, &block) return false unless valid? provider.time(metric, , &block) end |
#timing(metric, duration = 0, options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sapience/metrics/datadog.rb', line 49 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
45 46 47 |
# File 'lib/sapience/metrics/datadog.rb', line 45 def valid? @uri.scheme == "udp" end |