forked from goauthentik/authentik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
admin: monitor worker version (goauthentik#12463)
* root: include version in celery ping Signed-off-by: Jens Langhammer <[email protected]> * check version in worker endpoint Signed-off-by: Jens Langhammer <[email protected]> * include worker version in prom metrics Signed-off-by: Jens Langhammer <[email protected]> * format Signed-off-by: Jens Langhammer <[email protected]> * fix tests Signed-off-by: Jens Langhammer <[email protected]> --------- Signed-off-by: Jens Langhammer <[email protected]>
- Loading branch information
Showing
8 changed files
with
100 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,35 @@ | ||
"""admin signals""" | ||
|
||
from django.dispatch import receiver | ||
from packaging.version import parse | ||
from prometheus_client import Gauge | ||
|
||
from authentik.admin.apps import GAUGE_WORKERS | ||
from authentik import get_full_version | ||
from authentik.root.celery import CELERY_APP | ||
from authentik.root.monitoring import monitoring_set | ||
|
||
GAUGE_WORKERS = Gauge( | ||
"authentik_admin_workers", | ||
"Currently connected workers, their versions and if they are the same version as authentik", | ||
["version", "version_matched"], | ||
) | ||
|
||
|
||
_version = parse(get_full_version()) | ||
|
||
|
||
@receiver(monitoring_set) | ||
def monitoring_set_workers(sender, **kwargs): | ||
"""Set worker gauge""" | ||
count = len(CELERY_APP.control.ping(timeout=0.5)) | ||
GAUGE_WORKERS.set(count) | ||
raw: list[dict[str, dict]] = CELERY_APP.control.ping(timeout=0.5) | ||
worker_version_count = {} | ||
for worker in raw: | ||
key = list(worker.keys())[0] | ||
version = worker[key].get("version") | ||
version_matching = False | ||
if version: | ||
version_matching = parse(version) == _version | ||
worker_version_count.setdefault(version, {"count": 0, "matching": version_matching}) | ||
worker_version_count[version]["count"] += 1 | ||
for version, stats in worker_version_count.items(): | ||
GAUGE_WORKERS.labels(version, stats["matching"]).set(stats["count"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters