diff options
| author | Kevin Liu <mail@nivekuil.com> | 2023-03-08 01:04:02 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-08 01:04:02 -0800 |
| commit | 244385bf0d5ed9be2554619005fb1e469980632c (patch) | |
| tree | 4f34e74da8d84b9f922392835a95f615aac4f58a | |
| parent | 889ecf5c9d14be3ef360fef9ee8542e167b97265 (diff) | |
| download | seaweedfs-244385bf0d5ed9be2554619005fb1e469980632c.tar.xz seaweedfs-244385bf0d5ed9be2554619005fb1e469980632c.zip | |
Fix binding metrics to ipv6 (#4286)
* Fix binding metrics to ipv6
* Update weed/stats/metrics.go
---------
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
| -rw-r--r-- | weed/stats/metrics.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/weed/stats/metrics.go b/weed/stats/metrics.go index a9a24ce31..454b35d7a 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 { |
