mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2025-06-28 01:07:03 +00:00
Update API address and add delay before the first query
This commit is contained in:
parent
07a806a073
commit
e4a1d715ec
@ -9,7 +9,7 @@ import subprocess
|
|||||||
|
|
||||||
# Global variables
|
# Global variables
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
API_ADDRESS = "http://127.0.0.1:8000"
|
API_ADDRESS = "http://wireguard-webadmin:8000"
|
||||||
|
|
||||||
# Base directory for storing RRD files
|
# Base directory for storing RRD files
|
||||||
RRD_DATA_PATH = "/rrd_data"
|
RRD_DATA_PATH = "/rrd_data"
|
||||||
@ -170,6 +170,7 @@ def main_loop():
|
|||||||
Main loop that:
|
Main loop that:
|
||||||
- Ensures the necessary directories exist
|
- Ensures the necessary directories exist
|
||||||
- Retrieves the API key (terminating the script if invalid)
|
- Retrieves the API key (terminating the script if invalid)
|
||||||
|
- Waits 30 seconds before the first query
|
||||||
- Queries the wireguard status API every 5 minutes
|
- Queries the wireguard status API every 5 minutes
|
||||||
- Processes each peer using process_peer()
|
- Processes each peer using process_peer()
|
||||||
- Aggregates total tx and rx per interface and updates the corresponding instance RRD
|
- Aggregates total tx and rx per interface and updates the corresponding instance RRD
|
||||||
@ -185,6 +186,9 @@ def main_loop():
|
|||||||
print("API key not found or invalid. Exiting.")
|
print("API key not found or invalid. Exiting.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
debug_log("Waiting 30 seconds before first query...")
|
||||||
|
time.sleep(30)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
loop_start = time.time()
|
loop_start = time.time()
|
||||||
# Refresh the API key on every iteration in case the file changes
|
# Refresh the API key on every iteration in case the file changes
|
||||||
@ -202,8 +206,7 @@ def main_loop():
|
|||||||
data = response.json()
|
data = response.json()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
debug_log("Error fetching or parsing API data: " + str(e))
|
debug_log("Error fetching or parsing API data: " + str(e))
|
||||||
elapsed = time.time() - loop_start
|
time.sleep(30)
|
||||||
time.sleep(max(300 - elapsed, 0))
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Process each interface and its peers, aggregate tx and rx for the interface
|
# Process each interface and its peers, aggregate tx and rx for the interface
|
||||||
|
Loading…
x
Reference in New Issue
Block a user