diff options
Diffstat (limited to 'weed/stats/metrics.go')
| -rw-r--r-- | weed/stats/metrics.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/weed/stats/metrics.go b/weed/stats/metrics.go index 29e7c8edf..5326622bd 100644 --- a/weed/stats/metrics.go +++ b/weed/stats/metrics.go @@ -2,11 +2,14 @@ package stats import ( "fmt" + "log" + "net/http" "os" "strings" "time" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/push" "github.com/chrislusf/seaweedfs/weed/glog" @@ -150,6 +153,14 @@ func LoopPushingMetric(name, instance string, gatherer *prometheus.Registry, add } } +func StartMetricsServer(gatherer *prometheus.Registry, port int) { + if port == 0 { + return + } + http.Handle("/metrics", promhttp.HandlerFor(gatherer, promhttp.HandlerOpts{})) + log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil)) +} + func SourceName(port uint32) string { hostname, err := os.Hostname() if err != nil { |
