Current section

Files

Jump to
new_relic_agent lib new_relic sampler agent.ex
Raw

lib/new_relic/sampler/agent.ex

defmodule NewRelic.Sampler.Agent do
use GenServer
# Takes samples of the state of the Agent
@moduledoc false
def start_link(_) do
GenServer.start_link(__MODULE__, :ok, name: __MODULE__)
end
def init(:ok) do
if NewRelic.Config.enabled?(),
do: Process.send_after(self(), :report, NewRelic.Sampler.Reporter.random_sample_offset())
{:ok, %{}}
end
def handle_info(:report, state) do
record_sample()
Process.send_after(self(), :report, NewRelic.Sampler.Reporter.sample_cycle())
{:noreply, state}
end
def handle_call(:report, _from, state) do
record_sample()
{:reply, :ok, state}
end
def record_sample do
NewRelic.report_metric(
{:supportability, :agent, "Sidecar/ActiveCount"},
value: NewRelic.Transaction.Sidecar.counter()
)
NewRelic.report_metric(
{:supportability, :agent, "ErlangTrace/Restarts"},
value: NewRelic.Transaction.ErlangTraceManager.restart_count()
)
end
end