↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

Adding custom metrics to a Phoenix 1.5 live dashboard

The article adds custom metrics to a Phoenix 1.5 live dashboard by emitting telemetry from a controller, registering the counter in the Telemetry metrics list, and then adding a GenServer that periodically sends work events. It shows how those metrics appear on the dashboard and notes that summary metrics expose mix, max, average, count, or duration.

Reading notes
#

  • It starts by installing Phoenix 1.5 project generator, creating a new project, and adding a :telemetry.execute/2 call in PageController.index/2.
  • The custom counter is added in metrics_demo_web/telemetry.ex as counter("metrics_demo.render.controller").
  • The metric name prefix determines the dashboard tab, and the order of metrics in the array affects their order on the page.
  • The article explains that only the controller value is counted in the example, even though the action value is also present in the emitted event.
  • It then adds a MetricsDemo.MetricsGenerator GenServer that sends a :work telemetry event every 2 seconds with random duration and result_count values.
  • The GenServer is added to application.ex so it starts with the app.
  • Two summary metrics, metrics_demo.work.duration and metrics_demo.work.result_count, are added to the Telemetry metrics list.
  • After restarting the app, the dashboard shows the new metrics automatically.
  • The post notes that summary graphs show mix, max, average, and count or duration.
  • It also says the dashboard data is transient and refreshing the page clears collected data.