Skip to content

Commit 6e53b81

Browse files
feat: Monitor document cache (#47)
- also update to new networking v1 for ingress fixes #17 Signed-off-by: Ricky Moorhouse <[email protected]>
1 parent 5988d1b commit 6e53b81

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

datapower_net.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ def gather_metrics(self):
200200
self.fetch_data('TCPSummary', 'tcp', '_total')
201201
self.fetch_data('LogTargetStatus', 'logtarget')
202202
self.object_counts()
203+
self.fetch_document_cache_summary()
203204
if self.v5c:
204205
self.fetch_data('WSMAgentStatus', 'wsm')
205206
# Needs statistics enabled:
@@ -278,6 +279,46 @@ def object_counts(self):
278279
logger.info("Failed to get object count: {} (Check rest-mgmt is enabled and you have network connectivity)".format(e.strerror))
279280

280281

282+
def fetch_document_cache_summary(self, suffix=''):
283+
""" fetch data from a status provider """
284+
if self.v5c:
285+
provider = "DocumentCachingSummary"
286+
key = "XMLManager"
287+
else:
288+
provider = "APIDocumentCachingSummary"
289+
key = "APIGateway"
290+
try:
291+
logger.debug("Retrieving cache summary")
292+
url = "https://{}:{}/mgmt/status/{}/{}".format(
293+
self.ip,
294+
self.port,
295+
self.domain,
296+
provider)
297+
status = requests.get(url,
298+
auth=(self.username, self.password),
299+
verify=False, timeout=1).json()
300+
logger.debug(status)
301+
data = status.get(provider, {})
302+
if type(data) is not list:
303+
data = [data]
304+
305+
for item in data:
306+
try:
307+
name = item[key]['value']
308+
if name in ['webapi', 'webapi-internal', 'apiconnect']:
309+
del item[key]
310+
logger.debug(item)
311+
for key in item:
312+
self.trawler.set_gauge(
313+
'datapower',
314+
"{}.{}.{}{}".format("documentcache", name, key, suffix), item[key],
315+
pod_name=self.name, labels=self.labels)
316+
except KeyError:
317+
logger.warning('Failed to parse response for document cache summary')
318+
logger.info(item)
319+
except requests.exceptions.RequestException as e:
320+
logger.info("{}: {} (Check rest-mgmt is enabled and you have network connectivity)".format(provider, e.strerror))
321+
281322

282323

283324
# https://localhost:5554/mgmt/status/apiconnect/GatewayPeeringStatus

manager_net.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ def find_hostname(self):
9898
if self.use_kubeconfig:
9999
logger.info("Using KUBECONFIG")
100100
config.load_kube_config()
101-
v1beta = client.ExtensionsV1beta1Api()
102-
ingresslist = v1beta.list_namespaced_ingress(namespace=self.namespace)
101+
netv1 = client.NetworkingV1Api()
102+
ingresslist = netv1.list_namespaced_ingress(namespace=self.namespace)
103103
for ing in ingresslist.items:
104104
if ing.metadata.name.endswith('apiconnect-api') or ing.metadata.name.endswith('platform-api'):
105105
logger.info("Identified ingress host: {}".format(ing.spec.rules[0].host))

0 commit comments

Comments
 (0)