Skip to content

Commit f7c5670

Browse files
fix: re-instate support for ObjectStatus for earlier DP (#63)
fixes #62 Signed-off-by: Ricky Moorhouse <[email protected]>
1 parent baacfe4 commit f7c5670

File tree

1 file changed

+48
-18
lines changed

1 file changed

+48
-18
lines changed

datapower_net.py

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def fish(self):
8080
for i in pods:
8181
# Use default port of 5554 if not annotated
8282
port = i.metadata.annotations.get('restPort', 5554)
83+
version = i.metadata.annotations.get('productVersion', '0')
8384
if self.use_kubeconfig:
8485
ip = '127.0.0.1'
8586
else:
@@ -98,7 +99,8 @@ def fish(self):
9899
username=self.username,
99100
password=password,
100101
trawler=self.trawler,
101-
api_tests=self.api_tests
102+
api_tests=self.api_tests,
103+
version=version
102104
)
103105
self.items[dp_key].gather_metrics()
104106
logger.info("DataPowers in list: {}".format(len(pods)))
@@ -122,10 +124,11 @@ class DataPower():
122124
apiPort = 9443
123125
trawler = None
124126
timeout = 1
127+
version = '0'
125128
api_tests = None
126129
labels = {}
127130

128-
def __init__(self, ip, port, name, namespace, username, password, trawler, api_tests=None, timeout=1):
131+
def __init__(self, ip, port, name, namespace, username, password, trawler, api_tests=None, timeout=1, version='0'):
129132
self.ip = ip
130133
self.port = port
131134
self.name = name
@@ -136,6 +139,7 @@ def __init__(self, ip, port, name, namespace, username, password, trawler, api_t
136139
self.get_info()
137140
self.trawler = trawler
138141
self.api_tests = api_tests
142+
self.version = version
139143
self.are_statistics_enabled()
140144
self.labels = {"namespace": self.namespace}
141145
logger.info('DataPower {} {} initialised at {}:{}'.format(self.name, self.v5c, self.ip, self.port))
@@ -259,23 +263,49 @@ def fetch_data(self, provider, label, suffix=''):
259263
# https://127.0.0.1:5554/mgmt/status/apiconnect/ObjectInstanceCounts
260264
def object_counts(self):
261265
""" Count objects within datapower domain """
262-
logger.info("Processing status provider ObjectInstanceCounts")
263-
try:
264-
url = "https://{}:{}/mgmt/status/{}/ObjectInstanceCounts".format(
265-
self.ip,
266-
self.port,
267-
self.domain)
268-
status = requests.get(url,
269-
auth=(self.username, self.password),
270-
verify=False,
271-
timeout=self.timeout).json()
272-
logger.debug(status)
273-
data = status.get('ObjectInstanceCounts', [])
274-
for item in data:
275-
self.trawler.set_gauge('datapower', "{}_total".format(item['Class']), item['Count'], pod_name=self.name, labels=self.labels)
266+
if self.version > '10.5.0.0':
267+
# Supports ObjectInstanceCounts - much quicker...
268+
logger.info("Processing status provider ObjectInstanceCounts")
269+
try:
270+
url = "https://{}:{}/mgmt/status/{}/ObjectInstanceCounts".format(
271+
self.ip,
272+
self.port,
273+
self.domain)
274+
status = requests.get(url,
275+
auth=(self.username, self.password),
276+
verify=False,
277+
timeout=self.timeout).json()
278+
logger.debug(status)
279+
data = status.get('ObjectInstanceCounts', [])
280+
for item in data:
281+
self.trawler.set_gauge('datapower', "{}_total".format(item['Class']), item['Count'], pod_name=self.name, labels=self.labels)
276282

277-
except requests.exceptions.RequestException as e:
278-
logger.info("Failed to get object count: {} (Check rest-mgmt is enabled and you have network connectivity)".format(e.strerror))
283+
except requests.exceptions.RequestException as e:
284+
logger.info("Failed to get object instance count: {} (Check rest-mgmt is enabled and you have network connectivity)".format(e.strerror))
285+
else:
286+
logger.info("Processing status provider ObjectStatus")
287+
try:
288+
url = "https://{}:{}/mgmt/status/{}/ObjectStatus".format(
289+
self.ip,
290+
self.port,
291+
self.domain)
292+
status = requests.get(url,
293+
auth=(self.username, self.password),
294+
verify=False, timeout=self.timeout).json()
295+
logger.debug(status)
296+
data = status.get('ObjectStatus', [])
297+
counts = {}
298+
for item in data:
299+
if item['Class'] in counts:
300+
counts[item['Class']] += 1
301+
else:
302+
counts[item['Class']] = 1
303+
for item_class in counts:
304+
self.trawler.set_gauge('datapower', "{}_total".format(item_class), counts[item_class], pod_name=self.name, labels=self.labels)
305+
306+
logger.debug(counts)
307+
except requests.exceptions.RequestException as e:
308+
logger.info("Failed to get object status: {} (Check rest-mgmt is enabled and you have network connectivity)".format(e.strerror))
279309

280310

281311
def fetch_document_cache_summary(self, suffix=''):

0 commit comments

Comments
 (0)