mirror of
https://github.com/recklessop/Zerto_Exporter.git
synced 2026-07-05 16:53:14 -04:00
Update python-node-exporter.py
added exception handling to data collection function
This commit is contained in:
@@ -332,9 +332,16 @@ def GetDataFunc():
|
|||||||
## VMs API
|
## VMs API
|
||||||
log.debug("Getting VMs API")
|
log.debug("Getting VMs API")
|
||||||
uri = "https://" + zvm_url + ":" + zvm_port + "/v1/vms/"
|
uri = "https://" + zvm_url + ":" + zvm_port + "/v1/vms/"
|
||||||
vmapi = requests.get(url=uri, timeout=api_timeout, headers=h2, verify=verifySSL)
|
|
||||||
vmapi_json = vmapi.json()
|
try:
|
||||||
#log.debug(vmapi_json)
|
vmapi = requests.get(url=uri, timeout=3, headers=h2, verify=verifySSL)
|
||||||
|
vmapi_json = vmapi.json()
|
||||||
|
except Exception as e:
|
||||||
|
log.error("Error while sending api request: " + str(e))
|
||||||
|
VMName = "Unknown"
|
||||||
|
return
|
||||||
|
|
||||||
|
log.debug("Got VMs API")
|
||||||
for vm in vmapi_json :
|
for vm in vmapi_json :
|
||||||
metricsDictionary["vm_actualrpo{VmIdentifier=\"" + vm['VmIdentifier'] + "\",VmName=\"" + vm['VmName'] + "\",VmRecoveryVRA=\"" + vm["RecoveryHostName"] + "\",VmPriority=\"" + str(vm['Priority']) + "\",SiteIdentifier=\"" + siteId + "\",SiteName=\"" + siteName + "\"}"] = vm["ActualRPO"]
|
metricsDictionary["vm_actualrpo{VmIdentifier=\"" + vm['VmIdentifier'] + "\",VmName=\"" + vm['VmName'] + "\",VmRecoveryVRA=\"" + vm["RecoveryHostName"] + "\",VmPriority=\"" + str(vm['Priority']) + "\",SiteIdentifier=\"" + siteId + "\",SiteName=\"" + siteName + "\"}"] = vm["ActualRPO"]
|
||||||
metricsDictionary["vm_throughput_in_mb{VmIdentifier=\"" + vm['VmIdentifier'] + "\",VmName=\"" + vm['VmName'] + "\",VmRecoveryVRA=\"" + vm["RecoveryHostName"] + "\",VmPriority=\"" + str(vm['Priority']) + "\",SiteIdentifier=\"" + siteId + "\",SiteName=\"" + siteName + "\"}"] = vm["ThroughputInMB"]
|
metricsDictionary["vm_throughput_in_mb{VmIdentifier=\"" + vm['VmIdentifier'] + "\",VmName=\"" + vm['VmName'] + "\",VmRecoveryVRA=\"" + vm["RecoveryHostName"] + "\",VmPriority=\"" + str(vm['Priority']) + "\",SiteIdentifier=\"" + siteId + "\",SiteName=\"" + siteName + "\"}"] = vm["ThroughputInMB"]
|
||||||
@@ -351,9 +358,16 @@ def GetDataFunc():
|
|||||||
## Volumes API for Scratch Volumes
|
## Volumes API for Scratch Volumes
|
||||||
log.debug("Getting Scratch Volumes")
|
log.debug("Getting Scratch Volumes")
|
||||||
uri = "https://" + zvm_url + ":" + zvm_port + "/v1/volumes?volumeType=scratch"
|
uri = "https://" + zvm_url + ":" + zvm_port + "/v1/volumes?volumeType=scratch"
|
||||||
volapi = requests.get(url=uri, timeout=api_timeout, headers=h2, verify=verifySSL)
|
|
||||||
volapi_json = volapi.json()
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
volapi = requests.get(url=uri, timeout=api_timeout, headers=h2, verify=verifySSL)
|
||||||
|
volapi_json = volapi.json()
|
||||||
|
except Exception as e:
|
||||||
|
log.error("Error while sending api request: " + str(e))
|
||||||
|
VMName = "Unknown"
|
||||||
|
return
|
||||||
|
|
||||||
|
log.debug("Got Scratch Volumes API")
|
||||||
if(bool(volapi_json)):
|
if(bool(volapi_json)):
|
||||||
for volume in volapi_json :
|
for volume in volapi_json :
|
||||||
#metricsDictionary["scratch_volume_provisioned_size_in_bytes{ProtectedVm=\"" + volume['ProtectedVm']['Name'] + "\", ProtectedVmIdentifier=\"" + volume['ProtectedVm']['Identifier'] + "\", OwningVRA=\"" + volume['OwningVm']['Name'] + "\"}"] = volume["Size"]["ProvisionedInBytes"]
|
#metricsDictionary["scratch_volume_provisioned_size_in_bytes{ProtectedVm=\"" + volume['ProtectedVm']['Name'] + "\", ProtectedVmIdentifier=\"" + volume['ProtectedVm']['Identifier'] + "\", OwningVRA=\"" + volume['OwningVm']['Name'] + "\"}"] = volume["Size"]["ProvisionedInBytes"]
|
||||||
@@ -369,10 +383,17 @@ def GetDataFunc():
|
|||||||
|
|
||||||
## Volumes API for Journal Volumes
|
## Volumes API for Journal Volumes
|
||||||
log.debug("Getting Journal Volumes")
|
log.debug("Getting Journal Volumes")
|
||||||
uri = "https://" + zvm_url + ":" + zvm_port + "/v1/volumes?volumeType=journal"
|
|
||||||
volapi = requests.get(url=uri, timeout=api_timeout, headers=h2, verify=verifySSL)
|
|
||||||
volapi_json = volapi.json()
|
|
||||||
|
|
||||||
|
uri = "https://" + zvm_url + ":" + zvm_port + "/v1/volumes?volumeType=journal"
|
||||||
|
try:
|
||||||
|
volapi = requests.get(url=uri, timeout=api_timeout, headers=h2, verify=verifySSL)
|
||||||
|
volapi_json = volapi.json()
|
||||||
|
except Exception as e:
|
||||||
|
log.error("Error while sending api request: " + str(e))
|
||||||
|
VMName = "Unknown"
|
||||||
|
return
|
||||||
|
|
||||||
|
log.debug("Got Journal Volumes API")
|
||||||
if(bool(volapi_json)):
|
if(bool(volapi_json)):
|
||||||
log.debug("Journal Volumes Exist")
|
log.debug("Journal Volumes Exist")
|
||||||
for volume in volapi_json :
|
for volume in volapi_json :
|
||||||
@@ -631,7 +652,7 @@ webserver_thread = start_thread(WebServer)
|
|||||||
# loop indefinitely
|
# loop indefinitely
|
||||||
while True:
|
while True:
|
||||||
# check if any thread has crashed
|
# check if any thread has crashed
|
||||||
sleep(2)
|
sleep(10)
|
||||||
if not probe_thread.is_alive():
|
if not probe_thread.is_alive():
|
||||||
# restart the thread
|
# restart the thread
|
||||||
log.error("Probe Thread Died - Restarting")
|
log.error("Probe Thread Died - Restarting")
|
||||||
|
|||||||
Reference in New Issue
Block a user