Skip to content

Commit

Permalink
trying out metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshull committed May 6, 2024
1 parent 20913d5 commit 7910382
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
4 changes: 4 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ config :dotcom, :mbta_api,
{"x-enable-experimental-features", "true"}
]

config :dotcom, :telemetry_metrics_splunk,
token: System.get_env("TELEMETRY_METRICS_SPLUNK_TOKEN"),
url: "https://mbta.splunkcloud.com:8088/services/collector"

config :dotcom, aws_index_prefix: System.get_env("AWS_PLACE_INDEX_PREFIX") || "dotcom-dev"

if config_env() != :test do
Expand Down
23 changes: 22 additions & 1 deletion lib/dotcom/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ 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
telemetry_metrics_splunk_config = Application.get_env(:dotcom, :telemetry_metrics_splunk)

Application.put_env(
:dotcom,
:allow_indexing,
Expand All @@ -26,7 +30,24 @@ defmodule Dotcom.Application do

children =
[
{Application.get_env(:dotcom, :cache, Dotcom.Cache.Multilevel), []}
{Application.get_env(:dotcom, :cache, Dotcom.Cache.Multilevel), []},
{
TelemetryMetricsSplunk,
[
metrics: [Metrics.last_value("mbta_api.request")],
token: telemetry_metrics_splunk_config[:token],
url: telemetry_metrics_splunk_config[:url]
]
},
{MBTA.Api.Stats, %{}},
{
:telemetry_poller,
measurements: [
{MBTA.Api.Stats, :dispatch_stats, []}
],
period: :timer.seconds(60),
init_delay: :timer.seconds(15)
}
] ++
if Application.get_env(:dotcom, :env) != :test do
[
Expand Down
5 changes: 4 additions & 1 deletion lib/dotcom/cache/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ defmodule Dotcom.Cache.Telemetry do

def init(_arg) do
children = [
{:telemetry_poller, measurements: periodic_measurements(), period: 60_000},
{
:telemetry_poller,
measurements: periodic_measurements(), period: 60_000, init_delay: 5_000
},
{Dotcom.Cache.Telemetry.Reporter, metrics: reporter_metrics()},
{TelemetryMetricsStatsd, metrics: statsd_metrics()}
]
Expand Down
3 changes: 2 additions & 1 deletion lib/mbta/api/stats.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ defmodule MBTA.Api.Stats do
durations
|> Enum.sum()
|> Kernel.div(count)
|> System.convert_time_unit(:native, :millisecond)

:telemetry.execute([:mbta_api, :request], %{count: count, avg: avg}, %{
:telemetry.execute([:mbta_api], %{request: %{count: count, avg: avg}}, %{
path: path,
status: status
})
Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ defmodule DotCom.Mixfile do
{:sweet_xml, "0.7.4", only: [:prod, :dev]},
{:telemetry, "1.2.1", override: true},
{:telemetry_metrics, "1.0.0", override: true},
{:telemetry_metrics_splunk, "0.0.1-alpha"},
{:telemetry_metrics_statsd, "0.7.0"},
{:telemetry_poller, "1.1.0"},
{:telemetry_test, "0.1.2", only: [:test]},
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"sweet_xml": {:hex, :sweet_xml, "0.7.4", "a8b7e1ce7ecd775c7e8a65d501bc2cd933bff3a9c41ab763f5105688ef485d08", [:mix], [], "hexpm", "e7c4b0bdbf460c928234951def54fe87edf1a170f6896675443279e2dbeba167"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
"telemetry_metrics": {:hex, :telemetry_metrics, "1.0.0", "29f5f84991ca98b8eb02fc208b2e6de7c95f8bb2294ef244a176675adc7775df", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f23713b3847286a534e005126d4c959ebcca68ae9582118ce436b521d1d47d5d"},
"telemetry_metrics_splunk": {:hex, :telemetry_metrics_splunk, "0.0.1-alpha", "2104f9d79d5a278edde4976ce0905f09abfade81a5b4e96972a9d35618a89ea8", [:mix], [{:jason, "1.4.1", [hex: :jason, repo: "hexpm", optional: false]}, {:recase, "0.7.0", [hex: :recase, repo: "hexpm", optional: false]}, {:telemetry, "1.2.1", [hex: :telemetry, repo: "hexpm", optional: false]}, {:telemetry_metrics, "1.0.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "2f40676055ee8a44f6a2515be9ee171016a9635de66ddb3f4c86cf4b23169306"},
"telemetry_metrics_statsd": {:hex, :telemetry_metrics_statsd, "0.7.0", "92732fae63db31ef2508df6faee7d81401883e33f2976715a82f296a33a45cee", [:mix], [{:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "797e34a856376dfd4e96347da0f747fcff4e0cadf6e6f0f989598f563cad05ff"},
"telemetry_poller": {:hex, :telemetry_poller, "1.1.0", "58fa7c216257291caaf8d05678c8d01bd45f4bdbc1286838a28c4bb62ef32999", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "9eb9d9cbfd81cbd7cdd24682f8711b6e2b691289a0de6826e58452f28c103c8f"},
"telemetry_test": {:hex, :telemetry_test, "0.1.2", "122d927567c563cf57773105fa8104ae4299718ec2cbdddcf6776562c7488072", [:mix], [{:telemetry, "~> 1.2", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7bd41a49ecfd33ecd82d2c7edae19a5736f0d2150206d0ee290dcf3885d0e14d"},
Expand Down

0 comments on commit 7910382

Please sign in to comment.