mirror of
https://github.com/zix99/traefik-lazyload.git
synced 2025-12-26 07:13:33 +01:00
Add status page to expose metrics
This commit is contained in:
10
main.go
10
main.go
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user