add start metrics server

This commit is contained in:
Konstantin Lebedev
2020-09-24 17:45:39 +05:00
parent 3e52329cee
commit 324e44d4b3
7 changed files with 33 additions and 8 deletions

View File

@@ -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 {