Eliminating copying of objects in the prometheus integration.
This commit is contained in:
parent
bf6667aa81
commit
9a1b78ee63
@ -143,18 +143,18 @@ func agentActive(agent *models.Agent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func findAgent(state *models.State, guid string) (*models.Agent, bool) {
|
func findAgent(state *models.State, guid string) (*models.Agent, bool) {
|
||||||
for _, agent := range state.Agents {
|
for i := range state.Agents {
|
||||||
if agent.Guid == guid {
|
if state.Agents[i].Guid == guid {
|
||||||
return &agent, true
|
return &state.Agents[i], true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func findClient(state *models.State, guid string) (*models.Client, bool) {
|
func findClient(state *models.State, guid string) (*models.Client, bool) {
|
||||||
for _, client := range state.Clients {
|
for i := range state.Clients {
|
||||||
if client.Guid == guid {
|
if state.Clients[i].Guid == guid {
|
||||||
return &client, true
|
return &state.Clients[i], true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, false
|
return nil, false
|
||||||
@ -219,12 +219,14 @@ func updateMetrics(state *models.State) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateDurations() {
|
func updateDurations() {
|
||||||
for _, agent := range lastState.Agents {
|
for i := range lastState.Agents {
|
||||||
|
agent := &lastState.Agents[i]
|
||||||
agentDuration.
|
agentDuration.
|
||||||
With(prometheus.Labels{"agent_guid": agent.Guid}).
|
With(prometheus.Labels{"agent_guid": agent.Guid}).
|
||||||
Set(float64(time.Now().Sub(agent.StartTime).Seconds()))
|
Set(float64(time.Now().Sub(agent.StartTime).Seconds()))
|
||||||
}
|
}
|
||||||
for _, client := range lastState.Clients {
|
for i := range lastState.Clients {
|
||||||
|
client := &lastState.Clients[i]
|
||||||
clientDuration.
|
clientDuration.
|
||||||
With(prometheus.Labels{"client_guid": client.Guid}).
|
With(prometheus.Labels{"client_guid": client.Guid}).
|
||||||
Set(float64(time.Now().Sub(client.StartTime).Seconds()))
|
Set(float64(time.Now().Sub(client.StartTime).Seconds()))
|
||||||
@ -232,43 +234,47 @@ func updateDurations() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateMetricsImpl(state *models.State) {
|
func updateMetricsImpl(state *models.State) {
|
||||||
agentGuids := make(map[string]models.Agent)
|
agentGuids := make(map[string]*models.Agent)
|
||||||
clientGuids := make(map[string]models.Client)
|
clientGuids := make(map[string]*models.Client)
|
||||||
|
|
||||||
agentCount.Set(float64(len(state.Agents)))
|
agentCount.Set(float64(len(state.Agents)))
|
||||||
disconnectedAgents := make(map[string]models.Agent)
|
disconnectedAgents := make(map[string]*models.Agent)
|
||||||
for _, agent := range lastState.Agents {
|
for i := range lastState.Agents {
|
||||||
|
agent := &lastState.Agents[i]
|
||||||
disconnectedAgents[agent.Guid] = agent
|
disconnectedAgents[agent.Guid] = agent
|
||||||
}
|
}
|
||||||
for _, agent := range state.Agents {
|
for i := range state.Agents {
|
||||||
|
agent := &state.Agents[i]
|
||||||
if _, ok := findAgent(lastState, agent.Guid); !ok {
|
if _, ok := findAgent(lastState, agent.Guid); !ok {
|
||||||
cumulativeAgentCount.Inc()
|
cumulativeAgentCount.Inc()
|
||||||
}
|
}
|
||||||
delete(disconnectedAgents, agent.Guid)
|
delete(disconnectedAgents, agent.Guid)
|
||||||
agentGuids[agent.Guid] = agent
|
agentGuids[agent.Guid] = agent
|
||||||
agentActive(&agent)
|
agentActive(agent)
|
||||||
}
|
}
|
||||||
for _, agent := range disconnectedAgents {
|
for _, agent := range disconnectedAgents {
|
||||||
removeAgentMetrics(&agent)
|
removeAgentMetrics(agent)
|
||||||
}
|
}
|
||||||
|
|
||||||
clientCount.Set(float64(len(state.Clients)))
|
clientCount.Set(float64(len(state.Clients)))
|
||||||
|
|
||||||
// with this app
|
// with this app
|
||||||
disconnectedClients := make(map[string]models.Client)
|
disconnectedClients := make(map[string]*models.Client)
|
||||||
for _, client := range lastState.Clients {
|
for i := range lastState.Clients {
|
||||||
|
client := &lastState.Clients[i]
|
||||||
disconnectedClients[client.Guid] = client
|
disconnectedClients[client.Guid] = client
|
||||||
}
|
}
|
||||||
for _, client := range state.Clients {
|
for i := range state.Clients {
|
||||||
|
client := &state.Clients[i]
|
||||||
if _, ok := findClient(lastState, client.Guid); !ok {
|
if _, ok := findClient(lastState, client.Guid); !ok {
|
||||||
cumulativeClientCount.Inc()
|
cumulativeClientCount.Inc()
|
||||||
}
|
}
|
||||||
delete(disconnectedClients, client.Guid)
|
delete(disconnectedClients, client.Guid)
|
||||||
clientGuids[client.Guid] = client
|
clientGuids[client.Guid] = client
|
||||||
clientActive(&client)
|
clientActive(client)
|
||||||
}
|
}
|
||||||
for _, client := range disconnectedClients {
|
for _, client := range disconnectedClients {
|
||||||
removeClientMetrics(&client)
|
removeClientMetrics(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
lastState = state
|
lastState = state
|
||||||
|
Loading…
Reference in New Issue
Block a user