mirror of
https://github.com/recklessop/Zerto_Exporter.git
synced 2026-07-05 08:43:14 -04:00
exception handling and comments
This commit is contained in:
+18
-17
@@ -23,7 +23,7 @@ api_timeout = int(os.environ.get('API_TIMEOUT', 5))
|
|||||||
LOGLEVEL = os.environ.get('LOGLEVEL', 'INFO').upper()
|
LOGLEVEL = os.environ.get('LOGLEVEL', 'INFO').upper()
|
||||||
version = str(VERSION)
|
version = str(VERSION)
|
||||||
|
|
||||||
#log_formatter = logging.Formatter('%(relativeCreated)6d %(threadName)s %(message)s')
|
|
||||||
log_formatter = logging.Formatter("%(asctime)s;%(levelname)s;%(threadName)s;%(message)s", "%Y-%m-%d %H:%M:%S")
|
log_formatter = logging.Formatter("%(asctime)s;%(levelname)s;%(threadName)s;%(message)s", "%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
log_handler = RotatingFileHandler(filename='../logs/Log-Main.log', maxBytes=1024*1024*100, backupCount=5)
|
log_handler = RotatingFileHandler(filename='../logs/Log-Main.log', maxBytes=1024*1024*100, backupCount=5)
|
||||||
@@ -40,6 +40,7 @@ log.debug("Running with Variables:\nVerify SSL: " + str(verifySSL) + "\nZVM Host
|
|||||||
token = ""
|
token = ""
|
||||||
lastStats = CaseInsensitiveDict()
|
lastStats = CaseInsensitiveDict()
|
||||||
|
|
||||||
|
# Authentication Thread which handles authentication and token refresh for ZVM API
|
||||||
def ZvmAuthHandler():
|
def ZvmAuthHandler():
|
||||||
log.debug("ZVMAuthHandler Thread Started")
|
log.debug("ZVMAuthHandler Thread Started")
|
||||||
expiresIn = 0
|
expiresIn = 0
|
||||||
@@ -93,6 +94,7 @@ def ZvmAuthHandler():
|
|||||||
sleep(10)
|
sleep(10)
|
||||||
|
|
||||||
|
|
||||||
|
# Thread which gets VM level encryption statistics from ZVM API
|
||||||
def GetStatsFunc():
|
def GetStatsFunc():
|
||||||
tempdb = TinyDB(storage=MemoryStorage)
|
tempdb = TinyDB(storage=MemoryStorage)
|
||||||
dbvm = Query()
|
dbvm = Query()
|
||||||
@@ -130,16 +132,11 @@ def GetStatsFunc():
|
|||||||
VMName = "NA"
|
VMName = "NA"
|
||||||
|
|
||||||
oldvmdata = tempdb.search(dbvm.VmIdentifier == vm['VmIdentifier'])
|
oldvmdata = tempdb.search(dbvm.VmIdentifier == vm['VmIdentifier'])
|
||||||
#log.debug("+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_")
|
|
||||||
#log.debug("All Database")
|
|
||||||
#log.debug(tempdb.all())
|
|
||||||
#log.debug("+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_")
|
|
||||||
log.info("Checking TempDB for VM " + vm['VmIdentifier'])
|
log.info("Checking TempDB for VM " + vm['VmIdentifier'])
|
||||||
if (oldvmdata):
|
if (oldvmdata):
|
||||||
log.info(vm['VmIdentifier'] + " Record Found")
|
log.info(vm['VmIdentifier'] + " Record Found")
|
||||||
log.debug("_*_*_*_*_*_*_*_*")
|
|
||||||
log.debug(oldvmdata[0])
|
log.debug(oldvmdata[0])
|
||||||
log.debug("_*_*_*_*_*_*_*_*")
|
|
||||||
log.debug(tempdb.update(vm, dbvm.VmIdentifier == vm['VmIdentifier']))
|
log.debug(tempdb.update(vm, dbvm.VmIdentifier == vm['VmIdentifier']))
|
||||||
|
|
||||||
log.debug("!@!@!@!@!@ Stats !@!@!@!@!@")
|
log.debug("!@!@!@!@!@ Stats !@!@!@!@!@")
|
||||||
@@ -164,20 +161,23 @@ def GetStatsFunc():
|
|||||||
log.debug("CurrentPercentEncrypted " + str(CurrentPercentEncrypted))
|
log.debug("CurrentPercentEncrypted " + str(CurrentPercentEncrypted))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log.info(vm['VmIdentifier'] + " No Record Found")
|
log.info(vm['VmIdentifier'] + " No Record Found, Inserting into DB")
|
||||||
#insert original VM record to tempdb
|
#insert original VM record to tempdb
|
||||||
log.debug(tempdb.insert(vm))
|
log.debug(tempdb.insert(vm))
|
||||||
|
|
||||||
# update database with VM name, for easier display in Grafana Legends
|
# update database with VM name, for easier display in Grafana Legends
|
||||||
uri = "https://" + zvm_url + ":" + zvm_port + "/v1/vms/" + vm['VmIdentifier']
|
uri = "https://" + zvm_url + ":" + zvm_port + "/v1/vms/" + vm['VmIdentifier']
|
||||||
vapi = requests.get(url=uri, timeout=3, headers=h2, verify=verifySSL)
|
try:
|
||||||
vapi_json = vapi.json()
|
vapi = requests.get(url=uri, timeout=3, headers=h2, verify=verifySSL)
|
||||||
#log.debug("!@!@!@!@!@!@!@!@!@!@!@")
|
vapi_json = vapi.json()
|
||||||
#log.debug(vapi_json)
|
except Exception as e:
|
||||||
#log.debug("!@!@!@!@!@!@!@!@!@!@!@")
|
log.error("Error while sending api request: " + str(e))
|
||||||
tempdb.update({'VmName': vapi_json['VmName']}, dbvm.VmIdentifier == vm['VmIdentifier'])
|
VMName = "Unknown"
|
||||||
log.info(vm['VmIdentifier'] + " Added to temp vm db")
|
else:
|
||||||
VMName = vapi_json['VmName']
|
log.debug("vapi_json: " + str(vapi_json))
|
||||||
|
tempdb.update({'VmName': vapi_json['VmName']}, dbvm.VmIdentifier == vm['VmIdentifier'])
|
||||||
|
log.info("Added to temp vm db" + vm['VmIdentifier'] + " - " + vapi_json['VmName'])
|
||||||
|
VMName = vapi_json['VmName']
|
||||||
|
|
||||||
# Store Calculated Metrics
|
# Store Calculated Metrics
|
||||||
metricsDictionary["vm_IoOperationsCounter{VpgIdentifier=\"" + vm['VpgIdentifier'] + "\",VmIdentifier=\"" + vm['VmIdentifier'] + "\",VmName=\"" + VMName + "\"}"] = CurrentIops
|
metricsDictionary["vm_IoOperationsCounter{VpgIdentifier=\"" + vm['VpgIdentifier'] + "\",VmIdentifier=\"" + vm['VmIdentifier'] + "\",VmName=\"" + VMName + "\"}"] = CurrentIops
|
||||||
@@ -210,7 +210,7 @@ def GetStatsFunc():
|
|||||||
log.debug("Waiting 1 second for Auth Token")
|
log.debug("Waiting 1 second for Auth Token")
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
|
||||||
|
# Function which retrieves stats from various ZVM APIs and stores them in a metrics file
|
||||||
def GetDataFunc():
|
def GetDataFunc():
|
||||||
tempdb = TinyDB(storage=MemoryStorage)
|
tempdb = TinyDB(storage=MemoryStorage)
|
||||||
dbvm = Query()
|
dbvm = Query()
|
||||||
@@ -399,6 +399,7 @@ def GetDataFunc():
|
|||||||
log.debug("Waiting 1 second for Auth Token")
|
log.debug("Waiting 1 second for Auth Token")
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
|
||||||
|
# function which monitors the threads and restarts them if they die
|
||||||
def ThreadProbe():
|
def ThreadProbe():
|
||||||
while True:
|
while True:
|
||||||
log.debug("Thread Probe Started")
|
log.debug("Thread Probe Started")
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
# version.py
|
# version.py
|
||||||
VERSION = "1.0.0"
|
VERSION = "1.0.1"
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Put your main program code here
|
# Put your main program code here
|
||||||
|
|||||||
Reference in New Issue
Block a user