cumulative counters implemented.
This commit is contained in:
		
							parent
							
								
									5aba014deb
								
							
						
					
					
						commit
						7af8c2a09b
					
				| @ -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 | ||||
| } | ||||
|  | ||||
| @ -1,6 +1,9 @@ | ||||
| package models | ||||
| 
 | ||||
| type State struct { | ||||
| 	CumulativeAgentCount  int | ||||
| 	CumulativeClientCount int | ||||
| 
 | ||||
| 	Agents  []Agent | ||||
| 	Clients []Client | ||||
| 	Ascii   string | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user