telemetry.ex 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. defmodule FourlettersWeb.Telemetry do
  2. use Supervisor
  3. import Telemetry.Metrics
  4. def start_link(arg) do
  5. Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
  6. end
  7. @impl true
  8. def init(_arg) do
  9. children = [
  10. # Telemetry poller will execute the given period measurements
  11. # every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics
  12. {:telemetry_poller, measurements: periodic_measurements(), period: 10_000}
  13. # Add reporters as children of your supervision tree.
  14. # {Telemetry.Metrics.ConsoleReporter, metrics: metrics()}
  15. ]
  16. Supervisor.init(children, strategy: :one_for_one)
  17. end
  18. def metrics do
  19. [
  20. # Phoenix Metrics
  21. summary("phoenix.endpoint.stop.duration",
  22. unit: {:native, :millisecond}
  23. ),
  24. summary("phoenix.router_dispatch.stop.duration",
  25. tags: [:route],
  26. unit: {:native, :millisecond}
  27. ),
  28. # VM Metrics
  29. summary("vm.memory.total", unit: {:byte, :kilobyte}),
  30. summary("vm.total_run_queue_lengths.total"),
  31. summary("vm.total_run_queue_lengths.cpu"),
  32. summary("vm.total_run_queue_lengths.io")
  33. ]
  34. end
  35. defp periodic_measurements do
  36. [
  37. # A module, function and arguments to be invoked periodically.
  38. # This function must call :telemetry.execute/3 and a metric must be added above.
  39. # {FourlettersWeb, :count_users, []}
  40. ]
  41. end
  42. end