more metrics
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m43s

This commit is contained in:
matst80
2024-11-09 19:23:13 +01:00
parent 8cf8be2778
commit c858245ad9

View File

@@ -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