From 96cb5bafcdbf34001fecf84f0da2bdf80e6add42 Mon Sep 17 00:00:00 2001 From: Carl Pearson Date: Fri, 30 May 2025 09:14:13 -0600 Subject: [PATCH] Add num-images and heap-in-use fields to /about --- handlers/about.go | 14 +++++++++++--- store/store.go | 7 +++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/handlers/about.go b/handlers/about.go index 2e5d296..17d4682 100644 --- a/handlers/about.go +++ b/handlers/about.go @@ -2,15 +2,23 @@ package handlers import ( "net/http" + "runtime" "github.com/labstack/echo/v4" "git.sr.ht/~cwpearson/replicate-jump-server/config" + "git.sr.ht/~cwpearson/replicate-jump-server/store" ) func AboutGet(c echo.Context) error { - return c.JSON(http.StatusOK, map[string]string{ - "version": config.GitSHA(), - "build-date": config.BuildDate(), + + ms := &runtime.MemStats{} + runtime.ReadMemStats(ms) + + return c.JSON(http.StatusOK, map[string]any{ + "version": config.GitSHA(), + "build-date": config.BuildDate(), + "num-images": store.NumImages(), + "heap-in-use": ms.HeapInuse, }) } diff --git a/store/store.go b/store/store.go index 3d84eae..d4e7801 100644 --- a/store/store.go +++ b/store/store.go @@ -117,3 +117,10 @@ func Save(data []byte, contentType string) string { } return store.Save(data, contentType) } + +func NumImages() int { + if store == nil { + store = newStore() + } + return len(store.images) +}