@@ -146,6 +146,16 @@ type APIDocumentCachingSummaryResponse struct {
146
146
}
147
147
}
148
148
149
+ // Response from the /mgmt/status/{domain}/ObjectInstanceCounts endpoint
150
+ // of the DataPower REST Management Interface.
151
+ type ObjectInstanceCountsResponse struct {
152
+ Links Links `json:"_links"`
153
+ ObjectInstanceCounts []struct {
154
+ Class string
155
+ Count uint64
156
+ }
157
+ }
158
+
149
159
// Response from the /mgmt/status/{domain}/AnalyticsEndpointStatus2 endpoint of
150
160
// the DataPower REST Management Interface.
151
161
type AnalyticsEndpointStatus2Response struct {
@@ -234,6 +244,9 @@ func (d *DataPower) registerMetrics() {
234
244
// User defined policies Status
235
245
d .metrics ["user_defined_policies_info" ] = promauto .NewGaugeVec (prometheus.GaugeOpts {Name : "datapower_user_defined_policies_info" }, []string {"pod" , "namespace" , "policy" , "version" })
236
246
247
+ // Object count
248
+ d .metrics ["object_count" ] = promauto .NewGaugeVec (prometheus.GaugeOpts {Name : "datapower_object_count_total" }, []string {"pod" , "namespace" , "type" })
249
+
237
250
// Invoke API Tests
238
251
d .metrics ["invoke_api_size" ] = promauto .NewGaugeVec (prometheus.GaugeOpts {Name : "datapower_invoke_api_size" , Help : "invoke response content length" }, []string {"pod" , "namespace" , "name" })
239
252
d .metrics ["invoke_api_time" ] = promauto .NewGaugeVec (prometheus.GaugeOpts {Name : "datapower_invoke_api_time" , Help : "invoke time taken in ms" }, []string {"pod" , "namespace" , "name" })
@@ -265,9 +278,9 @@ func (d *DataPower) findGW(dynamicClient dynamic.DynamicClient) error {
265
278
log .Log (alog .ERROR , "Failed to list pods: %v" , err )
266
279
return err
267
280
}
268
-
281
+ log . Log ( alog . TRACE , "pods found: " , len ( pods . Items ))
269
282
for _ , pod := range pods .Items {
270
- log .Log (alog .TRACE , "pod name: %v" , pod .Name )
283
+ log .Log (alog .DEBUG , "pod name: %v" , pod .Name )
271
284
var V5Compatible bool
272
285
//Check for APICONNECT_V5_COMPAT_MODE set to on
273
286
for _ , env := range pod .Spec .Containers [0 ].Env {
@@ -277,6 +290,7 @@ func (d *DataPower) findGW(dynamicClient dynamic.DynamicClient) error {
277
290
}
278
291
}
279
292
ip := pod .Status .PodIP
293
+ log .Log (alog .DEBUG , "Pod IP is " , ip )
280
294
if d .Config .Host != "" {
281
295
log .Log (alog .TRACE , "Overriding host from %s to %s" , ip , d .Config .Host )
282
296
ip = d .Config .Host
@@ -288,8 +302,7 @@ func (d *DataPower) findGW(dynamicClient dynamic.DynamicClient) error {
288
302
d .gatewayPeeringStatus (ip , pod .Name , pod .Namespace )
289
303
d .openTelemetryExporterStatus (ip , pod .Name , pod .Namespace )
290
304
d .apiConnectGatewayServiceStatus (ip , pod .Name , pod .Namespace )
291
- // Still to do:
292
- // - Object Counts
305
+ d .objectCounts (ip , pod .Name , pod .Namespace )
293
306
if V5Compatible {
294
307
// - [v5c] WSMAgentStatus
295
308
// - [v5c] Cache Summary
@@ -413,6 +426,35 @@ func (d *DataPower) firmwareVersion(ip string, podName string, podNamespace stri
413
426
d .metrics ["version" ].WithLabelValues (podName , podNamespace , fw .FirmwareVersion3 .Version , fw .FirmwareVersion3 .Build ).Set (1.0 )
414
427
}
415
428
429
+ // *DataPower.objectCounts makes a request to the ObjectInstanceCounts endpoint
430
+ // and stores the resulting values to their matching *prometheus.GaugeVec items
431
+ // in the *DataPower.metrics map.
432
+ func (d * DataPower ) objectCounts (ip string , podName string , podNamespace string ) {
433
+ log .Log (alog .TRACE , "Entering objectCounts(%s, %s, %s)" , ip , podName , podNamespace )
434
+ response , err := d .invokeRestMgmt (ip , "mgmt/status/apiconnect/ObjectInstanceCounts" )
435
+ if err != nil {
436
+ log .Log (alog .ERROR , err .Error ())
437
+ return
438
+ }
439
+
440
+ var oc ObjectInstanceCountsResponse
441
+ err = json .NewDecoder (response .Body ).Decode (& oc )
442
+ if err != nil {
443
+ log .Log (alog .ERROR , err .Error ())
444
+ }
445
+ err2 := response .Body .Close ()
446
+ if err2 != nil {
447
+ log .Log (alog .ERROR , err2 .Error ())
448
+ }
449
+ // Loop through the response array and publish metrics
450
+ for _ , ocdata := range oc .ObjectInstanceCounts {
451
+ d .metrics ["object_count" ].WithLabelValues (podName , podNamespace , ocdata .Class ).Set (float64 (ocdata .Count ))
452
+ }
453
+ if err != nil || err2 != nil {
454
+ return
455
+ }
456
+ }
457
+
416
458
// *DataPower.logTargetStatus makes a request to the LogTargetStatus endpoint
417
459
// and stores the resulting values to their matching *prometheus.GaugeVec items
418
460
// in the *DataPower.metrics map.
0 commit comments