From a2f9b695041162d0bcb19e14e87641685090ea71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Mon, 3 Jun 2024 19:32:03 -0700 Subject: [PATCH] add statsviz --- cmd/web/routes.go | 9 +++++++++ go.mod | 2 ++ go.sum | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/cmd/web/routes.go b/cmd/web/routes.go index 1f63aff..bf75b26 100644 --- a/cmd/web/routes.go +++ b/cmd/web/routes.go @@ -3,6 +3,7 @@ package main import ( "net/http" + "github.com/arl/statsviz" "github.com/go-chi/chi/v5" "git.burning.moe/celediel/burning.moe/internal/config" @@ -19,6 +20,14 @@ func routes(app *config.AppConfig) http.Handler { mux.Use(mw) } + // Setup stats viewer + stats, _ := statsviz.NewServer() + mux.Get("/debug/statsviz/ws", stats.Ws()) + mux.Get("/debug/statsviz", func(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, "/debug/statsviz/", 301) + }) + mux.Handle("/debug/statsviz/*", stats.Index()) + // Setup static file server app.Logger.Debug("Setting up /static file server") mux.Handle("/static/*", http.StripPrefix("/static", http.FileServer(http.Dir("./static")))) diff --git a/go.mod b/go.mod index 076b81c..dbee1a3 100644 --- a/go.mod +++ b/go.mod @@ -11,9 +11,11 @@ require ( require ( github.com/BurntSushi/toml v1.3.2 // indirect + github.com/arl/statsviz v0.6.0 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/charmbracelet/lipgloss v0.10.0 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect + github.com/gorilla/websocket v1.5.0 // indirect github.com/joho/godotenv v1.5.1 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect diff --git a/go.sum b/go.sum index 24f61b4..7ad9c73 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/arl/statsviz v0.6.0 h1:jbW1QJkEYQkufd//4NDYRSNBpwJNrdzPahF7ZmoGdyE= +github.com/arl/statsviz v0.6.0/go.mod h1:0toboo+YGSUXDaS4g1D5TVS4dXs7S7YYT5J/qnW2h8s= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s= @@ -13,6 +15,8 @@ github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s= github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/ilyakaznacheev/cleanenv v1.5.0 h1:0VNZXggJE2OYdXE87bfSSwGxeiGt9moSR2lOrsHHvr4= github.com/ilyakaznacheev/cleanenv v1.5.0/go.mod h1:a5aDzaJrLCQZsazHol1w8InnDcOX0OColm64SlIi6gk= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=