diff --git a/.travis.yml b/.travis.yml index a4956eb..3a825b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ env: - REBAR_VSN=3 matrix: include: - - env: ELIXIR_VSN=1.2.0 REBAR_VSN= + - env: ELIXIR_VSN=1.3.2 REBAR_VSN= otp_release: 18.2 elixir: $ELIXIR_VSN before_install: diff --git a/README.md b/README.md index 8f25463..4480432 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,37 @@ [![Build Status](https://travis-ci.org/WhoopInc/dogstatsde.svg?branch=master)](https://travis-ci.org/WhoopInc/dogstatsde) +[![Hex.pm](https://img.shields.io/hexpm/v/dogstatsde.svg?maxAge=2592000)](https://hex.pm/packages/dogstatsde) -# A dogstatsd client for Erlang # +# A dogstatsd client for Erlang DogStatsD is Datadog's extension of StatsD. It adds tags to the metrics. -## Configure ## +## 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) | +| 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 ## +## Use -### Erlang ### +### Erlang 1. List dogstatsd in your `rebar.config` file ```erlang -{dogstatsd, "1.0.0", {pkg, dogstatsde}} +{dogstatsd, "", {pkg, dogstatsde}} ``` 2. List the dogstatsd application in your *.app.src file @@ -45,12 +46,12 @@ or in an Erlang config file in all_lowercase. dogstatsd:gauge("users.active", UserCount, #{ shard => ShardId, version => Vsn }) ``` -### Elixir ### +### Elixir 1. List dogstatsd dependency in your `mix.exs` file ```elixir -{:dogstatsd, "~> 1.0.0", hex: :dogstatsde} +{:dogstatsd, "~> ", hex: :dogstatsde} ``` 2. List `:dogstatsd` as an application in your `mix.exs` @@ -65,7 +66,7 @@ dogstatsd:gauge("users.active", UserCount, #{ shard => ShardId, version => Vsn } Dogstatsd.gauge("users.active", user_count, %{ :shard => shard_id, :version => vsn }) ``` -### VM Stats ### +### 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: @@ -92,7 +93,7 @@ If `VM_STATS` is not disabled, dogstatsd will periodically run `erlang:statistic ![screen-shot of VM stats in Datadog](img/erlang-vm-stats.jpg) -## Metric types ## +## Metric types All metrics share the same signature: diff --git a/mix.exs b/mix.exs index 5e18c4f..45e88ec 100644 --- a/mix.exs +++ b/mix.exs @@ -19,16 +19,19 @@ defmodule Dogstatsd do def project do [app: :dogstatsd, - version: "0.5.1", - elixir: "~> 1.2", + version: version(), + name: "Dogstatsd", + elixir: "~> 1.3", + source_url: "https://github.com/WhoopInc/dogstatsde", + docs: [ + extras: ["README.md"], + main: "README.md", + ], build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, deps: deps] end - # Configuration for the OTP application - # - # Type "mix help compile.app" for more information def application do [ applications: [:logger, :worker_pool, :stillir], @@ -36,21 +39,34 @@ defmodule Dogstatsd do ] end - # Dependencies can be Hex packages: - # - # {:mydep, "~> 0.3.0"} - # - # Or git/path repositories: - # - # {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"} - # - # Type "mix help deps" for more examples and options defp deps do [ {:stillir, "~> 1.0.0"}, - {:worker_pool, "~> 1.0.4"}, - {:meck, "~> 0.8.4"} # , only: :test} + {:worker_pool, "~> 2.1.0"}, + {:meck, "~> 0.8.4", only: :test} ] end + + def version do + # Fetch or fabricate a version number + {:ok, [{:application, :dogstatsd, appdata}]} = :file.consult("src/dogstatsd.app.src") + case appdata[:vsn] do + :git -> + # Fabricate a magic git version + last_vsn = case System.cmd("git", ["tag", "--sort=version:refname"]) do + {git_tags, 0} -> + git_tags |> String.trim |> String.split |> List.last + {_, 129} -> + {git_tags, 0} = System.cmd("git", ["tag"]) + git_tags |> String.trim |> String.split |> List.last + end + {git_hash,0} = System.cmd("git", ["rev-parse", "--short", "HEAD"]) + short_hash = git_hash |> String.trim + "#{last_vsn}+build-#{short_hash}" + real_vsn -> + # We get here when this is a downloaded Hex package + real_vsn + end + end end end diff --git a/rebar.config b/rebar.config index 67ed4e1..28546b3 100644 --- a/rebar.config +++ b/rebar.config @@ -1,7 +1,7 @@ %%% -*- mode: erlang; -*- {erl_opts, [debug_info]}. {deps, [ - {worker_pool, "1.0.4"} + {worker_pool, "2.1.0"} ,{stillir, "1.0.0"} ]}. @@ -9,7 +9,7 @@ [ {dev, [ {erl_opts, [{parse_transform, lager_transform}]} - ,{deps, [{lager, "2.1.1"}]} + ,{deps, [{lager, "3.2.1"}]} ,{shell, [ {config, "sys.conf"} ,{apps, [dogstatsd]} @@ -17,7 +17,7 @@ ]} ,{test, [ {deps, [ - {lager, "2.1.1"} + {lager, "3.2.1"} ,{meck, "0.8.4"} ]} ]} diff --git a/rebar.lock b/rebar.lock index 6bc0973..8859f54 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,2 +1,2 @@ [{<<"stillir">>,{pkg,<<"stillir">>,<<"1.0.0">>},0}, - {<<"worker_pool">>,{pkg,<<"worker_pool">>,<<"1.0.4">>},0}]. + {<<"worker_pool">>,{pkg,<<"worker_pool">>,<<"2.1.0">>},0}]. diff --git a/scripts/install-deps.bash b/scripts/install-deps.bash index 423bc84..b7276af 100755 --- a/scripts/install-deps.bash +++ b/scripts/install-deps.bash @@ -12,6 +12,7 @@ elif [ $REBAR_VSN -eq 3 ]; then elif [ $ELIXIR_VSN ]; then source $HOME/.kiex/elixirs/elixir-${ELIXIR_VSN}.env mix local.hex --force + mix local.rebar --force mix deps.get else echo Unknown rebar version requested: $REBAR_VSN