diff options
| author | hilimd <68371223+hilimd@users.noreply.github.com> | 2020-09-25 09:45:56 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-25 09:45:56 +0800 |
| commit | 76e24a5660a2192603b7d6d84aef1924ab95cb94 (patch) | |
| tree | 72e1b320c3487aa5f6cb3cd5fc849bfd94108ec8 /weed/stats/metrics.go | |
| parent | 48c578410fea2128f81356250b2cd9d56074d878 (diff) | |
| parent | 043b0631369bec00b33eb53cdf2cdef3eced006c (diff) | |
| download | seaweedfs-76e24a5660a2192603b7d6d84aef1924ab95cb94.tar.xz seaweedfs-76e24a5660a2192603b7d6d84aef1924ab95cb94.zip | |
Merge pull request #20 from chrislusf/master
sync
Diffstat (limited to 'weed/stats/metrics.go')
| -rw-r--r-- | weed/stats/metrics.go | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/weed/stats/metrics.go b/weed/stats/metrics.go index 29e7c8edf..d930caf0f 100644 --- a/weed/stats/metrics.go +++ b/weed/stats/metrics.go @@ -2,20 +2,21 @@ 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" ) var ( - FilerGather = prometheus.NewRegistry() - VolumeServerGather = prometheus.NewRegistry() - S3Gather = prometheus.NewRegistry() + Gather = prometheus.NewRegistry() FilerRequestCounter = prometheus.NewCounterVec( prometheus.CounterOpts{ @@ -111,23 +112,23 @@ var ( func init() { - FilerGather.MustRegister(FilerRequestCounter) - FilerGather.MustRegister(FilerRequestHistogram) - FilerGather.MustRegister(FilerStoreCounter) - FilerGather.MustRegister(FilerStoreHistogram) - FilerGather.MustRegister(prometheus.NewGoCollector()) + Gather.MustRegister(FilerRequestCounter) + Gather.MustRegister(FilerRequestHistogram) + Gather.MustRegister(FilerStoreCounter) + Gather.MustRegister(FilerStoreHistogram) + Gather.MustRegister(prometheus.NewGoCollector()) - VolumeServerGather.MustRegister(VolumeServerRequestCounter) - VolumeServerGather.MustRegister(VolumeServerRequestHistogram) - VolumeServerGather.MustRegister(VolumeServerVolumeCounter) - VolumeServerGather.MustRegister(VolumeServerMaxVolumeCounter) - VolumeServerGather.MustRegister(VolumeServerDiskSizeGauge) + Gather.MustRegister(VolumeServerRequestCounter) + Gather.MustRegister(VolumeServerRequestHistogram) + Gather.MustRegister(VolumeServerVolumeCounter) + Gather.MustRegister(VolumeServerMaxVolumeCounter) + Gather.MustRegister(VolumeServerDiskSizeGauge) - S3Gather.MustRegister(S3RequestCounter) - S3Gather.MustRegister(S3RequestHistogram) + Gather.MustRegister(S3RequestCounter) + Gather.MustRegister(S3RequestHistogram) } -func LoopPushingMetric(name, instance string, gatherer *prometheus.Registry, addr string, intervalSeconds int) { +func LoopPushingMetric(name, instance, addr string, intervalSeconds int) { if addr == "" || intervalSeconds == 0 { return @@ -135,7 +136,7 @@ func LoopPushingMetric(name, instance string, gatherer *prometheus.Registry, add glog.V(0).Infof("%s server sends metrics to %s every %d seconds", name, addr, intervalSeconds) - pusher := push.New(addr, name).Gatherer(gatherer).Grouping("instance", instance) + pusher := push.New(addr, name).Gatherer(Gather).Grouping("instance", instance) for { err := pusher.Push() @@ -150,6 +151,14 @@ func LoopPushingMetric(name, instance string, gatherer *prometheus.Registry, add } } +func StartMetricsServer(port int) { + if port == 0 { + return + } + http.Handle("/metrics", promhttp.HandlerFor(Gather, promhttp.HandlerOpts{})) + log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil)) +} + func SourceName(port uint32) string { hostname, err := os.Hostname() if err != nil { |
