From 8964c7a94a175f6b4f1e328e4b19815aab7fd1c8 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Tue, 4 Mar 2025 15:58:33 +0000 Subject: [PATCH] Add database metrics to Prometheus endpoint --- lib/music_library_web/telemetry.ex | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/music_library_web/telemetry.ex b/lib/music_library_web/telemetry.ex index 1df3c9f5..73aa15bc 100644 --- a/lib/music_library_web/telemetry.ex +++ b/lib/music_library_web/telemetry.ex @@ -110,7 +110,30 @@ defmodule MusicLibraryWeb.Telemetry do last_value("vm.memory.total", unit: {:byte, :megabyte}), last_value("vm.total_run_queue_lengths.total"), last_value("vm.total_run_queue_lengths.cpu"), - last_value("vm.total_run_queue_lengths.io") + last_value("vm.total_run_queue_lengths.io"), + + # Database Metrics + last_value("music_library.repo.query.total_time", + unit: {:native, :millisecond}, + description: "The sum of the other measurements" + ), + last_value("music_library.repo.query.decode_time", + unit: {:native, :millisecond}, + description: "The time spent decoding the data received from the database" + ), + last_value("music_library.repo.query.query_time", + unit: {:native, :millisecond}, + description: "The time spent executing the query" + ), + last_value("music_library.repo.query.queue_time", + unit: {:native, :millisecond}, + description: "The time spent waiting for a database connection" + ), + last_value("music_library.repo.query.idle_time", + unit: {:native, :millisecond}, + description: + "The time the connection spent waiting before being checked out for the query" + ) ] end