mirror of
https://github.com/recklessop/Zerto_Exporter.git
synced 2026-07-05 00:43:13 -04:00
vpg and vm data
metric exporter for VPG and VM data to prometheus
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 67 KiB |
+46
-29
@@ -3,49 +3,69 @@ import http.server
|
|||||||
import socketserver
|
import socketserver
|
||||||
import time
|
import time
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
||||||
|
from requests.structures import CaseInsensitiveDict
|
||||||
|
|
||||||
|
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
||||||
|
verifySSL = False
|
||||||
|
zvm_url = "192.168.52.30"
|
||||||
|
zvm_port = "443"
|
||||||
|
|
||||||
def GetDataFunc():
|
def GetDataFunc():
|
||||||
while True :
|
while True :
|
||||||
|
h = CaseInsensitiveDict()
|
||||||
|
h["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
|
||||||
#----------------------------------------------------------------------------------
|
d = CaseInsensitiveDict()
|
||||||
#----------------------------------------------------------------------------------
|
d["client_id"] = "my-script-client"
|
||||||
# in this part, i'll get some data from an API
|
d["client_secret"] = "c2c117be-504d-41f7-b29f-29fcaee6682a"
|
||||||
#
|
d["grant_type"] = "client_credentials"
|
||||||
# and put it into "metricsDictionary"
|
|
||||||
#
|
response = requests.post('https://192.168.52.30/auth/realms/zerto/protocol/openid-connect/token', data=d, headers=h, verify=verifySSL)
|
||||||
# you can remove this part and add your own script
|
|
||||||
#
|
token = response.json()
|
||||||
# (put your key/value items into "metricsDictionary")
|
|
||||||
#----------------------------------------------------------------------------------
|
h2 = CaseInsensitiveDict()
|
||||||
#----------------------------------------------------------------------------------
|
h2["Accept"] = "application/json"
|
||||||
|
h2["Authorization"] = "Bearer " + token['access_token']
|
||||||
service = requests.get("https://api.coindesk.com/v1/bpi/currentprice.json",timeout=3)
|
|
||||||
|
service = requests.get("https://192.168.52.30/v1/vpgs/",timeout=3, headers=h2, verify=verifySSL)
|
||||||
service_json = service.json()
|
service_json = service.json()
|
||||||
|
|
||||||
metricsDictionary = {}
|
metricsDictionary = {}
|
||||||
metricsDictionary["Bitcoin_USD: "] = service_json["bpi"]["USD"]["rate"].replace(",", "")
|
for vpg in service_json :
|
||||||
metricsDictionary["Bitcoin_EUR: "] = service_json["bpi"]["EUR"]["rate"].replace(",", "")
|
metricsDictionary["vpg-storage-used-in-mb{VpgIdentifier=" + vpg['VpgIdentifier'] + ",VpgName=" + vpg['VpgName'] + "}"] = vpg["UsedStorageInMB"]
|
||||||
|
metricsDictionary["vpg-actual-rpo{VpgIdentifier=" + vpg['VpgIdentifier'] + ",VpgName=" + vpg['VpgName'] + "}"] = vpg["ActualRPO"]
|
||||||
|
metricsDictionary["vpg-throughput-in-mb{VpgIdentifier=" + vpg['VpgIdentifier'] + ",VpgName=" + vpg['VpgName'] + "}"] = vpg["ThroughputInMB"]
|
||||||
|
metricsDictionary["vpg-iops{VpgIdentifier=" + vpg['VpgIdentifier'] + ",VpgName=" + vpg['VpgName'] + "}"] = vpg["IOPs"]
|
||||||
|
metricsDictionary["vpg-provisioned-storage-in-mb{VpgIdentifier=" + vpg['VpgIdentifier'] + ",VpgName=" + vpg['VpgName'] + "}"] = vpg["ProvisionedStorageInMB"]
|
||||||
|
metricsDictionary["vpg-vms-count{VpgIdentifier=" + vpg['VpgIdentifier'] + ",VpgName=" + vpg['VpgName'] + "}"] = vpg["VmsCount"]
|
||||||
|
metricsDictionary["vpg-configured-rpo-seconds{VpgIdentifier=" + vpg['VpgIdentifier'] + ",VpgName=" + vpg['VpgName'] + "}"] = vpg["ConfiguredRpoSeconds"]
|
||||||
|
metricsDictionary["vpg-actual-history-in-minutes{VpgIdentifier=" + vpg['VpgIdentifier'] + ",VpgName=" + vpg['VpgName'] + "}"] = vpg["HistoryStatusApi"]["ActualHistoryInMinutes"]
|
||||||
|
metricsDictionary["vpg-configured-history-in-minutes{VpgIdentifier=" + vpg['VpgIdentifier'] + ",VpgName=" + vpg['VpgName'] + "}"] = vpg["HistoryStatusApi"]["ConfiguredHistoryInMinutes"]
|
||||||
|
|
||||||
|
vmapi = requests.get("https://192.168.52.30/v1/vms/",timeout=3, headers=h2, verify=verifySSL)
|
||||||
|
vmapi_json = vmapi.json()
|
||||||
|
|
||||||
|
for vm in vmapi_json :
|
||||||
|
metricsDictionary["vm-actual-rpo{VmName=" + vm['VmName'] + "}"] = vm["ActualRPO"]
|
||||||
|
metricsDictionary["vm-throughput-in-mb{VmName=" + vm['VmName'] + "}"] = vm["ThroughputInMB"]
|
||||||
|
metricsDictionary["vm-iops{VmName=" + vm['VmName'] + "}"] = vm["IOPs"]
|
||||||
|
metricsDictionary["vm-journal-used-storage-MB{VmName=" + vm['VmName'] + "}"] = vm["JournalUsedStorageMb"]
|
||||||
|
metricsDictionary["vm-outgoing-bandwidth-in-mbps{VmName=" + vm['VmName'] + "}"] = vm["OutgoingBandWidthInMbps"]
|
||||||
|
#metricsDictionary["vm-actual-rpo{VmName=" + vpg['VmName'] + "}"] = vm["actualRPO"]
|
||||||
|
|
||||||
#----------------------------------------------------------------------------------
|
|
||||||
#----------------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# Now, I'll put all key/value items of metricsDictionary into metrics.txt file
|
|
||||||
#
|
|
||||||
#----------------------------------------------------------------------------------
|
|
||||||
#----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# This function will get data every 5 seconds
|
# This function will get data every 5 seconds
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
# open file to write new data
|
# open file to write new data
|
||||||
file_object = open('metrics.txt', 'w')
|
file_object = open('metrics.txt', 'w')
|
||||||
|
|
||||||
for item in metricsDictionary :
|
for item in metricsDictionary :
|
||||||
file_object.write("\n")
|
file_object.write("\n")
|
||||||
file_object.write(item)
|
file_object.write(item)
|
||||||
file_object.write(metricsDictionary[item])
|
file_object.write(" ")
|
||||||
|
file_object.write(str(metricsDictionary[item]))
|
||||||
|
|
||||||
|
|
||||||
# run GetDataFunc func in the background
|
# run GetDataFunc func in the background
|
||||||
@@ -53,9 +73,6 @@ background_thread = Thread(target = GetDataFunc)
|
|||||||
background_thread.start()
|
background_thread.start()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#----------------run http server on port 9999-----------------
|
#----------------run http server on port 9999-----------------
|
||||||
|
|
||||||
def WebServer():
|
def WebServer():
|
||||||
@@ -70,4 +87,4 @@ def WebServer():
|
|||||||
|
|
||||||
# run WebServer func in the background
|
# run WebServer func in the background
|
||||||
background_thread = Thread(target = WebServer)
|
background_thread = Thread(target = WebServer)
|
||||||
background_thread.start()
|
background_thread.start()
|
||||||
Reference in New Issue
Block a user