-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Expose metrics about used TeamForCapella license usage
A new gauge metric `t4c_licenses` was added to the `/metrics` endpoint, which contains the number of currently used licenses per TeamForCapella instance. The instance name is used as label for the metric. Note: If you have multiple TeamForCapella server instances, which point to the same license server, this is not detected. Therefore, make sure to filter the `t4c_licenses` for one instance first.
- Loading branch information
1 parent
4f90b53
commit c4bb6b7
Showing
3 changed files
with
44 additions
and
3 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
39 changes: 39 additions & 0 deletions
39
backend/capellacollab/settings/modelsources/t4c/metrics.py
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 |
---|---|---|
@@ -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()) | ||
Submodule capella-dockerimages
updated
42 files