diff --git a/backend/capellacollab/__main__.py b/backend/capellacollab/__main__.py index 052758e476..6b168f3b2d 100644 --- a/backend/capellacollab/__main__.py +++ b/backend/capellacollab/__main__.py @@ -13,7 +13,8 @@ from fastapi.middleware import cors import capellacollab.projects.toolmodels.backups.runs.interface as pipeline_runs_interface -import capellacollab.sessions.metrics +import capellacollab.sessions.metrics as sessions_metrics +import capellacollab.settings.modelsources.t4c.metrics as t4c_metrics # This import statement is required and should not be removed! (Alembic will not work otherwise) from capellacollab.config import config @@ -84,7 +85,8 @@ async def shutdown(): on_startup=[ startup, idletimeout.terminate_idle_sessions_in_background, - capellacollab.sessions.metrics.register, + sessions_metrics.register, + t4c_metrics.register, pipeline_runs_interface.schedule_refresh_and_trigger_pipeline_jobs, ], middleware=[ diff --git a/backend/capellacollab/settings/modelsources/t4c/metrics.py b/backend/capellacollab/settings/modelsources/t4c/metrics.py new file mode 100644 index 0000000000..dae9575e4d --- /dev/null +++ b/backend/capellacollab/settings/modelsources/t4c/metrics.py @@ -0,0 +1,39 @@ +# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors +# SPDX-License-Identifier: Apache-2.0 + +import typing as t + +import prometheus_client +import prometheus_client.core + +from capellacollab.core import database + +from . import crud, interface + + +class UsedT4CLicensesCollector: + def collect(self) -> t.Iterable[prometheus_client.core.Metric]: + metric = prometheus_client.core.GaugeMetricFamily( + "t4c_licenses", + "Currently used T4C licenses per registered TeamForCapella instance.", + ) + + with database.SessionLocal() as db: + instances = crud.get_t4c_instances(db) + + if not instances: + return + + for instance in instances: + try: + t4c_status = interface.get_t4c_status(instance) + used_licenses = t4c_status.total - t4c_status.free + except: # pylint: disable=bare-except + used_licenses = -1 + + metric.add_metric([instance.name], used_licenses) + yield metric + + +def register() -> None: + prometheus_client.REGISTRY.register(UsedT4CLicensesCollector()) diff --git a/capella-dockerimages b/capella-dockerimages index cdf5ec7c2b..e03bb68031 160000 --- a/capella-dockerimages +++ b/capella-dockerimages @@ -1 +1 @@ -Subproject commit cdf5ec7c2be87f2aa2373eef7bbd04ee0de4f3bf +Subproject commit e03bb680317ddf32a16ec0af097a165446080104