Development
This commit is contained in:
parent
836f4557f2
commit
46afed7965
2 changed files with 19 additions and 7 deletions
|
|
@ -34,6 +34,8 @@ import sys
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import mod_metrics as metrics
|
||||||
|
|
||||||
SCRIPT_DIR = Path(__file__).parent
|
SCRIPT_DIR = Path(__file__).parent
|
||||||
CONFIG_FILE = SCRIPT_DIR / "config.json"
|
CONFIG_FILE = SCRIPT_DIR / "config.json"
|
||||||
CACHE_SERVICE_FILE = SCRIPT_DIR / ".ddns-last-service"
|
CACHE_SERVICE_FILE = SCRIPT_DIR / ".ddns-last-service"
|
||||||
|
|
@ -650,5 +652,14 @@ def main():
|
||||||
rotate_radius_log(cfg.get("_radius", {}))
|
rotate_radius_log(cfg.get("_radius", {}))
|
||||||
refresh_arp_cache(cfg)
|
refresh_arp_cache(cfg)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(CONFIG_FILE) as f:
|
||||||
|
full_cfg = json.load(f)
|
||||||
|
new_metrics = metrics.collect_metrics(full_cfg)
|
||||||
|
if new_metrics:
|
||||||
|
metrics.update_metrics_file(new_metrics)
|
||||||
|
except Exception as e:
|
||||||
|
log.warning(f"DNS metrics collection failed: {e}")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@ and accumulates lifetime totals in a JSON file.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
@ -42,14 +44,13 @@ def collect_metrics(data):
|
||||||
|
|
||||||
any_running = False
|
any_running = False
|
||||||
for vlan in data["vlans"]:
|
for vlan in data["vlans"]:
|
||||||
svc = shared.vlan_service_name(vlan, validation.derive_interface(vlan, data))
|
pid_file = shared.vlan_pid_file(vlan)
|
||||||
result = subprocess.run(
|
try:
|
||||||
["systemctl", "kill", "--signal=SIGUSR1", svc],
|
pid = int(pid_file.read_text().strip())
|
||||||
capture_output=True, text=True
|
os.kill(pid, signal.SIGUSR1)
|
||||||
)
|
any_running = True
|
||||||
if result.returncode != 0:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
any_running = True
|
|
||||||
|
|
||||||
if not any_running:
|
if not any_running:
|
||||||
print("No dnsmasq instances are running.")
|
print("No dnsmasq instances are running.")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue