v0.43.1
This commit is contained in:
1 parent
5b6d4a7903
commit
4d1087e357
160 files changed
+2407
-1933
No files matched your search
@@ -15,18 +15,15 @@ import urllib.request
|
||||
|
||||
OK, WARNING, CRITICAL, UNKNOWN = 0, 1, 2, 3
|
||||
|
||||
|
||||
class CheckError(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
def plugin_exit(state: int, message: str, perf: list[str] | None = None) -> None:
|
||||
names = {OK: "OK", WARNING: "WARNING", CRITICAL: "CRITICAL", UNKNOWN: "UNKNOWN"}
|
||||
suffix = f" | {' '.join(perf)}" if perf else ""
|
||||
print(f"RUSTPROXY {names[state]} - {message}{suffix}")
|
||||
raise SystemExit(state)
|
||||
|
||||
|
||||
def threshold(value: float, warning: float, critical: float) -> int:
|
||||
if value >= critical:
|
||||
return CRITICAL
|
||||
@@ -34,7 +31,6 @@ def threshold(value: float, warning: float, critical: float) -> int:
|
||||
return WARNING
|
||||
return OK
|
||||
|
||||
|
||||
class Client:
|
||||
def __init__(self, args: argparse.Namespace) -> None:
|
||||
self.base = args.url.rstrip("/")
|
||||
@@ -111,7 +107,6 @@ class Client:
|
||||
except urllib.error.HTTPError as error:
|
||||
raise CheckError(f"status endpoint returned HTTP {error.code} after login") from error
|
||||
|
||||
|
||||
def pools(status: dict, selected: list[str]) -> list[dict]:
|
||||
values = status.get("backend_pools") or []
|
||||
if not isinstance(values, list):
|
||||
@@ -125,7 +120,6 @@ def pools(status: dict, selected: list[str]) -> list[dict]:
|
||||
raise CheckError("unknown vhost/backend pool: " + ", ".join(sorted(missing)))
|
||||
return found
|
||||
|
||||
|
||||
def check_api(client: Client, args: argparse.Namespace) -> None:
|
||||
status, latency = client.status()
|
||||
state = threshold(latency, args.warning_ms, args.critical_ms)
|
||||
@@ -133,7 +127,6 @@ def check_api(client: Client, args: argparse.Namespace) -> None:
|
||||
uptime = status.get("uptime_seconds", "?")
|
||||
plugin_exit(state, f"API {latency:.1f} ms, revision {revision}, uptime {uptime}s", [f"api_ms={latency:.1f}ms;{args.warning_ms};{args.critical_ms};0"])
|
||||
|
||||
|
||||
def check_backends(client: Client, args: argparse.Namespace) -> None:
|
||||
status, api_ms = client.status()
|
||||
down: list[str] = []
|
||||
@@ -162,7 +155,6 @@ def check_backends(client: Client, args: argparse.Namespace) -> None:
|
||||
detail += "; checking: " + ", ".join(checking[:10])
|
||||
plugin_exit(state, detail, [f"up={up}", f"down={len(down)}", f"checking={len(checking)}", f"api_ms={api_ms:.1f}ms"])
|
||||
|
||||
|
||||
def check_latency(client: Client, args: argparse.Namespace) -> None:
|
||||
status, api_ms = client.status()
|
||||
samples: list[tuple[float, str]] = []
|
||||
@@ -184,7 +176,6 @@ def check_latency(client: Client, args: argparse.Namespace) -> None:
|
||||
state = threshold(value, args.warning_ms, args.critical_ms)
|
||||
plugin_exit(state, f"slowest backend {name}: {value:.1f} ms ({len(samples)} sampled)", [f"backend_ms={value:.1f}ms;{args.warning_ms};{args.critical_ms};0", f"api_ms={api_ms:.1f}ms"])
|
||||
|
||||
|
||||
def check_queues(client: Client, args: argparse.Namespace) -> None:
|
||||
status, api_ms = client.status()
|
||||
logs = int(status.get("logs_dropped") or 0)
|
||||
@@ -193,7 +184,6 @@ def check_queues(client: Client, args: argparse.Namespace) -> None:
|
||||
state = CRITICAL if total >= args.critical else WARNING if total >= args.warning else OK
|
||||
plugin_exit(state, f"dropped work: logs={logs}, cold-cache={cold}", [f"logs_dropped={logs};{args.warning};{args.critical};0", f"cold_queue_dropped={cold};{args.warning};{args.critical};0", f"api_ms={api_ms:.1f}ms"])
|
||||
|
||||
|
||||
def parser() -> argparse.ArgumentParser:
|
||||
p = argparse.ArgumentParser(description=__doc__)
|
||||
p.add_argument("mode", choices=["api", "backends", "latency", "queues"])
|
||||
@@ -211,7 +201,6 @@ def parser() -> argparse.ArgumentParser:
|
||||
p.add_argument("--critical", type=int, default=10, help="queues: critical total")
|
||||
return p
|
||||
|
||||
|
||||
def main() -> None:
|
||||
args = parser().parse_args()
|
||||
if args.warning_ms < 0 or args.critical_ms <= args.warning_ms:
|
||||
@@ -223,9 +212,8 @@ def main() -> None:
|
||||
{"api": check_api, "backends": check_backends, "latency": check_latency, "queues": check_queues}[args.mode](client, args)
|
||||
except CheckError as error:
|
||||
plugin_exit(UNKNOWN, str(error))
|
||||
except Exception as error: # Nagios plugins must fail closed with a single line.
|
||||
except Exception as error:
|
||||
plugin_exit(UNKNOWN, f"unexpected check failure: {error}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user