cumulative counters implemented.

This commit is contained in:
Erik Brakkee 2024-08-07 22:22:54 +02:00
parent 4746279353
commit f62b81cbfb
2 changed files with 34 additions and 0 deletions

View File

@ -12,6 +12,22 @@ import (
const NAMESPACE = "converge"
var (
// remember previous values of agent guids and clients so that we can increment
// the cumulative counters.
lastAgentGuids map[string]bool = make(map[string]bool)
lastClientGuids map[string]bool = make(map[string]bool)
cumulativeAgentCount = promauto.NewCounter(prometheus.CounterOpts{
Namespace: NAMESPACE,
Name: "agent_count_total",
Help: "Total number of agents connected over time",
})
cumulativeClientCount = promauto.NewCounter(prometheus.CounterOpts{
Namespace: NAMESPACE,
Name: "client_count_total",
Help: "Total number of clients connected over time",
})
agentCount = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: NAMESPACE,
Name: "agent_count",
@ -88,14 +104,29 @@ func updateMetrics(state *models.State) {
// become 0.
log.Printf("Got notification %v", *state)
agentGuids := make(map[string]bool)
clientGuids := make(map[string]bool)
agentCount.Set(float64(len(state.Agents)))
agentInfo.Reset()
for _, agent := range state.Agents {
if !lastAgentGuids[agent.Guid] {
cumulativeAgentCount.Inc()
}
agentGuids[agent.Guid] = true
agentActive(agent)
}
lastAgentGuids = agentGuids
clientCount.Set(float64(len(state.Clients)))
clientInfo.Reset()
for _, client := range state.Clients {
if !lastClientGuids[client.Guid] {
cumulativeClientCount.Inc()
}
clientGuids[client.Guid] = true
clientActive(client)
}
lastClientGuids = clientGuids
}

View File

@ -1,6 +1,9 @@
package models
type State struct {
CumulativeAgentCount int
CumulativeClientCount int
Agents []Agent
Clients []Client
Ascii string