@@ -15,6 +15,7 @@ type MetricsCollectorAgentPool struct {
1515 agentPoolAgent * prometheus.GaugeVec
1616 agentPoolAgentStatus * prometheus.GaugeVec
1717 agentPoolAgentJob * prometheus.GaugeVec
18+ agentPoolQueueLength * prometheus.GaugeVec
1819 }
1920}
2021
@@ -89,11 +90,22 @@ func (m *MetricsCollectorAgentPool) Setup(collector *CollectorAgentPool) {
8990 },
9091 )
9192
93+ m .prometheus .agentPoolQueueLength = prometheus .NewGaugeVec (
94+ prometheus.GaugeOpts {
95+ Name : "azure_devops_agentpool_queue_length" ,
96+ Help : "Azure DevOps agentpool" ,
97+ },
98+ []string {
99+ "agentPoolID" ,
100+ },
101+ )
102+
92103 prometheus .MustRegister (m .prometheus .agentPool )
93104 prometheus .MustRegister (m .prometheus .agentPoolSize )
94105 prometheus .MustRegister (m .prometheus .agentPoolAgent )
95106 prometheus .MustRegister (m .prometheus .agentPoolAgentStatus )
96107 prometheus .MustRegister (m .prometheus .agentPoolAgentJob )
108+ prometheus .MustRegister (m .prometheus .agentPoolQueueLength )
97109}
98110
99111func (m * MetricsCollectorAgentPool ) Reset () {
@@ -102,6 +114,7 @@ func (m *MetricsCollectorAgentPool) Reset() {
102114 m .prometheus .agentPoolAgent .Reset ()
103115 m .prometheus .agentPoolAgentStatus .Reset ()
104116 m .prometheus .agentPoolAgentJob .Reset ()
117+ m .prometheus .agentPoolQueueLength .Reset ()
105118}
106119
107120func (m * MetricsCollectorAgentPool ) Collect (ctx context.Context , callback chan <- func ()) {
@@ -111,6 +124,7 @@ func (m *MetricsCollectorAgentPool) Collect(ctx context.Context, callback chan<-
111124
112125 for _ , agentPoolId := range m .CollectorReference .AgentPoolIdList {
113126 m .collectAgentQueues (ctx , callback , agentPoolId )
127+ m .collectAgentPoolJobs (ctx , callback , agentPoolId )
114128 }
115129}
116130
@@ -185,7 +199,7 @@ func (m *MetricsCollectorAgentPool) collectAgentQueues(ctx context.Context, call
185199 "definitionName" : agentPoolAgent .AssignedRequest .Definition .Name ,
186200 "scopeID" : agentPoolAgent .AssignedRequest .ScopeId ,
187201 }
188- agentPoolAgentJobMetric .Add (jobLabels , timeToFloat64 (agentPoolAgent .AssignedRequest .AssignTime ))
202+ agentPoolAgentJobMetric .Add (jobLabels , timeToFloat64 (* agentPoolAgent .AssignedRequest .AssignTime ))
189203 }
190204 }
191205
@@ -195,3 +209,31 @@ func (m *MetricsCollectorAgentPool) collectAgentQueues(ctx context.Context, call
195209 agentPoolAgentJobMetric .GaugeSet (m .prometheus .agentPoolAgentJob )
196210 }
197211}
212+
213+ func (m * MetricsCollectorAgentPool ) collectAgentPoolJobs (ctx context.Context , callback chan <- func (), agentPoolId int64 ) {
214+ list , err := AzureDevopsClient .ListAgentPoolJobs (agentPoolId )
215+ if err != nil {
216+ Logger .Errorf ("agentpool[%v]call[ListAgentJobs]: %v" , agentPoolId , err )
217+ return
218+ }
219+
220+ agentPoolQueueLengthMetric := NewMetricCollectorList ()
221+
222+ notStartedJobCount := 0
223+
224+ for _ , agentPoolJob := range list .List {
225+ if agentPoolJob .AssignTime == nil {
226+ notStartedJobCount ++
227+ }
228+ }
229+
230+ infoLabels := prometheus.Labels {
231+ "agentPoolID" : int64ToString (agentPoolId ),
232+ }
233+
234+ agentPoolQueueLengthMetric .Add (infoLabels , float64 (notStartedJobCount ))
235+
236+ callback <- func () {
237+ agentPoolQueueLengthMetric .GaugeSet (m .prometheus .agentPoolQueueLength )
238+ }
239+ }
0 commit comments