Build Status

A dogstatsd client for Erlang

DogStatsD is Datadog's extension of StatsD. It adds tags to the metrics.

Configure

The defaults assume that you're running a statsd server on localhost (true if the agent is installed locally).

There are a number of configuration settings. You can either provide them as environment variables in ALL_CAPS or in an Erlang config file in all_lowercase.

| name | type | default | info |
| ---- | ---- | ------- | ---- |
| AGENT_ADDRESS | string | `"localhost"` | Hostname or IP where we can send the StatsD UDP packets |
| AGENT_PORT | integer | `8125` | Port that the StatsD agent is listening on |
| GLOBAL_PREFIX | string | `""` | Prefix to attach before all metric names. The `.` will be inserted for you |
| GLOBAL_TAGS | map | `#{}` | Tags to attach to all metrics |
| SEND_METRICS | boolean | `true` | Set to `false` when you're running tests to disable sending any metrics |
| VM_STATS | boolean | `true` | Collect stats on the Erlang VM? |
| VM_STATS_DELAY | integer | `60000` | Time in ms between collection Erlang VM stats |
| VM_STATS_SCHEDULER | boolean | `true` | Collect stats on the scheduler? |
| VM_STATS_BASE_KEY | string | `"erlang.vm"` | All the VM stats will begin with this prefix (after the GLOBAL_PREFIX if that is set) |

Use

  1. List dogstatsd in your rebar.config file
{deps, [
{dogstatsd, {git, "https://github.com/WhoopInc/dogstatsde.git"}}
]}.
  1. List the dogstatsd application in your *.app.src file

  2. Provide configuration as needed when starting up

  3. For VM stats, no action is needed -- they'll collect on their own as long as the application is running

  4. For custom metrics:

dogstatsd:gauge("users.active", UserCount, #{ shard => ShardId, version > Vsn })

VM Stats

If VM_STATS is not disabled, dogstatsd will periodically run erlang:statistics/1 and friends and collect data on the VM's performance:

nameerlang callinfo
proc_counterlang:system_info(process_count)
proc_limiterlang:system_info(process_limit)
messages_in_queuesprocess_info(Pid, message_queue_len)over all PIDs
moduleslength(code:all_loaded())
run_queueerlang:statistics(run_queue)
error_logger_queue_lenprocess_info(Pid, message_queue_len)where Pid belongs to error_logger
memory.totalerlang:memory()
memory.procs_userderlang:memory()
memory.atom_usederlang:memory()
memory.binaryerlang:memory()
memory.etserlang:memory()
io.bytes_inerlang:statistics(io)
io.bytes_outerlang:statistics(io)
gc.counterlang:statistics(garbage_collection)
gc.words_reclaimederlang:statistics(words_reclaimed)
reductionserlang:statistics(reductions)
scheduler_wall_time.activeerlang:statistics(scheduler_wall_time)there are multiple schedulers, and the scheduler tag differentiates between them
scheduler_wall_time.totalerlang:statistics(scheduler_wall_time)there are multiple schedulers, and the scheduler tag differentiates between them

screen-shot of VM stats in Datadog

Metric types

All metrics share the same signature:

-type metric_name() :: iodata().
-type metric_value() :: number().
-type metric_sample_rate() :: number().
-type metric_tags() :: map().
-spec MetricFunction(metric_name(), metric_value(), metric_sample_rate(), metric_tags()) -> ok.

Metric name and value are required. Sample rate defaults to 1.0. Tags defaults to an empty tag-set, but the value of GLOBAL_TAGS (which also defaults to an empty tag-set) is always merged with the passed tags.