Skip to content

Commit

Permalink
Add Agent's Computer Name to metric (#115)
Browse files Browse the repository at this point in the history
* Add systemcapabilities property to model

* set IncludeCapabilities to true in URL

* Add label for agent computername

* Change fetch capabilities for fetch computername

* Fixed formatting

* Use full capability export rather than demand

Using `Demands` in the query string breaks support for
includeAssignedRequest which is used for working out which agents are
currently doing work

---------

Co-authored-by: Charlie B <[email protected]>
  • Loading branch information
cbat98 and Charlie B authored Feb 9, 2025
1 parent 19ab770 commit 00197b2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
23 changes: 12 additions & 11 deletions azure-devops-client/agentpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,17 @@ type AgentPoolAgentList struct {
}

type AgentPoolAgent struct {
Id int64
Enabled bool
MaxParallelism int64
Name string
OsDescription string
ProvisioningState string
Status string
Version string
CreatedOn time.Time
AssignedRequest JobRequest
Id int64
Enabled bool
MaxParallelism int64
Name string
OsDescription string
SystemCapabilities map[string]string
ProvisioningState string
Status string
Version string
CreatedOn time.Time
AssignedRequest JobRequest
}

type JobRequest struct {
Expand Down Expand Up @@ -160,7 +161,7 @@ func (c *AzureDevopsClient) ListAgentPoolAgents(agentPoolId int64) (list AgentPo
c.concurrencyLock()

url := fmt.Sprintf(
"/_apis/distributedtask/pools/%v/agents?includeCapabilities=false&includeAssignedRequest=true",
"/_apis/distributedtask/pools/%v/agents?includeCapabilities=true&includeAssignedRequest=true",
fmt.Sprintf("%d", agentPoolId),
)
response, err := c.rest().R().Get(url)
Expand Down
22 changes: 12 additions & 10 deletions metrics_agentpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (m *MetricsCollectorAgentPool) Setup(collector *collector.Collector) {
"provisioningState",
"maxParallelism",
"agentPoolAgentOs",
"agentPoolAgentComputerName",
"enabled",
"status",
"hasAssignedRequest",
Expand Down Expand Up @@ -183,16 +184,17 @@ func (m *MetricsCollectorAgentPool) collectAgentQueues(ctx context.Context, logg
for _, agentPoolAgent := range list.List {
agentPoolSize++
infoLabels := prometheus.Labels{
"agentPoolID": int64ToString(agentPoolId),
"agentPoolAgentID": int64ToString(agentPoolAgent.Id),
"agentPoolAgentName": agentPoolAgent.Name,
"agentPoolAgentVersion": agentPoolAgent.Version,
"provisioningState": agentPoolAgent.ProvisioningState,
"maxParallelism": int64ToString(agentPoolAgent.MaxParallelism),
"agentPoolAgentOs": agentPoolAgent.OsDescription,
"enabled": to.BoolString(agentPoolAgent.Enabled),
"status": agentPoolAgent.Status,
"hasAssignedRequest": to.BoolString(agentPoolAgent.AssignedRequest.RequestId > 0),
"agentPoolID": int64ToString(agentPoolId),
"agentPoolAgentID": int64ToString(agentPoolAgent.Id),
"agentPoolAgentName": agentPoolAgent.Name,
"agentPoolAgentVersion": agentPoolAgent.Version,
"provisioningState": agentPoolAgent.ProvisioningState,
"maxParallelism": int64ToString(agentPoolAgent.MaxParallelism),
"agentPoolAgentOs": agentPoolAgent.OsDescription,
"agentPoolAgentComputerName": agentPoolAgent.SystemCapabilities["Agent.ComputerName"],
"enabled": to.BoolString(agentPoolAgent.Enabled),
"status": agentPoolAgent.Status,
"hasAssignedRequest": to.BoolString(agentPoolAgent.AssignedRequest.RequestId > 0),
}

agentPoolAgentMetric.Add(infoLabels, 1)
Expand Down

0 comments on commit 00197b2

Please sign in to comment.