make sure prometheus metrics are correctly served

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
Marc 'risson' Schmitt 2023-12-27 12:16:22 +01:00
parent e57c824c97
commit 806d1f0b75
No known key found for this signature in database
GPG Key ID: 9C3FA22FABF1AA8D
8 changed files with 21 additions and 5 deletions

View File

@ -7,7 +7,7 @@ from authentik.lib.config import CONFIG, ENV_PREFIX
GAUGE_TASKS = Gauge(
"authentik_system_tasks",
"System tasks and their status",
["task_name", "task_uid", "status"],
["tenant", "task_name", "task_uid", "status"],
)

View File

@ -13,6 +13,7 @@ from tenant_schemas_celery.task import TenantTask
from authentik.events.apps import GAUGE_TASKS
from authentik.events.models import Event, EventAction
from authentik.lib.utils.errors import exception_to_string
from authentik.tenants.utils import get_current_tenant
LOGGER = get_logger()
CACHE_KEY_PREFIX = "goauthentik.io/events/tasks/"
@ -101,6 +102,7 @@ class TaskInfo:
except TypeError:
duration = 0
GAUGE_TASKS.labels(
tenant=get_current_tenant().tenant_uuid,
task_name=self.task_name.split(":")[0],
task_uid=self.result.uid or "",
status=self.result.status.name.lower(),

View File

@ -7,6 +7,7 @@ from authentik.lib.utils.reflection import all_subclasses
GAUGE_FLOWS_CACHED = Gauge(
"authentik_flows_cached",
"Cached flows",
["tenant"],
)
HIST_FLOW_EXECUTION_STAGE_TIME = Histogram(
"authentik_flows_execution_stage_time",

View File

@ -7,6 +7,7 @@ from structlog.stdlib import get_logger
from authentik.flows.apps import GAUGE_FLOWS_CACHED
from authentik.flows.planner import CACHE_PREFIX
from authentik.root.monitoring import monitoring_set
from authentik.tenants.utils import get_current_tenant
LOGGER = get_logger()
@ -21,7 +22,9 @@ def delete_cache_prefix(prefix: str) -> int:
@receiver(monitoring_set)
def monitoring_set_flows(sender, **kwargs):
"""set flow gauges"""
GAUGE_FLOWS_CACHED.set(len(cache.keys(f"{CACHE_PREFIX}*") or []))
GAUGE_FLOWS_CACHED.labels(tenant=get_current_tenant().tenant_uuid).set(
len(cache.keys(f"{CACHE_PREFIX}*") or [])
)
@receiver(post_save)

View File

@ -8,12 +8,14 @@ from authentik.lib.config import CONFIG
LOGGER = get_logger()
GAUGE_OUTPOSTS_CONNECTED = Gauge(
"authentik_outposts_connected", "Currently connected outposts", ["outpost", "uid", "expected"]
"authentik_outposts_connected",
"Currently connected outposts",
["tenant", "outpost", "uid", "expected"],
)
GAUGE_OUTPOSTS_LAST_UPDATE = Gauge(
"authentik_outposts_last_update",
"Last update from any outpost",
["outpost", "uid", "version"],
["tenant", "outpost", "uid", "version"],
)
MANAGED_OUTPOST = "goauthentik.io/outposts/embedded"

View File

@ -14,6 +14,7 @@ from structlog.stdlib import BoundLogger, get_logger
from authentik.core.channels import AuthJsonConsumer
from authentik.outposts.apps import GAUGE_OUTPOSTS_CONNECTED, GAUGE_OUTPOSTS_LAST_UPDATE
from authentik.outposts.models import OUTPOST_HELLO_INTERVAL, Outpost, OutpostState
from authentik.tenants.utils import get_current_tenant
OUTPOST_GROUP = "group_outpost_%(outpost_pk)s"
@ -76,6 +77,7 @@ class OutpostConsumer(AuthJsonConsumer):
OUTPOST_GROUP % {"outpost_pk": str(self.outpost.pk)}, self.channel_name
)
GAUGE_OUTPOSTS_CONNECTED.labels(
tenant=get_current_tenant().tenant_uuid,
outpost=self.outpost.name,
uid=self.last_uid,
expected=self.outpost.config.kubernetes_replicas,
@ -88,6 +90,7 @@ class OutpostConsumer(AuthJsonConsumer):
)
if self.outpost and self.last_uid:
GAUGE_OUTPOSTS_CONNECTED.labels(
tenant=get_current_tenant().tenant_uuid,
outpost=self.outpost.name,
uid=self.last_uid,
expected=self.outpost.config.kubernetes_replicas,
@ -112,6 +115,7 @@ class OutpostConsumer(AuthJsonConsumer):
elif msg.instruction == WebsocketMessageInstruction.ACK:
return
GAUGE_OUTPOSTS_LAST_UPDATE.labels(
tenant=get_current_tenant().tenant_uuid,
outpost=self.outpost.name,
uid=self.last_uid or "",
version=state.version or "",

View File

@ -6,6 +6,7 @@ from authentik.blueprints.apps import ManagedAppConfig
GAUGE_POLICIES_CACHED = Gauge(
"authentik_policies_cached",
"Cached Policies",
["tenant"],
)
HIST_POLICIES_ENGINE_TOTAL_TIME = Histogram(
"authentik_policies_engine_time_total_seconds",

View File

@ -10,6 +10,7 @@ from authentik.policies.apps import GAUGE_POLICIES_CACHED
from authentik.policies.models import Policy, PolicyBinding, PolicyBindingModel
from authentik.policies.types import CACHE_PREFIX
from authentik.root.monitoring import monitoring_set
from authentik.tenants.utils import get_current_tenant
LOGGER = get_logger()
@ -17,7 +18,9 @@ LOGGER = get_logger()
@receiver(monitoring_set)
def monitoring_set_policies(sender, **kwargs):
"""set policy gauges"""
GAUGE_POLICIES_CACHED.set(len(cache.keys(f"{CACHE_PREFIX}*") or []))
GAUGE_POLICIES_CACHED.labels(tenant=get_current_tenant().tenant_uuid).set(
len(cache.keys(f"{CACHE_PREFIX}*") or [])
)
@receiver(post_save, sender=Policy)