telemetry.ex 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. defmodule OpenpodWeb.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. # Database Metrics
  29. summary("openpod.repo.query.total_time", unit: {:native, :millisecond}),
  30. summary("openpod.repo.query.decode_time", unit: {:native, :millisecond}),
  31. summary("openpod.repo.query.query_time", unit: {:native, :millisecond}),
  32. summary("openpod.repo.query.queue_time", unit: {:native, :millisecond}),
  33. summary("openpod.repo.query.idle_time", unit: {:native, :millisecond}),
  34. # VM Metrics
  35. summary("vm.memory.total", unit: {:byte, :kilobyte}),
  36. summary("vm.total_run_queue_lengths.total"),
  37. summary("vm.total_run_queue_lengths.cpu"),
  38. summary("vm.total_run_queue_lengths.io")
  39. ]
  40. end
  41. defp periodic_measurements do
  42. [
  43. # A module, function and arguments to be invoked periodically.
  44. # This function must call :telemetry.execute/3 and a metric must be added above.
  45. # {OpenpodWeb, :count_users, []}
  46. ]
  47. end
  48. end