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: {}, short_stat: nil) ⇒ 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.

  • short_stat (String, nil) (defaults to: nil)

    Stat name to use instead of metric if backed by DataDog.



35
36
37
38
39
40
41
42
43
# File 'lib/inst_statsd/distribution.rb', line 35

def distributed_increment(metric, tags: {}, short_stat: nil)
  metric = stat_name_for(metric)
  tags = prepare_datadog_tags(tags) if data_dog?

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

  distribution(short_stat || 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
23
24
25
# File 'lib/inst_statsd/distribution.rb', line 18

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

  metric = stat_name_for(metric)
  tags = prepare_datadog_tags(tags) if data_dog?

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