📎 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/2call inPageController.index/2. - The custom counter is added in
metrics_demo_web/telemetry.exascounter("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.MetricsGeneratorGenServer that sends a:worktelemetry event every 2 seconds with randomdurationandresult_countvalues. - The GenServer is added to
application.exso it starts with the app. - Two summary metrics,
metrics_demo.work.durationandmetrics_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.
