Module: InstStatsd::Distribution

Included in:
Statsd
Defined in:
lib/inst_statsd/distribution.rb

Overview

Mix-in methods for supporting DataDog events See docs.datadoghq.com/metrics/types/?tab=distribution#metric-types

Instance Method Summary collapse

Instance Method Details

#distributed_increment(metric, tags: {}) ⇒ Object

Increments the specified distribution metric by 1.

Examples:

Increment the error count:

InstStatsd::Statsd.distributed_increment('client.request.failed', tags: { status: '500' })

Parameters:

  • metric (String)

    The name of the metric to increment.

  • tags (Hash) (defaults to: {})

    Optional tags to associate with the metric.



31
32
33
34
35
36
# File 'lib/inst_statsd/distribution.rb', line 31

def distributed_increment(metric, tags: {})
  # Non-Datadog clients don't support distribution metrics, so we use fall back to increment
  return increment(metric, tags: tags) if instance && !data_dog?

  distribution(metric, 1, tags: tags)
end

#distribution(metric, value, tags: {}) ⇒ Object

Sends a distribution metric to DataDog if the instance and DataDog are configured.

Distributions are aggregated globally and are appropriate when a metric sourced from multiple hosts need to be considered in a global statistical distribution.

Examples:

Record an error occurrence:

InstStatsd::Statsd.distribution('client.request.failed', 1, tags: { status: '500' })

Parameters:

  • metric (String)

    The name of the metric to send.

  • value (Numeric)

    The value of the metric.

  • tags (Hash) (defaults to: {})

    Optional tags to associate with the metric. Defaults to an empty hash.



18
19
20
21
22
# File 'lib/inst_statsd/distribution.rb', line 18

def distribution(metric, value, tags: {})
  return unless instance && data_dog?

  instance.distribution(metric, value, { tags: tags.merge(dog_tags) }.compact)
end