diff --git a/ansible/roles/schulcloud-server-core/tasks/main.yml b/ansible/roles/schulcloud-server-core/tasks/main.yml index 6a83839a2fe..afa2563936b 100644 --- a/ansible/roles/schulcloud-server-core/tasks/main.yml +++ b/ansible/roles/schulcloud-server-core/tasks/main.yml @@ -207,3 +207,10 @@ template: tldraw-ingress.yml.j2 apply: yes when: WITH_TLDRAW is defined and WITH_TLDRAW|bool + + - name: TldrawServiceMonitor + kubernetes.core.k8s: + kubeconfig: ~/.kube/config + namespace: "{{ NAMESPACE }}" + template: tldraw-svc-monitor.yml.j2 + when: WITH_TLDRAW is defined and WITH_TLDRAW|bool diff --git a/ansible/roles/schulcloud-server-core/templates/tldraw-deployment.yml.j2 b/ansible/roles/schulcloud-server-core/templates/tldraw-deployment.yml.j2 index e6e45a1fd33..4530c223673 100644 --- a/ansible/roles/schulcloud-server-core/templates/tldraw-deployment.yml.j2 +++ b/ansible/roles/schulcloud-server-core/templates/tldraw-deployment.yml.j2 @@ -52,6 +52,9 @@ spec: - containerPort: 3349 name: tldraw-http protocol: TCP + - containerPort: 9090 + name: api-metrics + protocol: TCP envFrom: - configMapRef: name: api-configmap diff --git a/ansible/roles/schulcloud-server-core/templates/tldraw-server-svc.yml.j2 b/ansible/roles/schulcloud-server-core/templates/tldraw-server-svc.yml.j2 index 8a1ded9a1d9..59074ea4f29 100644 --- a/ansible/roles/schulcloud-server-core/templates/tldraw-server-svc.yml.j2 +++ b/ansible/roles/schulcloud-server-core/templates/tldraw-server-svc.yml.j2 @@ -18,5 +18,9 @@ spec: targetPort: 3349 protocol: TCP name: tldraw-http + - port: {{ PORT_METRICS_SERVER }} + targetPort: 9090 + protocol: TCP + name: api-metrics selector: app: tldraw-server diff --git a/ansible/roles/schulcloud-server-core/templates/tldraw-svc-monitor.yml.j2 b/ansible/roles/schulcloud-server-core/templates/tldraw-svc-monitor.yml.j2 new file mode 100644 index 00000000000..6fcc75f0402 --- /dev/null +++ b/ansible/roles/schulcloud-server-core/templates/tldraw-svc-monitor.yml.j2 @@ -0,0 +1,17 @@ +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: tldraw-svc-monitor + namespace: {{ NAMESPACE }} + labels: + app: tldraw-server +spec: + selector: + matchExpressions: + - key: app.kubernetes.io/name + operator: in + values: + - tldraw-server-svc + endpoints: + - path: /metrics + port: api-metrics diff --git a/apps/server/src/apps/tldraw.app.ts b/apps/server/src/apps/tldraw.app.ts index a394b1e8deb..704ef3be4f1 100644 --- a/apps/server/src/apps/tldraw.app.ts +++ b/apps/server/src/apps/tldraw.app.ts @@ -10,6 +10,10 @@ import { enableOpenApiDocs } from '@shared/controller/swagger'; import { AppStartLoggable } from '@src/apps/helpers/app-start-loggable'; import { ExpressAdapter } from '@nestjs/platform-express'; import express from 'express'; +import { + addPrometheusMetricsMiddlewaresIfEnabled, + createAndStartPrometheusMetricsAppIfEnabled, +} from '@src/apps/helpers/prometheus-metrics'; async function bootstrap() { sourceMapInstall(); @@ -33,18 +37,23 @@ async function bootstrap() { // mount instances const rootExpress = express(); + addPrometheusMetricsMiddlewaresIfEnabled(logger, rootExpress); const port = 3349; const basePath = '/api/v3'; // exposed alias mounts rootExpress.use(basePath, nestExpress); - rootExpress.listen(port); - logger.info( - new AppStartLoggable({ - appName: 'Tldraw server app', - }) - ); + rootExpress.listen(port, () => { + logger.info( + new AppStartLoggable({ + appName: 'Tldraw server app', + port, + }) + ); + + createAndStartPrometheusMetricsAppIfEnabled(logger); + }); } void bootstrap();