Class: DatadogMetrics
- Inherits:
-
Object
- Object
- DatadogMetrics
- Defined in:
- lib/datadog_metrics.rb,
lib/datadog_metrics/version.rb
Overview
The default endpoint is the local dogstatsd agent which we can talk to using the ruby client:
github.com/DataDog/dogstatsd-ruby
In development we will pass an object that just logs what it would have reported to DataDog to the local log file, and in test we pass an object we can test with.
Constant Summary collapse
- VERSION =
"1.1.2"
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Class Method Summary collapse
Instance Method Summary collapse
- #batch ⇒ Object
- #count(metric, count, tags: {}) ⇒ Object
- #count_with_tags(metric, count, tags: {}) ⇒ Object
- #decrement(metric, tags: {}) ⇒ Object
- #event(metric, value, tags: {}) ⇒ Object
- #gauge(metric, value, tags = [], sample_rate = 1, **opts) ⇒ Object
- #histogram(metric, value, tags: {}) ⇒ Object
- #histogram_with_tags(metric, value, tags) ⇒ Object
- #increment(metric, tags: {}) ⇒ Object
- #increment_with_tags(metric, tags) ⇒ Object
-
#initialize(endpoint = Datadog::Statsd.new(ENV.fetch("STATS_HOST", "localhost"), 8125)) ⇒ DatadogMetrics
constructor
A new instance of DatadogMetrics.
- #time(stat, opt = {}, &block) ⇒ Object
- #timing(metric, ms, tags: {}) ⇒ Object
- #timing_with_tags(metric, ms, tags) ⇒ Object
Constructor Details
#initialize(endpoint = Datadog::Statsd.new(ENV.fetch("STATS_HOST", "localhost"), 8125)) ⇒ DatadogMetrics
Returns a new instance of DatadogMetrics.
27 28 29 |
# File 'lib/datadog_metrics.rb', line 27 def initialize(endpoint = Datadog::Statsd.new(ENV.fetch("STATS_HOST", "localhost"), 8125)) @endpoint = endpoint end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
25 26 27 |
# File 'lib/datadog_metrics.rb', line 25 def endpoint @endpoint end |
Class Method Details
.default_tags ⇒ Object
20 21 22 |
# File 'lib/datadog_metrics.rb', line 20 def @default_tags ||= {} end |
.default_tags=(tags) ⇒ Object
16 17 18 |
# File 'lib/datadog_metrics.rb', line 16 def () @default_tags = .transform_keys(&:to_s).freeze end |
Instance Method Details
#batch ⇒ Object
84 85 86 |
# File 'lib/datadog_metrics.rb', line 84 def batch @endpoint.batch(&proc { yield(endpoint)}) end |
#count(metric, count, tags: {}) ⇒ Object
51 52 53 |
# File 'lib/datadog_metrics.rb', line 51 def count(metric, count, tags: {}) @endpoint.count(metric, count, tags: ()) end |
#count_with_tags(metric, count, tags: {}) ⇒ Object
63 64 65 |
# File 'lib/datadog_metrics.rb', line 63 def (metric, count, tags: {}) @endpoint.count(metric, count, tags: ()) end |
#decrement(metric, tags: {}) ⇒ Object
47 48 49 |
# File 'lib/datadog_metrics.rb', line 47 def decrement(metric, tags: {}) @endpoint.decrement(metric, tags: ()) end |
#event(metric, value, tags: {}) ⇒ Object
80 81 82 |
# File 'lib/datadog_metrics.rb', line 80 def event(metric, value, tags: {}) @endpoint.event(metric, value, tags: ()) end |
#gauge(metric, value, tags = [], sample_rate = 1, **opts) ⇒ Object
67 68 69 70 |
# File 'lib/datadog_metrics.rb', line 67 def gauge(metric, value, =[], sample_rate=1, **opts) = opts[:tags] if opts.key?(:tags) @endpoint.gauge(metric, value, tags: (), sample_rate: sample_rate) end |
#histogram(metric, value, tags: {}) ⇒ Object
72 73 74 |
# File 'lib/datadog_metrics.rb', line 72 def histogram(metric, value, tags: {}) @endpoint.histogram(metric, value, tags: ()) end |
#histogram_with_tags(metric, value, tags) ⇒ Object
76 77 78 |
# File 'lib/datadog_metrics.rb', line 76 def (metric, value, ) @endpoint.histogram(metric, value, tags: ()) end |
#increment(metric, tags: {}) ⇒ Object
43 44 45 |
# File 'lib/datadog_metrics.rb', line 43 def increment(metric, tags: {}) @endpoint.increment(metric, tags: ()) end |
#increment_with_tags(metric, tags) ⇒ Object
59 60 61 |
# File 'lib/datadog_metrics.rb', line 59 def (metric, ) @endpoint.increment(metric, tags: ()) end |
#time(stat, opt = {}, &block) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/datadog_metrics.rb', line 31 def time(stat, opt={}, &block) opt[:tags] = (opt[:tags]) if opt.key?(:tags) @endpoint.time(stat, opt) do yield end end |
#timing(metric, ms, tags: {}) ⇒ Object
39 40 41 |
# File 'lib/datadog_metrics.rb', line 39 def timing(metric, ms, tags: {}) @endpoint.timing(metric, ms, tags: ()) end |
#timing_with_tags(metric, ms, tags) ⇒ Object
55 56 57 |
# File 'lib/datadog_metrics.rb', line 55 def (metric, ms, ) @endpoint.timing(metric, ms, tags: ()) end |