Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

Fix binding metrics to ipv6 (#4286)

Kevin Liu244385bf0d5e
diff --git a/weed/stats/metrics.go b/weed/stats/metrics.go
index a9a24ce317..454b35d7a3 100644
--- a/weed/stats/metrics.go
+++ b/weed/stats/metrics.go
@@ -1,7 +1,6 @@
package stats
import (
- "fmt"
"log"
"net"
"net/http"
@@ -282,12 +281,21 @@ func LoopPushingMetric(name, instance, addr string, intervalSeconds int) {
}
}
+func JoinHostPort(host string, port int) string {
+ portStr := strconv.Itoa(port)
+ if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {
+ return host + ":" + portStr
+ }
+ return net.JoinHostPort(host, portStr)
+}
+
+
func StartMetricsServer(ip string, port int) {
if port == 0 {
return
}
http.Handle("/metrics", promhttp.HandlerFor(Gather, promhttp.HandlerOpts{}))
- log.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%d", ip, port), nil))
+ log.Fatal(http.ListenAndServe(JoinHostPort(ip, port), nil))
}
func SourceName(port uint32) string {