From 68a2159d7df65f409208b38f6da127be5efa61f2 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sat, 20 Sep 2025 08:24:15 +0300 Subject: [PATCH] Track total assets cache size in Live Dashboard --- lib/music_library/assets/cache.ex | 8 ++++++++ lib/music_library_web/telemetry.ex | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/lib/music_library/assets/cache.ex b/lib/music_library/assets/cache.ex index 00dfd362..f5a38dd1 100644 --- a/lib/music_library/assets/cache.ex +++ b/lib/music_library/assets/cache.ex @@ -23,6 +23,14 @@ defmodule MusicLibrary.Assets.Cache do ) end + def track_total_content_size do + :telemetry.execute( + [:music_library, :assets, :cache], + %{total_content_size: total_content_size()}, + %{} + ) + end + def prune(older_than_seconds) do threshold = DateTime.utc_now() diff --git a/lib/music_library_web/telemetry.ex b/lib/music_library_web/telemetry.ex index 3b86f204..87025d63 100644 --- a/lib/music_library_web/telemetry.ex +++ b/lib/music_library_web/telemetry.ex @@ -115,6 +115,9 @@ defmodule MusicLibraryWeb.Telemetry do ] ), + # Assets + summary("music_library.assets.cache.total_content_size", unit: {:byte, :kilobyte}), + # VM Metrics summary("vm.memory.total", unit: {:byte, :megabyte}), summary("vm.total_run_queue_lengths.total"), @@ -125,6 +128,7 @@ defmodule MusicLibraryWeb.Telemetry do defp periodic_measurements do [ + {MusicLibrary.Assets.Cache, :track_total_content_size, []} # A module, function and arguments to be invoked periodically. # This function must call :telemetry.execute/3 and a metric must be added above. # {MusicLibraryWeb, :count_users, []}