diff options
| author | Chris Lu <chris.lu@gmail.com> | 2019-06-17 14:51:47 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2019-06-17 14:51:47 -0700 |
| commit | d8ed73926dc79aaea57e9eb305c718e82dace64c (patch) | |
| tree | e0dab86e8ddf7a79b2330b9eeb6654378a255df1 /weed/stats | |
| parent | 68d1bef23671f353f65d89b73907edf5ce6918fc (diff) | |
| download | seaweedfs-d8ed73926dc79aaea57e9eb305c718e82dace64c.tar.xz seaweedfs-d8ed73926dc79aaea57e9eb305c718e82dace64c.zip | |
volume servers get metrics address and interval from the master
Diffstat (limited to 'weed/stats')
| -rw-r--r-- | weed/stats/metrics.go | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/weed/stats/metrics.go b/weed/stats/metrics.go index ce0af342d..2912bd34e 100644 --- a/weed/stats/metrics.go +++ b/weed/stats/metrics.go @@ -86,25 +86,29 @@ func init() { } -func StartPushingMetric(name, instance string, gatherer *prometheus.Registry, addr string, intervalSeconds int) { - if intervalSeconds == 0 || addr == "" { - glog.V(0).Info("disable metrics reporting") - return - } - glog.V(0).Infof("push metrics to %s every %d seconds", addr, intervalSeconds) - go loopPushMetrics(name, instance, gatherer, addr, intervalSeconds) -} - -func loopPushMetrics(name, instance string, gatherer *prometheus.Registry, addr string, intervalSeconds int) { +func LoopPushingMetric(name, instance string, gatherer *prometheus.Registry, fnGetMetricsDest func() (addr string, intervalSeconds int)) { + addr, intervalSeconds := fnGetMetricsDest() pusher := push.New(addr, name).Gatherer(gatherer).Grouping("instance", instance) + currentAddr := addr for { - err := pusher.Push() - if err != nil { - glog.V(0).Infof("could not push metrics to prometheus push gateway %s: %v", addr, err) + if currentAddr != "" { + err := pusher.Push() + if err != nil { + glog.V(0).Infof("could not push metrics to prometheus push gateway %s: %v", addr, err) + } + } + if intervalSeconds <= 0 { + intervalSeconds = 15 } time.Sleep(time.Duration(intervalSeconds) * time.Second) + addr, intervalSeconds = fnGetMetricsDest() + if currentAddr != addr { + pusher = push.New(addr, name).Gatherer(gatherer).Grouping("instance", instance) + currentAddr = addr + } + } } |
