fix: handle errors gracefully in user count updates
Return False instead of 0 when fetching registered users fails, and skip updating the gauge if an error occurs. Improves error handling, avoiding misleading user count updates.
This commit is contained in:
parent
101cabb99b
commit
139a036dad
1 changed files with 3 additions and 2 deletions
|
@ -28,7 +28,7 @@ def fetch_registered_users(domain):
|
||||||
return int(match.group(1))
|
return int(match.group(1))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error fetching registered users from {domain}: {e}")
|
print(f"Error fetching registered users from {domain}: {e}")
|
||||||
return 0
|
return False
|
||||||
|
|
||||||
|
|
||||||
def update_registered_users(domains, update_interval):
|
def update_registered_users(domains, update_interval):
|
||||||
|
@ -36,7 +36,8 @@ def update_registered_users(domains, update_interval):
|
||||||
for domain in domains:
|
for domain in domains:
|
||||||
# Fetch the number of registered users and update the gauge
|
# Fetch the number of registered users and update the gauge
|
||||||
registered_users = fetch_registered_users(domain)
|
registered_users = fetch_registered_users(domain)
|
||||||
registered_users_gauge.labels(domain=domain).set(registered_users)
|
if registered_users:
|
||||||
|
registered_users_gauge.labels(domain=domain).set(registered_users)
|
||||||
# Sleep for a while before fetching the data again
|
# Sleep for a while before fetching the data again
|
||||||
time.sleep(update_interval)
|
time.sleep(update_interval)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue