Add status page to expose metrics

This commit is contained in:
Christopher LaPointe
2023-05-23 21:48:16 -04:00
parent 3466d20b80
commit 757be8639f
5 changed files with 176 additions and 56 deletions

10
main.go
View File

@@ -2,9 +2,11 @@ package main
import (
"errors"
"fmt"
"io"
"io/fs"
"net/http"
"runtime"
"traefik-lazyload/pkg/config"
"traefik-lazyload/pkg/service"
@@ -84,7 +86,13 @@ func ContainerHandler(w http.ResponseWriter, r *http.Request) {
func StatusHandler(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/":
io.WriteString(w, "Status page")
var stats runtime.MemStats
runtime.ReadMemStats(&stats)
statusPageTemplate.Execute(w, StatusPageModel{
Active: core.ActiveContainers(),
Qualifying: core.QualifyingContainers(),
RuntimeMetrics: fmt.Sprintf("Heap=%d, InUse=%d, Total=%d, Sys=%d, NumGC=%d", stats.HeapAlloc, stats.HeapInuse, stats.TotalAlloc, stats.Sys, stats.NumGC),
})
default:
w.WriteHeader(http.StatusNotFound)
io.WriteString(w, "Status page not found")