mirror of
https://github.com/recklessop/Zerto_Exporter.git
synced 2026-07-06 01:03:14 -04:00
Update python-node-exporter.py
Testing ChatGPT generated optimizations which will make sure that the various stats gathering threads will be restarted if they crash
This commit is contained in:
+24
-20
@@ -359,23 +359,6 @@ def GetDataFunc():
|
|||||||
log.debug("Waiting 1 second for Auth Token")
|
log.debug("Waiting 1 second for Auth Token")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
#-------Start function to maintain ZVM Authentication---------
|
|
||||||
# run ZvmAuthHandler func in the background
|
|
||||||
background_thread = Thread(target = ZvmAuthHandler)
|
|
||||||
background_thread.start()
|
|
||||||
|
|
||||||
|
|
||||||
#-----------------Start Data collector Thread-----------------
|
|
||||||
# run GetDataFunc func in the background
|
|
||||||
background_thread = Thread(target = GetDataFunc)
|
|
||||||
background_thread.start()
|
|
||||||
|
|
||||||
#-----------------Start Data collector Thread-----------------
|
|
||||||
# run GetDataFunc func in the background
|
|
||||||
background_thread = Thread(target = GetStatsFunc)
|
|
||||||
background_thread.start()
|
|
||||||
|
|
||||||
#----------------run http server on port 9999-----------------
|
#----------------run http server on port 9999-----------------
|
||||||
def WebServer():
|
def WebServer():
|
||||||
PORT = 9999
|
PORT = 9999
|
||||||
@@ -386,6 +369,27 @@ def WebServer():
|
|||||||
print("serving at port", PORT)
|
print("serving at port", PORT)
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|
||||||
# run WebServer func in the background
|
def start_thread(target_func):
|
||||||
background_thread = Thread(target = WebServer)
|
# start a new thread
|
||||||
background_thread.start()
|
thread = threading.Thread(target=target_func)
|
||||||
|
thread.start()
|
||||||
|
# return the thread object
|
||||||
|
return thread
|
||||||
|
|
||||||
|
# start the threads
|
||||||
|
auth_thread = start_thread(ZvmAuthHandler)
|
||||||
|
data_thread = start_thread(GetDataFunc)
|
||||||
|
stats_thread = start_thread(GetStatsFunc)
|
||||||
|
|
||||||
|
# loop indefinitely
|
||||||
|
while True:
|
||||||
|
# check if any thread has crashed
|
||||||
|
if not auth_thread.is_alive():
|
||||||
|
# restart the thread
|
||||||
|
auth_thread = start_thread(ZvmAuthHandler)
|
||||||
|
if not data_thread.is_alive():
|
||||||
|
# restart the thread
|
||||||
|
data_thread = start_thread(GetDataFunc)
|
||||||
|
if not stats_thread.is_alive():
|
||||||
|
# restart the thread
|
||||||
|
stats_thread = start_thread(GetStatsFunc)
|
||||||
|
|||||||
Reference in New Issue
Block a user