Browse Source
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>
pull/4097/head^2
Kevin Liu
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
10 additions and
2 deletions
-
weed/stats/metrics.go
|
@ -1,7 +1,6 @@ |
|
|
package stats |
|
|
package stats |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"fmt" |
|
|
|
|
|
"log" |
|
|
"log" |
|
|
"net" |
|
|
"net" |
|
|
"net/http" |
|
|
"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) { |
|
|
func StartMetricsServer(ip string, port int) { |
|
|
if port == 0 { |
|
|
if port == 0 { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
http.Handle("/metrics", promhttp.HandlerFor(Gather, promhttp.HandlerOpts{})) |
|
|
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 { |
|
|
func SourceName(port uint32) string { |
|
|