diff options
| author | chrislu <chris.lu@gmail.com> | 2025-03-25 12:19:53 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2025-03-25 12:19:53 -0700 |
| commit | c2d6fabd935c85527fcfe024b0ef4dda3675aab1 (patch) | |
| tree | c71816e4bfb92aad0207dd8a8d41bf51b57a5ed7 /weed/server/master_server.go | |
| parent | 138b66231a90f3bdea829d1567cd8f34d91010f1 (diff) | |
| download | seaweedfs-origin/collect-public-metrics.tar.xz seaweedfs-origin/collect-public-metrics.zip | |
add option to collect metricsorigin/collect-public-metrics
Diffstat (limited to 'weed/server/master_server.go')
| -rw-r--r-- | weed/server/master_server.go | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/weed/server/master_server.go b/weed/server/master_server.go index 8621708d2..32d6b76b1 100644 --- a/weed/server/master_server.go +++ b/weed/server/master_server.go @@ -45,13 +45,14 @@ type MasterOption struct { VolumePreallocate bool MaxParallelVacuumPerServer int // PulseSeconds int - DefaultReplicaPlacement string - GarbageThreshold float64 - WhiteList []string - DisableHttp bool - MetricsAddress string - MetricsIntervalSec int - IsFollower bool + DefaultReplicaPlacement string + GarbageThreshold float64 + WhiteList []string + DisableHttp bool + MetricsAddress string + MetricsIntervalSec int + IsFollower bool + SupportSeaweedFsWithMetrics bool } type MasterServer struct { @@ -416,3 +417,31 @@ func (ms *MasterServer) Reload() { util.StringSplit(v.GetString("guard.white_list"), ",")...), ) } + +func (ms *MasterServer) startMetricsCollection() { + go func() { + ticker := time.NewTicker(30 * time.Second) + defer ticker.Stop() + + for { + select { + case <-ticker.C: + if ms.Topo != nil { + stats.UpdateClusterMetrics(ms.Topo.ToTopologyInfo(), ms.option.VolumeSizeLimitMB) + // Push metrics to the gateway if enabled + if err := stats.PushMetrics(stats.GenerateClusterId(ms.Topo.ToTopologyInfo()), ms.option.SupportSeaweedFsWithMetrics); err != nil { + glog.Warningf("Failed to push metrics: %v", err) + } + } + } + } + }() +} + +func (ms *MasterServer) Start() error { + // Start metrics collection + ms.startMetricsCollection() + + // ... rest of existing code ... + return nil +} |
