feat: push directly to prometheus
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
from time import time
|
||||
|
||||
|
||||
def aggregate(domains: dict[str, list[str]]) -> list[dict]:
|
||||
data = {"no_auth": 0, "no_wan": 0, "auth": 0, "wan": 0, "none": 0}
|
||||
for domain, imports in domains.items():
|
||||
num = len(imports)
|
||||
if num == 0:
|
||||
data["none"] += 1
|
||||
continue
|
||||
|
||||
if "auth" in imports:
|
||||
data["auth"] += 1
|
||||
|
||||
if "wan" in imports:
|
||||
data["wan"] += 1
|
||||
|
||||
if "auth" not in imports:
|
||||
data["no_auth"] += 1
|
||||
|
||||
if "wan" not in imports:
|
||||
data["no_wan"] += 1
|
||||
# return data
|
||||
p = [
|
||||
{
|
||||
"metric": {"__name__": "caddy_domain_imports", "import": "caddy_"+imported, "host": "server1"},
|
||||
"values": [count],
|
||||
"timestamps": [int(time())],
|
||||
}
|
||||
for imported, count in data.items()
|
||||
]
|
||||
return p
|
||||
|
||||
def domain_imports(domains: dict[str, list[str]]):
|
||||
# print(domains)
|
||||
return [
|
||||
{"metric": {"__name__": "caddy_domain_imported", "domain": domain, "auth": 1 if "auth" in import_lists else 0, "wan": 1 if "wan" in import_lists else 0}, "values": [1], "timestamps": [int(time())]}
|
||||
for domain, import_lists in domains.items()
|
||||
]
|
||||
Reference in New Issue
Block a user