1defmodule CometWeb.Telemetry do
2 use Supervisor
3 import Telemetry.Metrics
4
5 def start_link(arg) do
6 Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
7 end
8
9 @impl true
10 def init(_arg) do
11 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 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 sum("phoenix.socket_drain.count"),
47 summary("phoenix.channel_joined.duration",
48 unit: {:native, :millisecond}
49 ),
50 summary("phoenix.channel_handled_in.duration",
51 tags: [:event],
52 unit: {:native, :millisecond}
53 ),
54
55 # Database Metrics
56 summary("comet.repo.query.total_time",
57 unit: {:native, :millisecond},
58 description: "The sum of the other measurements"
59 ),
60 summary("comet.repo.query.decode_time",
61 unit: {:native, :millisecond},
62 description: "The time spent decoding the data received from the database"
63 ),
64 summary("comet.repo.query.query_time",
65 unit: {:native, :millisecond},
66 description: "The time spent executing the query"
67 ),
68 summary("comet.repo.query.queue_time",
69 unit: {:native, :millisecond},
70 description: "The time spent waiting for a database connection"
71 ),
72 summary("comet.repo.query.idle_time",
73 unit: {:native, :millisecond},
74 description:
75 "The time the connection spent waiting before being checked out for the query"
76 ),
77
78 # VM Metrics
79 summary("vm.memory.total", unit: {:byte, :kilobyte}),
80 summary("vm.total_run_queue_lengths.total"),
81 summary("vm.total_run_queue_lengths.cpu"),
82 summary("vm.total_run_queue_lengths.io")
83 ]
84 end
85
86 defp periodic_measurements do
87 [
88 # A module, function and arguments to be invoked periodically.
89 # This function must call :telemetry.execute/3 and a metric must be added above.
90 # {CometWeb, :count_users, []}
91 ]
92 end
93end