add option to collect metrics

This commit is contained in:
chrislu committed 2025-03-25 12:19:53 -07:00
1 parent 138b66231a
commit c2d6fabd93
2 files changed
+222 -7

No files matched your search

+36 -7
View File
@@ -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
}