diff --git a/cmd/converge/prometheus.go b/cmd/converge/prometheus.go index e67bc26..9e59c61 100644 --- a/cmd/converge/prometheus.go +++ b/cmd/converge/prometheus.go @@ -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 } diff --git a/pkg/models/state.go b/pkg/models/state.go index 70d1cfd..529bf28 100644 --- a/pkg/models/state.go +++ b/pkg/models/state.go @@ -1,6 +1,9 @@ package models type State struct { + CumulativeAgentCount int + CumulativeClientCount int + Agents []Agent Clients []Client Ascii string