summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2021-10-13 16:03:43 +0100
committerMichael Morris <michael.morris@est.tech>2022-04-14 09:48:51 +0000
commitcd2747ff0dc6a02c03f2b17ce986d28b3abdf773 (patch)
tree46043d5a1eb3c65fea9453f9cb154bae78715dc1 /catalog-be/src/main/java
parent2cebeb91247c9c1a1fcd45a1bfec56e632d04501 (diff)
Add application metrics in the catalog backend
A new endpoint was introduced sdc2/rest/actuator/prometheus in the catalog backend, that returns application metrics in a format consumable by prometheus, using the micrometer library. Change-Id: I03542e1c1a9b8b12d4e00f86e5b02c597740934b Issue-ID: SDC-3957 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PrometheusMetricsServlet.java83
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/config/MicrometerSpringConfig.java37
2 files changed, 120 insertions, 0 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PrometheusMetricsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PrometheusMetricsServlet.java
new file mode 100644
index 0000000000..a90164a9c4
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PrometheusMetricsServlet.java
@@ -0,0 +1,83 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import io.micrometer.core.instrument.binder.jetty.JettyConnectionMetrics;
+import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
+import io.micrometer.core.instrument.binder.jvm.JvmCompilationMetrics;
+import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
+import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
+import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics;
+import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics;
+import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
+import io.micrometer.core.instrument.binder.system.UptimeMetrics;
+import io.micrometer.prometheus.PrometheusMeterRegistry;
+import io.prometheus.client.exporter.common.TextFormat;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.servers.Server;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import org.openecomp.sdc.common.api.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Controller;
+
+@Controller
+@Path("/actuator")
+@Tag(name = "SDCE-2 APIs")
+@Server(url = "/sdc2/rest")
+public class PrometheusMetricsServlet {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(PrometheusMetricsServlet.class);
+
+ private final PrometheusMeterRegistry prometheusRegistry;
+
+ public PrometheusMetricsServlet(final PrometheusMeterRegistry prometheusRegistry) {
+ this.prometheusRegistry = prometheusRegistry;
+ new ClassLoaderMetrics().bindTo(prometheusRegistry);
+ try (final JvmGcMetrics jvmGcMetrics = new JvmGcMetrics()) {
+ jvmGcMetrics.bindTo(prometheusRegistry);
+ } catch (final Exception e) {
+ LOGGER.error("Could not instantiate the JVM GC Metrics", e);
+ }
+ new JvmMemoryMetrics().bindTo(prometheusRegistry);
+ new JvmCompilationMetrics().bindTo(prometheusRegistry);
+ new JvmThreadMetrics().bindTo(prometheusRegistry);
+ new ProcessorMetrics().bindTo(prometheusRegistry);
+ new UptimeMetrics().bindTo(prometheusRegistry);
+ new FileDescriptorMetrics().bindTo(prometheusRegistry);
+ new JettyConnectionMetrics(prometheusRegistry);
+ }
+
+ @GET
+ @Path("/prometheus")
+ @Operation(summary = "Prometheus Micrometer Metrics", description = "Gets the prometheus micrometer application metrics")
+ public String prometheus(
+ @Parameter(description = "The Accept header to determine the output content type")
+ @HeaderParam(value = Constants.ACCEPT_HEADER) String acceptHeader) {
+ return prometheusRegistry.scrape(TextFormat.chooseContentType(acceptHeader));
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/config/MicrometerSpringConfig.java b/catalog-be/src/main/java/org/openecomp/sdc/config/MicrometerSpringConfig.java
new file mode 100644
index 0000000000..d7e62f7ea6
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/config/MicrometerSpringConfig.java
@@ -0,0 +1,37 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.config;
+
+import io.micrometer.prometheus.PrometheusConfig;
+import io.micrometer.prometheus.PrometheusMeterRegistry;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class MicrometerSpringConfig {
+
+ @Bean(name = "prometheusRegistry")
+ PrometheusMeterRegistry prometheusRegistry() {
+ return new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
+ }
+
+}