Files
multica/server/internal/metrics/config.go
devv-eve f864a07bd5 feat: add server Prometheus metrics endpoint
Add Prometheus metrics endpoint with local-bind listener support and baseline metrics collectors.
2026-04-28 14:29:01 +08:00

36 lines
611 B
Go

package metrics
import (
"net"
"os"
"strings"
)
type Config struct {
Addr string
}
func ConfigFromEnv() Config {
return Config{Addr: strings.TrimSpace(os.Getenv("METRICS_ADDR"))}
}
func (c Config) Enabled() bool {
return strings.TrimSpace(c.Addr) != ""
}
func IsLoopbackAddr(addr string) bool {
host, _, err := net.SplitHostPort(strings.TrimSpace(addr))
if err != nil {
host = strings.TrimSpace(addr)
}
host = strings.Trim(host, "[]")
if host == "" {
return false
}
if strings.EqualFold(host, "localhost") {
return true
}
ip := net.ParseIP(host)
return ip != nil && ip.IsLoopback()
}