From c8f7040fe57d5f16a0a54c2cd85424511d537ad3 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 09 Mar 2025 16:33:51 +0800 Subject: [PATCH] index: Show allocated bytes --- http_handle_index.go | 6 ++++++ templates/index.tmpl | 9 ++++++--- diff --git a/http_handle_index.go b/http_handle_index.go index 4632526ed5fcd102e51d8cbb5a7252fa4cef1959..623c6194c9c7c0d3704c31b88565a2f311fddd39 100644 --- a/http_handle_index.go +++ b/http_handle_index.go @@ -5,6 +5,7 @@ package main import ( "net/http" + "runtime" ) func handle_index(w http.ResponseWriter, r *http.Request, params map[string]any) { @@ -17,5 +18,10 @@ http.Error(w, "Error querying groups: "+err.Error(), http.StatusInternalServerError) return } params["groups"] = groups + + // Memory currently allocated + memstats := runtime.MemStats{} + runtime.ReadMemStats(&memstats) + params["mem"] = memstats.Alloc render_template(w, "index", params) } diff --git a/templates/index.tmpl b/templates/index.tmpl index 2aa5729ac033d35d300764e8e1fef837710fad53..917e7feaa23616a7cf8624b4a686400ad30cb75e 100644 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -53,11 +53,14 @@ SSH fingerprint {{- .global.server_public_key_fingerprint -}} + + Memory usage + + Allocated {{ .mem }} bytes Collect garbage + + - -
- Run the garbage collector