From 67a2810d2d917fb368700922ee80011559195fe3 Mon Sep 17 00:00:00 2001 From: Lisandro Pin Date: Mon, 13 Apr 2026 18:34:08 +0200 Subject: [PATCH] Export `start_time_seconds` metrics on both master & volume servers. (#9046) These are to be used to track uptimes. See https://github.com/seaweedfs/seaweedfs/issues/8535 for details. Co-authored-by: Lisandro Pin --- weed/server/master_server.go | 1 + weed/server/volume_server.go | 1 + weed/stats/metrics.go | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/weed/server/master_server.go b/weed/server/master_server.go index fd85976a9..89634b8f0 100644 --- a/weed/server/master_server.go +++ b/weed/server/master_server.go @@ -204,6 +204,7 @@ func NewMasterServer(r *mux.Router, option *MasterOption, peers map[string]pb.Se ms.startAdminScripts() } + stats.MasterStartTimeSeconds.Set(float64(time.Now().Unix())) return ms } diff --git a/weed/server/volume_server.go b/weed/server/volume_server.go index 211ec1523..7bab70276 100644 --- a/weed/server/volume_server.go +++ b/weed/server/volume_server.go @@ -142,6 +142,7 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string, stats.VolumeServerConcurrentDownloadLimit.Set(float64(vs.concurrentDownloadLimit)) stats.VolumeServerConcurrentUploadLimit.Set(float64(vs.concurrentUploadLimit)) + stats.VolumeServerStartTimeSeconds.Set(float64(time.Now().Unix())) go vs.heartbeat() go stats.LoopPushingMetric("volumeServer", util.JoinHostPort(ip, port), vs.metricsAddress, vs.metricsIntervalSec) diff --git a/weed/stats/metrics.go b/weed/stats/metrics.go index 5a702fbee..4cb53a594 100644 --- a/weed/stats/metrics.go +++ b/weed/stats/metrics.go @@ -54,6 +54,14 @@ var ( Help: "A metric with a constant '1' value labeled by version, commit, sizelimit, goos, and goarch from which SeaweedFS was built.", }, []string{"version", "commit", "sizelimit", "goos", "goarch"}) + MasterStartTimeSeconds = prometheus.NewGauge( + prometheus.GaugeOpts{ + Namespace: Namespace, + Subsystem: "master", + Name: "start_time_seconds", + Help: "Start time of the master, as seconds since UNIX epoch.", + }) + MasterClientConnectCounter = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: Namespace, @@ -216,6 +224,14 @@ var ( Help: "The offset of the filer synchronization service.", }, []string{"sourceFiler", "targetFiler", "clientName", "path"}) + VolumeServerStartTimeSeconds = prometheus.NewGauge( + prometheus.GaugeOpts{ + Namespace: Namespace, + Subsystem: "volumeServer", + Name: "start_time_seconds", + Help: "Start time of the volume server, as seconds since UNIX epoch.", + }) + VolumeServerRequestCounter = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: Namespace, @@ -470,6 +486,7 @@ var ( func init() { Gather.MustRegister(BuildInfo) + Gather.MustRegister(MasterStartTimeSeconds) Gather.MustRegister(MasterClientConnectCounter) Gather.MustRegister(MasterRaftIsleader) Gather.MustRegister(MasterAdminLock) @@ -494,6 +511,7 @@ func init() { Gather.MustRegister(collectors.NewGoCollector()) Gather.MustRegister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{})) + Gather.MustRegister(VolumeServerStartTimeSeconds) Gather.MustRegister(VolumeServerRequestCounter) Gather.MustRegister(VolumeServerHandlerCounter) Gather.MustRegister(VolumeServerRequestHistogram)