Files
simple-cluster-node/health/health.go
2026-02-01 22:52:17 +01:00

39 lines
751 B
Go

package health
import (
"encoding/json"
"fmt"
"net/http"
"os"
"runtime"
)
type HealthInfo struct {
Hostname string
OS string
Arch string
CPU string
Memory string
}
func Handle(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(healthCheck())
}
func healthCheck() HealthInfo {
hostname, _ := os.Hostname()
var mem runtime.MemStats
runtime.ReadMemStats(&mem)
return HealthInfo{Hostname: hostname,
OS: runtime.GOOS,
Arch: runtime.GOARCH,
CPU: string(runtime.NumCPU()),
Memory: string(mem.Alloc/1024/1024) + " MB"}
}
func (h HealthInfo) String() string {
return fmt.Sprintf("HealthInfo{Hostname=%s, OS=%s, Arch=%s. CPU=%s, Memory=%s}", h.Hostname, h.OS, h.Arch, h.CPU, h.Memory)
}