Multiple Clusters Monitoring from one container

This commit is contained in:
Tushar D 2021-04-21 15:17:49 -07:00
Родитель 0cf47c2faf
Коммит c7ebb2b69a
1 изменённых файлов: 19 добавлений и 18 удалений

Просмотреть файл

@ -14,7 +14,7 @@ from applicationinsights.exceptions import enable
from influxdb import InfluxDBClient from influxdb import InfluxDBClient
from datetime import datetime from datetime import datetime
API_URL = os.getenv('API_URL', "http://localhost:8080/nifi-api/") # complete api-endpoint API_URL = os.getenv('API_URL', "http://localhost:8080/nifi-api/").split(',') # Comma separated list of nifi cluster api urls in case of multiple clusters.
ENDPOINT_LIST = os.getenv('ENDPOINT_LIST', "controller/cluster,flow/cluster/summary,flow/process-groups/root,flow/status,counters,system-diagnostics?nodewise=true").split(',') ENDPOINT_LIST = os.getenv('ENDPOINT_LIST', "controller/cluster,flow/cluster/summary,flow/process-groups/root,flow/status,counters,system-diagnostics?nodewise=true").split(',')
MODE = os.getenv('MODE', "unlimited") # In limited mode, only NUMBEROFITERATIONS API calls are made before exiting. MODE = os.getenv('MODE', "unlimited") # In limited mode, only NUMBEROFITERATIONS API calls are made before exiting.
NUMBER_OF_ITERATIONS = int(os.getenv('NUMBER_OF_ITERATIONS', 2)) NUMBER_OF_ITERATIONS = int(os.getenv('NUMBER_OF_ITERATIONS', 2))
@ -133,23 +133,24 @@ def match_key(ignorelist, value):
while conditions[MODE](): while conditions[MODE]():
try: try:
for ENDPOINT in ENDPOINT_LIST: for AURL in API_URL:
r = requests.get(url=API_URL + ENDPOINT) if SECURE == False else get(url=API_URL + ENDPOINT, headers={ for ENDPOINT in ENDPOINT_LIST:
'Content-Type': 'application/json'}, verify=False, pkcs12_filename=CERT_FILE, pkcs12_password=CERT_PASS) r = requests.get(url=AURL + ENDPOINT) if SECURE == False else get(url=AURL + ENDPOINT, headers={
received_response = r.json() 'Content-Type': 'application/json'}, verify=False, pkcs12_filename=CERT_FILE, pkcs12_password=CERT_PASS)
flat_response = flattening(received_response, "", []) received_response = r.json()
current_time = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ') flat_response = flattening(received_response, "", [])
points = [{ current_time = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
"measurement": ENDPOINT, points = [{
"tags": {'APIURL':API_URL}, "measurement": ENDPOINT,
"time": current_time, "tags": {'APIURL':AURL},
"fields": flat_response "time": current_time,
}] "fields": flat_response
logger.info(ENDPOINT, extra=received_response) }]
iclient.write_points(points) logger.info(ENDPOINT, extra=received_response)
if IKEY != "REPLACE_ME": iclient.write_points(points)
handler.flush() if IKEY != "REPLACE_ME":
count += 1 handler.flush()
count += 1
except Exception as e: except Exception as e:
# this will send an exception to the Application Insights Logs # this will send an exception to the Application Insights Logs
logging.exception("Code ran into an unforseen exception!", sys.exc_info()[0]) logging.exception("Code ran into an unforseen exception!", sys.exc_info()[0])