mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-23 18:17:44 +02:00
Add Prometheus metrics endpoint with local-bind listener support and baseline metrics collectors.
36 lines
611 B
Go
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()
|
|
}
|