| 1 |
|
defmodule DaProductAppWeb.Telemetry do |
| 2 |
|
use Supervisor |
| 3 |
|
import Telemetry.Metrics |
| 4 |
|
|
| 5 |
|
def start_link(arg) do |
| 6 |
1 |
Supervisor.start_link(__MODULE__, arg, name: __MODULE__) |
| 7 |
|
end |
| 8 |
|
|
| 9 |
|
@impl true |
| 10 |
|
def init(_arg) do |
| 11 |
1 |
children = [ |
| 12 |
|
# Telemetry poller will execute the given period measurements |
| 13 |
|
# every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics |
| 14 |
|
{:telemetry_poller, measurements: periodic_measurements(), period: 10_000} |
| 15 |
|
# Add reporters as children of your supervision tree. |
| 16 |
|
# {Telemetry.Metrics.ConsoleReporter, metrics: metrics()} |
| 17 |
|
] |
| 18 |
|
|
| 19 |
1 |
Supervisor.init(children, strategy: :one_for_one) |
| 20 |
|
end |
| 21 |
|
|
| 22 |
:-( |
def metrics do |
| 23 |
|
[ |
| 24 |
|
# Phoenix Metrics |
| 25 |
|
summary("phoenix.endpoint.start.system_time", |
| 26 |
|
unit: {:native, :millisecond} |
| 27 |
|
), |
| 28 |
|
summary("phoenix.endpoint.stop.duration", |
| 29 |
|
unit: {:native, :millisecond} |
| 30 |
|
), |
| 31 |
|
summary("phoenix.router_dispatch.start.system_time", |
| 32 |
|
tags: [:route], |
| 33 |
|
unit: {:native, :millisecond} |
| 34 |
|
), |
| 35 |
|
summary("phoenix.router_dispatch.exception.duration", |
| 36 |
|
tags: [:route], |
| 37 |
|
unit: {:native, :millisecond} |
| 38 |
|
), |
| 39 |
|
summary("phoenix.router_dispatch.stop.duration", |
| 40 |
|
tags: [:route], |
| 41 |
|
unit: {:native, :millisecond} |
| 42 |
|
), |
| 43 |
|
summary("phoenix.socket_connected.duration", |
| 44 |
|
unit: {:native, :millisecond} |
| 45 |
|
), |
| 46 |
|
summary("phoenix.channel_joined.duration", |
| 47 |
|
unit: {:native, :millisecond} |
| 48 |
|
), |
| 49 |
|
summary("phoenix.channel_handled_in.duration", |
| 50 |
|
tags: [:event], |
| 51 |
|
unit: {:native, :millisecond} |
| 52 |
|
), |
| 53 |
|
|
| 54 |
|
# Database Metrics |
| 55 |
|
summary("da_product_app.repo.query.total_time", |
| 56 |
|
unit: {:native, :millisecond}, |
| 57 |
|
description: "The sum of the other measurements" |
| 58 |
|
), |
| 59 |
|
summary("da_product_app.repo.query.decode_time", |
| 60 |
|
unit: {:native, :millisecond}, |
| 61 |
|
description: "The time spent decoding the data received from the database" |
| 62 |
|
), |
| 63 |
|
summary("da_product_app.repo.query.query_time", |
| 64 |
|
unit: {:native, :millisecond}, |
| 65 |
|
description: "The time spent executing the query" |
| 66 |
|
), |
| 67 |
|
summary("da_product_app.repo.query.queue_time", |
| 68 |
|
unit: {:native, :millisecond}, |
| 69 |
|
description: "The time spent waiting for a database connection" |
| 70 |
|
), |
| 71 |
|
summary("da_product_app.repo.query.idle_time", |
| 72 |
|
unit: {:native, :millisecond}, |
| 73 |
|
description: |
| 74 |
|
"The time the connection spent waiting before being checked out for the query" |
| 75 |
|
), |
| 76 |
|
|
| 77 |
|
# VM Metrics |
| 78 |
|
summary("vm.memory.total", unit: {:byte, :kilobyte}), |
| 79 |
|
summary("vm.total_run_queue_lengths.total"), |
| 80 |
|
summary("vm.total_run_queue_lengths.cpu"), |
| 81 |
|
summary("vm.total_run_queue_lengths.io") |
| 82 |
|
] |
| 83 |
|
end |
| 84 |
|
|
| 85 |
1 |
defp periodic_measurements do |
| 86 |
|
[ |
| 87 |
|
# A module, function and arguments to be invoked periodically. |
| 88 |
|
# This function must call :telemetry.execute/3 and a metric must be added above. |
| 89 |
|
# {DaProductAppWeb, :count_users, []} |
| 90 |
|
] |
| 91 |
|
end |
| 92 |
|
end |