aboutsummaryrefslogtreecommitdiff
path: root/weed/stats/metrics.go
diff options
context:
space:
mode:
authorChris Lu <chrislusf@users.noreply.github.com>2020-09-24 09:50:48 -0700
committerGitHub <noreply@github.com>2020-09-24 09:50:48 -0700
commit2e9099369e603308c703e4a78e48882ca3c5a5fc (patch)
tree67152aa22273e000ed0a35b2c91a9c01587aca08 /weed/stats/metrics.go
parent2e7c361a0d5fe1217bc00512d7ac7bc5975dfb53 (diff)
parent98e9de6e111a1e4512a9d78d7d44d949af14d6dc (diff)
downloadseaweedfs-2e9099369e603308c703e4a78e48882ca3c5a5fc.tar.xz
seaweedfs-2e9099369e603308c703e4a78e48882ca3c5a5fc.zip
Merge pull request #1489 from kmlebedev/promhttp
Promhttp
Diffstat (limited to 'weed/stats/metrics.go')
-rw-r--r--weed/stats/metrics.go11
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 {