From 32d9ff45624f8382132d2ca24fbbb5357d66082b Mon Sep 17 00:00:00 2001 From: itsWill Date: Wed, 11 Feb 2026 02:35:00 -0500 Subject: [PATCH 1/2] don't hardcode localhost for event hostname --- config/test.exs | 1 + lib/instruments.ex | 6 +++++- pages/Configuration.md | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/config/test.exs b/config/test.exs index 0231c27..08193bd 100644 --- a/config/test.exs +++ b/config/test.exs @@ -3,6 +3,7 @@ use Mix.Config # setting the statsd port to something other than the default # in test so we don't conflict in the build env. config :instruments, + statsd_host: "localhost", statsd_port: 15310, fast_counter_report_interval: 10, fast_counter_report_jitter_range: 0..0, diff --git a/lib/instruments.ex b/lib/instruments.ex index 953d13a..271a781 100644 --- a/lib/instruments.ex +++ b/lib/instruments.ex @@ -58,6 +58,7 @@ defmodule Instruments do require Logger @metrics_module Application.get_env(:instruments, :reporter_module, Instruments.Statix) + @statsd_host Application.get_env(:instruments, :statsd_host, "localhost") @statsd_port Application.get_env(:instruments, :statsd_port, 8125) defmacro __using__(_opts) do @@ -66,6 +67,9 @@ defmodule Instruments do end end + @doc false + def statsd_host(), do: @statsd_host |> String.to_charlist() + @doc false def statsd_port(), do: @statsd_port @@ -203,7 +207,7 @@ defmodule Instruments do # this will have to be changed. unquote(@metrics_module) |> Process.whereis() - |> :gen_udp.send('localhost', Instruments.statsd_port(), message) + |> :gen_udp.send(Instruments.statsd_host(), Instruments.statsd_port(), message) end end diff --git a/pages/Configuration.md b/pages/Configuration.md index 7f7c28b..152b484 100644 --- a/pages/Configuration.md +++ b/pages/Configuration.md @@ -28,7 +28,9 @@ There are a couple of `Instruments` specific application variables: * `fast_counter_report_jitter_range`: How much random jitter should be applied to the reporting interval, in milliseconds. Defaults to half a second before and after the reporting interval. * `probe_prefix`: A global prefix to apply to all probes. -* `statsd_port`: The port that the statsd server listens on. Should be the same as the port in the statix +* `statsd_host`: The hostname of the statsd server. Defaults to `"localhost"`. Should be the same as the host + in the statix configuration above. +* `statsd_port`: The port that the statsd server listens on. Should be the same as the port in the statix configuration above. * `enable_sysmon`: Enables and registers `Instruments.Sysmon.Reporter` with `:erlang.system_monitor/1` to receive system monitor events. @@ -42,4 +44,5 @@ For example: fast_counter_report_interval: 30_000, fast_counter_report_jitter_range: -700..700, probe_prefix: "probes", + statsd_host: "localhost", statsd_port: 15339 From 526c0fcb016533febb7921f7e5eaa671490e9d49 Mon Sep 17 00:00:00 2001 From: itsWill Date: Wed, 11 Feb 2026 05:09:20 -0500 Subject: [PATCH 2/2] dont puts statsd_hostname as module attribute --- lib/instruments.ex | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/instruments.ex b/lib/instruments.ex index 271a781..efabbe7 100644 --- a/lib/instruments.ex +++ b/lib/instruments.ex @@ -58,7 +58,6 @@ defmodule Instruments do require Logger @metrics_module Application.get_env(:instruments, :reporter_module, Instruments.Statix) - @statsd_host Application.get_env(:instruments, :statsd_host, "localhost") @statsd_port Application.get_env(:instruments, :statsd_port, 8125) defmacro __using__(_opts) do @@ -68,7 +67,11 @@ defmodule Instruments do end @doc false - def statsd_host(), do: @statsd_host |> String.to_charlist() + def statsd_host do + :instruments + |> Application.get_env(:statsd_host, "localhost") + |> String.to_charlist() + end @doc false def statsd_port(), do: @statsd_port