Skip to content

Commit 00197b2

Browse files
cbat98Charlie B
and
Charlie B
authored
Add Agent's Computer Name to metric (#115)
* 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]>
1 parent 19ab770 commit 00197b2

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

azure-devops-client/agentpool.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,17 @@ type AgentPoolAgentList struct {
100100
}
101101

102102
type AgentPoolAgent struct {
103-
Id int64
104-
Enabled bool
105-
MaxParallelism int64
106-
Name string
107-
OsDescription string
108-
ProvisioningState string
109-
Status string
110-
Version string
111-
CreatedOn time.Time
112-
AssignedRequest JobRequest
103+
Id int64
104+
Enabled bool
105+
MaxParallelism int64
106+
Name string
107+
OsDescription string
108+
SystemCapabilities map[string]string
109+
ProvisioningState string
110+
Status string
111+
Version string
112+
CreatedOn time.Time
113+
AssignedRequest JobRequest
113114
}
114115

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

162163
url := fmt.Sprintf(
163-
"/_apis/distributedtask/pools/%v/agents?includeCapabilities=false&includeAssignedRequest=true",
164+
"/_apis/distributedtask/pools/%v/agents?includeCapabilities=true&includeAssignedRequest=true",
164165
fmt.Sprintf("%d", agentPoolId),
165166
)
166167
response, err := c.rest().R().Get(url)

metrics_agentpool.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (m *MetricsCollectorAgentPool) Setup(collector *collector.Collector) {
7777
"provisioningState",
7878
"maxParallelism",
7979
"agentPoolAgentOs",
80+
"agentPoolAgentComputerName",
8081
"enabled",
8182
"status",
8283
"hasAssignedRequest",
@@ -183,16 +184,17 @@ func (m *MetricsCollectorAgentPool) collectAgentQueues(ctx context.Context, logg
183184
for _, agentPoolAgent := range list.List {
184185
agentPoolSize++
185186
infoLabels := prometheus.Labels{
186-
"agentPoolID": int64ToString(agentPoolId),
187-
"agentPoolAgentID": int64ToString(agentPoolAgent.Id),
188-
"agentPoolAgentName": agentPoolAgent.Name,
189-
"agentPoolAgentVersion": agentPoolAgent.Version,
190-
"provisioningState": agentPoolAgent.ProvisioningState,
191-
"maxParallelism": int64ToString(agentPoolAgent.MaxParallelism),
192-
"agentPoolAgentOs": agentPoolAgent.OsDescription,
193-
"enabled": to.BoolString(agentPoolAgent.Enabled),
194-
"status": agentPoolAgent.Status,
195-
"hasAssignedRequest": to.BoolString(agentPoolAgent.AssignedRequest.RequestId > 0),
187+
"agentPoolID": int64ToString(agentPoolId),
188+
"agentPoolAgentID": int64ToString(agentPoolAgent.Id),
189+
"agentPoolAgentName": agentPoolAgent.Name,
190+
"agentPoolAgentVersion": agentPoolAgent.Version,
191+
"provisioningState": agentPoolAgent.ProvisioningState,
192+
"maxParallelism": int64ToString(agentPoolAgent.MaxParallelism),
193+
"agentPoolAgentOs": agentPoolAgent.OsDescription,
194+
"agentPoolAgentComputerName": agentPoolAgent.SystemCapabilities["Agent.ComputerName"],
195+
"enabled": to.BoolString(agentPoolAgent.Enabled),
196+
"status": agentPoolAgent.Status,
197+
"hasAssignedRequest": to.BoolString(agentPoolAgent.AssignedRequest.RequestId > 0),
196198
}
197199

198200
agentPoolAgentMetric.Add(infoLabels, 1)

0 commit comments

Comments
 (0)