Skip to content

Commit 94eebc8

Browse files
custom health metrics
1 parent da0e933 commit 94eebc8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

apiconnect_net.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ class APIConnectNet(object):
1212
namespace = 'apic-management'
1313
use_kubeconfig = False
1414
trawler = None
15+
health_prefix = "apiconnect"
1516

1617
def __init__(self, config, trawler):
1718
# Takes in config object and trawler instance it's behind
1819
# Use kubeconfig or in-cluster config for k8s comms
1920
# self.use_kubeconfig = trawler.use_kubeconfig
2021
# Namespace to find CRs
2122
self.namespace = config.get('namespace', 'default')
23+
self.health_prefix = config.get('health_prefix', 'apiconnect')
24+
self.health_label = config.get('health_label', {})
2225
self.trawler = trawler
2326
self.use_kubeconfig = trawler.use_kubeconfig
2427

@@ -45,6 +48,20 @@ def fish(self):
4548
customResource['plural'])
4649
for item in api_response['items']:
4750
for condition in item['status']['conditions']:
51+
if condition['type'] == 'Ready':
52+
if condition['status']:
53+
health = 1
54+
else:
55+
health = 0
56+
self.trawler.set_gauge(
57+
self.health_prefix,
58+
"health_status",
59+
health,
60+
labels={
61+
"component": "{} {}".format(customResource['plural'][:-1], item['metadata']['name']),
62+
**self.health_label
63+
})
64+
4865
self.trawler.set_gauge(
4966
'apiconnect',
5067
"{}_status".format(customResource['plural']),

0 commit comments

Comments
 (0)