diff --git a/pom.xml b/pom.xml
index 9a60dfa..5eed326 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,7 +12,7 @@
UTF-8
quarkus-bom
io.quarkus.platform
- 3.13.2
+ 3.14.2
true
3.4.0
1.20.1
@@ -39,6 +39,10 @@
io.quarkus
quarkus-scheduler
+
+ io.quarkus
+ quarkus-micrometer-registry-prometheus
+
io.quarkus
quarkus-kubernetes-client
diff --git a/src/main/java/de/svs/Namespace.java b/src/main/java/de/svs/Namespace.java
index 20fdc50..a657d11 100644
--- a/src/main/java/de/svs/Namespace.java
+++ b/src/main/java/de/svs/Namespace.java
@@ -6,6 +6,7 @@
import org.bson.types.ObjectId;
import java.time.Instant;
+import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@@ -32,6 +33,15 @@ public static List findByActivatedUntilOlderThan(Instant activatedUnt
return find("activatedUntil < ?1", activatedUntil).list();
}
+ public static long countActiveNamespaces() {
+ LocalDateTime now = LocalDateTime.now();
+ return count("activatedUntil > ?1", now);
+ }
+
+ public static long countTotalNamespaces() {
+ return count();
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
diff --git a/src/main/java/de/svs/metrics/CustomNamespaceActivatorMetrics.java b/src/main/java/de/svs/metrics/CustomNamespaceActivatorMetrics.java
new file mode 100644
index 0000000..57e34df
--- /dev/null
+++ b/src/main/java/de/svs/metrics/CustomNamespaceActivatorMetrics.java
@@ -0,0 +1,25 @@
+package de.svs.metrics;
+
+import de.svs.Namespace;
+import io.micrometer.core.instrument.Gauge;
+import io.micrometer.core.instrument.MeterRegistry;
+import io.quarkus.runtime.Startup;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+
+@Startup
+@ApplicationScoped
+public class CustomNamespaceActivatorMetrics {
+
+ @Inject
+ public CustomNamespaceActivatorMetrics(MeterRegistry registry) {
+ Gauge.builder("active_namespaces", Namespace::countActiveNamespaces)
+ .description("Number of active namespaces")
+ .register(registry);
+
+ Gauge.builder("total_namespaces", Namespace::countTotalNamespaces)
+ .description("Total number of namespaces known by the activator")
+ .register(registry);
+ }
+
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 05a4bf2..ccfaf34 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -2,4 +2,8 @@ quarkus.mongodb.connection-string=mongodb://localhost:27017/keda
baseDomain=.brb.dbildungscloud.dev
quarkus.mongodb.database=keda
namespace.deletion.cron=30 * * * * ?
-# to set a kubeconfig you have to set the kubeconfig variable, yes lowercase
\ No newline at end of file
+# to set a kubeconfig you have to set the kubeconfig variable, yes lowercase
+
+quarkus.management.enabled=true
+quarkus.management.port=9999
+quarkus.micrometer.export.prometheus.enabled=true
\ No newline at end of file