Skip to content

Commit

Permalink
vm stats are coming through
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshull committed May 7, 2024
1 parent 2850372 commit 52587d5
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/dotcom/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ defmodule Dotcom.Application do

use Application

alias Telemetry.Metrics

# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
Expand All @@ -29,11 +27,12 @@ defmodule Dotcom.Application do
children =
[
{Application.get_env(:dotcom, :cache, Dotcom.Cache.Multilevel), []},
{DotcomWeb.Telemetry, []},
{Req.Telemetry, []}
] ++
if Application.get_env(:dotcom, :env) != :test do
[
# We can't run telemetry in the test environment because none of the levels are running
# We can't run cache telemetry in the test environment because none of the levels are running
{Dotcom.Cache.Telemetry, []},
# We don't need to run this cache because we are using the local cache for tests
{Dotcom.Cache.TripPlanFeedback.Cache, []}
Expand Down
Empty file removed lib/dotcom/stats.ex
Empty file.
38 changes: 38 additions & 0 deletions lib/dotcom/telemetry.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
defmodule Dotcom.Telemetry do
@moduledoc """
"""

use Supervisor

alias Telemetry.Metrics

def start_link(arg) do
Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
end

def init(_arg) do
telemetry_metrics_splunk_config = Application.get_env(:dotcom, :telemetry_metrics_splunk)

children = [
{
TelemetryMetricsSplunk,
[
metrics: metrics(),
token: telemetry_metrics_splunk_config[:token],
url: telemetry_metrics_splunk_config[:url]
]
}
]

Supervisor.init(children, strategy: :one_for_one)
end

defp metrics do
[
Metrics.last_value("vm.memory.total", unit: :byte),
Metrics.last_value("vm.total_run_queue_lengths.total"),
Metrics.last_value("vm.total_run_queue_lengths.cpu"),
Metrics.last_value("vm.system_counts.process_count")
]
end
end
14 changes: 14 additions & 0 deletions lib/dotcom_web/stats.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule DotcomWeb.Stats do
@moduledoc """
This Agent attaches to telemetry events emitted by Phoenix and aggregates them.
"""

use Agent

@doc """
Starts the Agent and attaches to `[:phoenix, ...]` telemetry events.
"""
def start_link(initial_value \\ %{}) do
Agent.start_link(fn -> initial_value end, name: __MODULE__)
end
end
40 changes: 40 additions & 0 deletions lib/dotcom_web/telemetry.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
defmodule DotcomWeb.Telemetry do
@moduledoc """
This module is responsible for starting the Telemetry poller and defining the metrics to be collected for Phoenix and the Erlang VM.
"""

use Supervisor

alias Telemetry.Metrics

def start_link(arg) do
Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
end

@impl true
def init(_arg) do
telemetry_metrics_splunk_config = Application.get_env(:dotcom, :telemetry_metrics_splunk)

children = [
{
TelemetryMetricsSplunk,
[
metrics: metrics(),
token: telemetry_metrics_splunk_config[:token],
url: telemetry_metrics_splunk_config[:url]
]
},
{DotcomWeb.Stats, %{}}
]

Supervisor.init(children, strategy: :one_for_one)
end

def measurements do
[]
end

def metrics do
[]
end
end
4 changes: 2 additions & 2 deletions lib/req/stats.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Req.Stats do
@moduledoc """
This Agent attaches to telemetry events emitted by Finch and aggregates them by path and status.
This Agent attaches to telemetry events emitted by Finch (used by Req) and aggregates them by host, path, and status.
"""

use Agent
Expand All @@ -15,7 +15,7 @@ defmodule Req.Stats do
end

@doc """
Handles telemetry events and aggregates them by path and status.
Handles telemetry events and aggregates them by host, path, and status.
"""
def handle_event(_name, measurement, metadata, _config) do
host = metadata.request.host
Expand Down

0 comments on commit 52587d5

Please sign in to comment.