From c858245ad9d41ce3477818de42b34a807f52a76d Mon Sep 17 00:00:00 2001 From: matst80 Date: Sat, 9 Nov 2024 19:23:13 +0100 Subject: [PATCH] more metrics --- synced-pool.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/synced-pool.go b/synced-pool.go index 15ffb67..13a4b50 100644 --- a/synced-pool.go +++ b/synced-pool.go @@ -10,6 +10,8 @@ import ( "strings" "time" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" ) @@ -116,6 +118,21 @@ func NewSyncedPool(local *GrainLocalPool, hostname string, d Discovery) (*Synced return pool, nil } +var ( + negotiationCount = promauto.NewCounter(prometheus.CounterOpts{ + Name: "cart_remote_negotiation_total", + Help: "The total number of remote negotiations", + }) + grainSyncCount = promauto.NewCounter(prometheus.CounterOpts{ + Name: "cart_grain_spawned_total", + Help: "The total number of grain owner changes", + }) + connectedRemotes = promauto.NewGauge(prometheus.GaugeOpts{ + Name: "cart_connected_remotes", + Help: "The number of connected remotes", + }) +) + const ( RemoteNegotiate = uint16(3) RemoteGrainChanged = uint16(4) @@ -140,6 +157,7 @@ func (p *SyncedPool) handleConnection(conn net.Conn) { // } switch packet.MessageType { case RemoteNegotiate: + negotiationCount.Inc() data := make([]byte, packet.DataLength) conn.Read(data) knownHosts := strings.Split(string(data), ";") @@ -162,6 +180,7 @@ func (p *SyncedPool) handleConnection(conn net.Conn) { }) case RemoteGrainChanged: // remote grain changed + grainSyncCount.Inc() log.Printf("Remote grain changed\n") for err == nil { idAndHost := make([]byte, packet.DataLength) @@ -280,7 +299,9 @@ func (p *SyncedPool) AddRemote(address string) error { Pool: pool, Host: address, } + p.remotes = append(p.remotes, remote) + connectedRemotes.Set(float64(len(p.remotes))) log.Printf("Added remote %s\n", remote.Host) return nil