diff options
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PrometheusMetricsServlet.java | 83 | ||||
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/config/MicrometerSpringConfig.java | 37 |
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); + } + +} |