aboutsummaryrefslogtreecommitdiff
path: root/weed/stats/metrics.go
diff options
context:
space:
mode:
authorKonstantin Lebedev <lebedev_k@tochka.com>2020-09-24 17:45:39 +0500
committerKonstantin Lebedev <lebedev_k@tochka.com>2020-09-24 17:45:39 +0500
commit324e44d4b3dffc1197bf8f6c6ec49297ace44c2b (patch)
treeedf0b2b4d990e4085d58ab084270912fd9fb5e77 /weed/stats/metrics.go
parent3e52329cee39f3a83f58d3896514547093ff0cf8 (diff)
downloadseaweedfs-324e44d4b3dffc1197bf8f6c6ec49297ace44c2b.tar.xz
seaweedfs-324e44d4b3dffc1197bf8f6c6ec49297ace44c2b.zip
add start metrics server
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 {