more metrics
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m43s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m43s
This commit is contained in:
@@ -10,6 +10,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
)
|
)
|
||||||
@@ -116,6 +118,21 @@ func NewSyncedPool(local *GrainLocalPool, hostname string, d Discovery) (*Synced
|
|||||||
return pool, nil
|
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 (
|
const (
|
||||||
RemoteNegotiate = uint16(3)
|
RemoteNegotiate = uint16(3)
|
||||||
RemoteGrainChanged = uint16(4)
|
RemoteGrainChanged = uint16(4)
|
||||||
@@ -140,6 +157,7 @@ func (p *SyncedPool) handleConnection(conn net.Conn) {
|
|||||||
// }
|
// }
|
||||||
switch packet.MessageType {
|
switch packet.MessageType {
|
||||||
case RemoteNegotiate:
|
case RemoteNegotiate:
|
||||||
|
negotiationCount.Inc()
|
||||||
data := make([]byte, packet.DataLength)
|
data := make([]byte, packet.DataLength)
|
||||||
conn.Read(data)
|
conn.Read(data)
|
||||||
knownHosts := strings.Split(string(data), ";")
|
knownHosts := strings.Split(string(data), ";")
|
||||||
@@ -162,6 +180,7 @@ func (p *SyncedPool) handleConnection(conn net.Conn) {
|
|||||||
})
|
})
|
||||||
case RemoteGrainChanged:
|
case RemoteGrainChanged:
|
||||||
// remote grain changed
|
// remote grain changed
|
||||||
|
grainSyncCount.Inc()
|
||||||
log.Printf("Remote grain changed\n")
|
log.Printf("Remote grain changed\n")
|
||||||
for err == nil {
|
for err == nil {
|
||||||
idAndHost := make([]byte, packet.DataLength)
|
idAndHost := make([]byte, packet.DataLength)
|
||||||
@@ -280,7 +299,9 @@ func (p *SyncedPool) AddRemote(address string) error {
|
|||||||
Pool: pool,
|
Pool: pool,
|
||||||
Host: address,
|
Host: address,
|
||||||
}
|
}
|
||||||
|
|
||||||
p.remotes = append(p.remotes, remote)
|
p.remotes = append(p.remotes, remote)
|
||||||
|
connectedRemotes.Set(float64(len(p.remotes)))
|
||||||
log.Printf("Added remote %s\n", remote.Host)
|
log.Printf("Added remote %s\n", remote.Host)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user