From c9952759c428a0b07929e5aa92c8853afaecb800 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Mon, 24 Jan 2022 20:13:07 +0500 Subject: [PATCH] metrics master is leader --- weed/server/master_grpc_server.go | 3 +++ weed/stats/metrics.go | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/weed/server/master_grpc_server.go b/weed/server/master_grpc_server.go index f1d495c66..50fcc0d62 100644 --- a/weed/server/master_grpc_server.go +++ b/weed/server/master_grpc_server.go @@ -237,7 +237,10 @@ func (ms *MasterServer) KeepConnected(stream master_pb.Seaweed_KeepConnectedServ } case <-ticker.C: if !ms.Topo.IsLeader() { + stats.MasterRaftIsleader.Set(0) return ms.informNewLeader(stream) + } else { + stats.MasterRaftIsleader.Set(1) } case <-stopChan: return nil diff --git a/weed/stats/metrics.go b/weed/stats/metrics.go index b43da609f..c764ba63d 100644 --- a/weed/stats/metrics.go +++ b/weed/stats/metrics.go @@ -28,6 +28,14 @@ var ( Help: "Counter of master client leader updates.", }, []string{"type"}) + MasterRaftIsleader = prometheus.NewGauge( + prometheus.GaugeOpts{ + Namespace: "SeaweedFS", + Subsystem: "master", + Name: "is leader", + Help: "is leader", + }) + MasterReceivedHeartbeatCounter = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: "SeaweedFS", @@ -153,6 +161,11 @@ var ( ) func init() { + Gather.MustRegister(MasterClientConnectCounter) + Gather.MustRegister(MasterRaftIsleader) + Gather.MustRegister(MasterReceivedHeartbeatCounter) + Gather.MustRegister(MasterLeaderChangeCounter) + Gather.MustRegister(FilerRequestCounter) Gather.MustRegister(FilerRequestHistogram) Gather.MustRegister(FilerStoreCounter)