diff --git a/collector/pom.xml b/collector/pom.xml index 6e9d8b1a6148..56eb409bb3df 100644 --- a/collector/pom.xml +++ b/collector/pom.xml @@ -262,23 +262,6 @@ test - - - io.dropwizard.metrics - metrics-core - - - io.dropwizard.metrics - metrics-jvm - - - io.dropwizard.metrics - metrics-jmx - - - io.dropwizard.metrics - metrics-servlets - jakarta.servlet diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/config/HbaseAsyncConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/config/HbaseAsyncConfiguration.java index 7dddf8d43926..9fad4939fb90 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/config/HbaseAsyncConfiguration.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/config/HbaseAsyncConfiguration.java @@ -17,10 +17,7 @@ package com.navercorp.pinpoint.collector.config; -import com.navercorp.pinpoint.collector.dao.hbase.BulkOperationReporter; import com.navercorp.pinpoint.collector.manage.HBaseManager; -import com.navercorp.pinpoint.collector.monitor.dropwizard.BulkOperationMetrics; -import com.navercorp.pinpoint.collector.monitor.dropwizard.HBaseAsyncOperationMetrics; import com.navercorp.pinpoint.common.hbase.async.HBaseTableMultiplexerFactory; import com.navercorp.pinpoint.common.hbase.async.HbasePutWriter; import com.navercorp.pinpoint.common.hbase.async.LoggingHbasePutWriter; @@ -38,8 +35,6 @@ import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Primary; -import java.util.List; - @Configuration @Import({ CommonCacheManagerConfiguration.class, @@ -54,11 +49,6 @@ public HbaseBatchPerformanceCounter batchPerformanceCounter() { return new HbaseBatchPerformanceCounter(); } - @Bean - public HBaseAsyncOperationMetrics asyncOperationMetrics(List hBaseAsyncOperationList) { - return new HBaseAsyncOperationMetrics(hBaseAsyncOperationList); - } - @Configuration @ConditionalOnProperty(name = "hbase.client.put-writer", havingValue = "tableMultiplexer") public static class TableMultiplexerConfig { @@ -81,8 +71,8 @@ public HbasePutWriter hbasePutWriter(@Qualifier("batchConnectionFactory") Connec @Bean public HbasePutWriter spanPutWriter(@Qualifier("batchConnectionFactory") Connection connection, - HbaseBatchPerformanceCounter counter, - HbaseMultiplexerProperties properties) throws Exception { + HbaseBatchPerformanceCounter counter, + HbaseMultiplexerProperties properties) throws Exception { HbasePutWriter writer = newPutWriter(connection, counter, properties); logger.info("HbaseSpanPutWriter:{}", writer); return writer; @@ -98,16 +88,9 @@ private HbasePutWriter newPutWriter(Connection connection, HbaseBatchPerformance } - - @Bean - public BulkOperationMetrics cachedStatisticsDaoMetrics(List bulkOperationReporters) { - return new BulkOperationMetrics(bulkOperationReporters); - } - @Bean public HBaseManager hBaseManager(@Qualifier("batchPerformanceCounter") HBaseBatchPerformance hBaseAsyncOperation) { return new HBaseManager(hBaseAsyncOperation); } - } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/CollectorGrpcConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/CollectorGrpcConfiguration.java index 54e9a969c508..2af98bab4b73 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/CollectorGrpcConfiguration.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/CollectorGrpcConfiguration.java @@ -17,7 +17,6 @@ package com.navercorp.pinpoint.collector.grpc; -import com.codahale.metrics.MetricRegistry; import com.navercorp.pinpoint.collector.grpc.channelz.ChannelzConfiguration; import com.navercorp.pinpoint.collector.grpc.config.GrpcAgentConfiguration; import com.navercorp.pinpoint.collector.grpc.config.GrpcAgentReceiverConfiguration; @@ -28,17 +27,10 @@ import com.navercorp.pinpoint.collector.grpc.config.GrpcStatConfiguration; import com.navercorp.pinpoint.collector.grpc.config.GrpcStatReceiverConfiguration; import com.navercorp.pinpoint.collector.monitor.MonitoredThreadPoolExecutorFactoryProvider; -import com.navercorp.pinpoint.collector.monitor.config.DropwizardConfiguration; import com.navercorp.pinpoint.collector.monitor.config.MicrometerConfiguration; -import com.navercorp.pinpoint.collector.monitor.dropwizard.DropwizardThreadPoolExecutorFactoryProvider; import com.navercorp.pinpoint.collector.monitor.MonitoringExecutors; -import com.navercorp.pinpoint.collector.monitor.micrometer.MicrometerThreadPoolExecutorFactoryProvider; import com.navercorp.pinpoint.common.server.executor.ExecutorCustomizer; -import io.micrometer.core.instrument.MeterRegistry; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -60,7 +52,6 @@ GrpcKeepAliveScheduler.class, - DropwizardConfiguration.class, MicrometerConfiguration.class, ChannelzConfiguration.class diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentReceiverConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentReceiverConfiguration.java index 295ff2ed91b9..b876d4db9cc0 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentReceiverConfiguration.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentReceiverConfiguration.java @@ -16,16 +16,12 @@ package com.navercorp.pinpoint.collector.grpc.config; -import com.codahale.metrics.MetricRegistry; -import com.navercorp.pinpoint.collector.monitor.MonitoredThreadPoolExecutorFactoryProvider; import com.navercorp.pinpoint.collector.monitor.MonitoringExecutors; -import com.navercorp.pinpoint.collector.monitor.dropwizard.DropwizardThreadPoolExecutorFactoryProvider; import com.navercorp.pinpoint.collector.receiver.BindAddress; import com.navercorp.pinpoint.common.server.thread.MonitoringExecutorProperties; import com.navercorp.pinpoint.common.server.util.CallerUtils; import com.navercorp.pinpoint.grpc.server.ServerOption; import org.springframework.beans.factory.FactoryBean; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcSpanConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcSpanConfiguration.java index a630084c197d..9cb95f3a49d1 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcSpanConfiguration.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcSpanConfiguration.java @@ -16,16 +16,12 @@ package com.navercorp.pinpoint.collector.grpc.config; -import com.codahale.metrics.MetricRegistry; -import com.navercorp.pinpoint.collector.monitor.MonitoredThreadPoolExecutorFactoryProvider; import com.navercorp.pinpoint.collector.monitor.MonitoringExecutors; -import com.navercorp.pinpoint.collector.monitor.dropwizard.DropwizardThreadPoolExecutorFactoryProvider; import com.navercorp.pinpoint.collector.receiver.BindAddress; import com.navercorp.pinpoint.common.server.thread.MonitoringExecutorProperties; import com.navercorp.pinpoint.common.server.util.CallerUtils; import com.navercorp.pinpoint.grpc.server.ServerOption; import org.springframework.beans.factory.FactoryBean; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStatConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStatConfiguration.java index ee733b1aced3..5d208117fd3a 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStatConfiguration.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStatConfiguration.java @@ -16,17 +16,13 @@ package com.navercorp.pinpoint.collector.grpc.config; -import com.codahale.metrics.MetricRegistry; -import com.navercorp.pinpoint.collector.monitor.MonitoredThreadPoolExecutorFactoryProvider; import com.navercorp.pinpoint.collector.monitor.MonitoringExecutors; -import com.navercorp.pinpoint.collector.monitor.dropwizard.DropwizardThreadPoolExecutorFactoryProvider; import com.navercorp.pinpoint.collector.receiver.BindAddress; import com.navercorp.pinpoint.common.server.thread.MonitoringExecutorProperties; import com.navercorp.pinpoint.common.server.util.CallerUtils; import com.navercorp.pinpoint.grpc.server.ServerOption; import jakarta.inject.Provider; import org.springframework.beans.factory.FactoryBean; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/MonitoredThreadPoolExecutorFactoryProvider.java b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/MonitoredThreadPoolExecutorFactoryProvider.java index 52939c89da5c..66c8ea9408dd 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/MonitoredThreadPoolExecutorFactoryProvider.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/MonitoredThreadPoolExecutorFactoryProvider.java @@ -15,12 +15,7 @@ */ package com.navercorp.pinpoint.collector.monitor; -import com.codahale.metrics.MetricRegistry; -import com.navercorp.pinpoint.collector.monitor.dropwizard.DropwizardThreadPoolExecutorFactory; -import com.navercorp.pinpoint.collector.monitor.micrometer.MicrometerThreadPoolExecutorFactory; import com.navercorp.pinpoint.common.server.thread.MonitoringExecutorProperties; -import io.micrometer.core.instrument.MeterRegistry; -import org.springframework.beans.factory.annotation.Autowired; /** * @author intr3p1d diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/config/DropwizardConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/config/DropwizardConfiguration.java deleted file mode 100644 index cdef2305218a..000000000000 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/config/DropwizardConfiguration.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.navercorp.pinpoint.collector.monitor.config; - -import com.codahale.metrics.MetricRegistry; -import com.navercorp.pinpoint.collector.config.CollectorProperties; -import com.navercorp.pinpoint.collector.monitor.MonitoredThreadPoolExecutorFactoryProvider; -import com.navercorp.pinpoint.collector.monitor.dropwizard.BulkOperationMetrics; -import com.navercorp.pinpoint.collector.monitor.dropwizard.CollectorMetric; -import com.navercorp.pinpoint.collector.monitor.dropwizard.DropwizardThreadPoolExecutorFactoryProvider; -import com.navercorp.pinpoint.collector.monitor.dropwizard.HBaseAsyncOperationMetrics; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.util.Optional; - -@Configuration -// FIXME: The MetricRegistry is currently used in other parts -// so it cannot be removed at this time. -// It needs to be separated in the future. -//@ConditionalOnProperty( -// value = "pinpoint.modules.collector.monitor.metric", -// havingValue = "dropwizard", matchIfMissing = true -//) -public class DropwizardConfiguration { - private final Logger logger = LogManager.getLogger(DropwizardConfiguration.class); - - public DropwizardConfiguration() { - logger.info("Install {}", DropwizardConfiguration.class.getSimpleName()); - } - - @Bean - public MetricRegistry metricRegistry() { - return new MetricRegistry(); - } - - - @Bean - public CollectorMetric collectorMetric( - CollectorProperties collectorProperties, - MetricRegistry metricRegistry, - Optional hBaseAsyncOperationMetrics, - Optional cachedStatisticsDaoMetrics - ) { - return new CollectorMetric(collectorProperties, metricRegistry, hBaseAsyncOperationMetrics, cachedStatisticsDaoMetrics); - } - - @Bean - @ConditionalOnProperty( - value = "pinpoint.modules.collector.monitor.metric", - havingValue = "dropwizard", matchIfMissing = true - ) - public MonitoredThreadPoolExecutorFactoryProvider dropwizardMonitoredThreadPoolExecutorFactoryProvider( - @Autowired(required = false) MetricRegistry metricRegistry - ) { - return new DropwizardThreadPoolExecutorFactoryProvider(metricRegistry); - } -} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/config/MicrometerConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/config/MicrometerConfiguration.java index 58be3765c8c7..b4457f99b09b 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/config/MicrometerConfiguration.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/config/MicrometerConfiguration.java @@ -15,35 +15,36 @@ */ package com.navercorp.pinpoint.collector.monitor.config; +import com.navercorp.pinpoint.collector.dao.hbase.BulkOperationReporter; import com.navercorp.pinpoint.collector.monitor.MonitoredThreadPoolExecutorFactoryProvider; +import com.navercorp.pinpoint.collector.monitor.micrometer.BulkOperationMetrics; +import com.navercorp.pinpoint.collector.monitor.micrometer.HBaseAsyncOperationMetrics; import com.navercorp.pinpoint.collector.monitor.micrometer.MicrometerThreadPoolExecutorFactoryProvider; +import com.navercorp.pinpoint.common.hbase.counter.HBaseBatchPerformance; import io.grpc.ServerInterceptor; import io.micrometer.core.instrument.Counter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Timer; -import io.micrometer.core.instrument.binder.MeterBinder; import io.micrometer.core.instrument.binder.grpc.MetricCollectingServerInterceptor; import io.micrometer.core.instrument.binder.logging.Log4j2Metrics; import io.micrometer.core.instrument.binder.netty4.NettyAllocatorMetrics; +import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocatorMetricProvider; import io.netty.buffer.PooledByteBufAllocator; -import io.netty.channel.EventLoopGroup; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import java.util.List; + /** * @author intr3p1d */ @Configuration -@ConditionalOnProperty( - value = "pinpoint.modules.collector.monitor.metric", - havingValue = "micrometer" -) public class MicrometerConfiguration { private final Logger logger = LogManager.getLogger(MicrometerConfiguration.class); private static final String GRPC_INTERCEPTOR_TAG_KEY = "service"; @@ -54,10 +55,12 @@ public MicrometerConfiguration() { } @Bean - @ConditionalOnProperty( - value = "pinpoint.modules.collector.monitor.metric", - havingValue = "micrometer" - ) + @ConditionalOnMissingBean(MeterRegistry.class) + public MeterRegistry simpleMeterRegistry() { + return new SimpleMeterRegistry(); + } + + @Bean public MonitoredThreadPoolExecutorFactoryProvider micrometerMonitoredThreadPoolExecutorFactoryProvider( MeterRegistry meterRegistry ) { @@ -112,11 +115,28 @@ private Timer.Builder addTimerTag(Timer.Builder builder, String tagValue) { @Bean @Qualifier("monitoredByteBufAllocator") - public ByteBufAllocator monitoredByteBufAllocator(MeterRegistry meterRegistry){ + public ByteBufAllocator monitoredByteBufAllocator(MeterRegistry meterRegistry) { ByteBufAllocator allocator = PooledByteBufAllocator.DEFAULT; if (allocator != null) { new NettyAllocatorMetrics((ByteBufAllocatorMetricProvider) allocator).bindTo(meterRegistry); } return allocator; } + + @Bean + public BulkOperationMetrics cachedStatisticsDaoMetrics( + List bulkOperationReporters, + MeterRegistry meterRegistry + ) { + return new BulkOperationMetrics(bulkOperationReporters, meterRegistry); + } + + @Bean + public HBaseAsyncOperationMetrics asyncOperationMetrics( + List hBaseAsyncOperationList, + MeterRegistry meterRegistry + ) { + return new HBaseAsyncOperationMetrics(hBaseAsyncOperationList, meterRegistry); + } + } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/CollectorMetric.java b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/CollectorMetric.java deleted file mode 100644 index 7d1a6cd8b2ee..000000000000 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/CollectorMetric.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright 2014 NAVER Corp. - * - * 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. - */ - -package com.navercorp.pinpoint.collector.monitor.dropwizard; - -import com.codahale.metrics.Metric; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.Slf4jReporter; -import com.codahale.metrics.jmx.JmxReporter; -import com.codahale.metrics.jvm.GarbageCollectorMetricSet; -import com.codahale.metrics.jvm.JvmAttributeGaugeSet; -import com.codahale.metrics.jvm.MemoryUsageGaugeSet; -import com.codahale.metrics.jvm.ThreadStatesGaugeSet; -import com.navercorp.pinpoint.collector.config.CollectorProperties; -import com.navercorp.pinpoint.common.util.IOUtils; -import jakarta.annotation.PostConstruct; -import jakarta.annotation.PreDestroy; -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.slf4j.Log4jLoggerFactory; -import org.apache.logging.slf4j.Log4jMarkerFactory; -import org.springframework.stereotype.Component; -import org.springframework.util.Assert; - -import java.io.Closeable; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.concurrent.TimeUnit; - -/** - * @author emeroad - */ -@Component -public class CollectorMetric { - - public static final String REPORTER_LOGGER_NAME = "com.navercorp.pinpoint.collector.StateReport"; - - private final CollectorProperties collectorProperties; - - private final MetricRegistry metricRegistry; - - private final HBaseAsyncOperationMetrics hBaseAsyncOperationMetrics; - private final BulkOperationMetrics bulkOperationMetrics; - - private List reporterList = new ArrayList<>(2); - - private final boolean isEnable = isEnable0(REPORTER_LOGGER_NAME); - - public CollectorMetric(CollectorProperties collectorProperties, - MetricRegistry metricRegistry, - Optional hBaseAsyncOperationMetrics, - Optional cachedStatisticsDaoMetrics) { - this.collectorProperties = Objects.requireNonNull(collectorProperties, "collectorProperties"); - this.metricRegistry = Objects.requireNonNull(metricRegistry, "metricRegistry"); - this.hBaseAsyncOperationMetrics = hBaseAsyncOperationMetrics.orElse(null); - this.bulkOperationMetrics = cachedStatisticsDaoMetrics.orElse(null); - } - - @PostConstruct - public void start() { - initRegistry(); - initReporters(); - } - - public boolean isEnable() { - return isEnable; - } - - private boolean isEnable0(String loggerName) { - final Logger logger = LogManager.getLogger(loggerName); - final Level level = logger.getLevel(); - if (level.isLessSpecificThan(Level.WARN)) { - return false; - } - return true; - } - - private void initRegistry() { - // add JVM statistics - metricRegistry.register("jvm.memory", new MemoryUsageGaugeSet()); - metricRegistry.register("jvm.vm", new JvmAttributeGaugeSet()); - metricRegistry.register("jvm.garbage-collectors", new GarbageCollectorMetricSet()); - metricRegistry.register("jvm.thread-states", new ThreadStatesGaugeSet()); - - if (hBaseAsyncOperationMetrics != null) { - Map metrics = hBaseAsyncOperationMetrics.getMetrics(); - for (Map.Entry metric : metrics.entrySet()) { - metricRegistry.register(metric.getKey(), metric.getValue()); - } - } - - if (bulkOperationMetrics != null) { - Map metrics = bulkOperationMetrics.getMetrics(); - for (Map.Entry metric : metrics.entrySet()) { - metricRegistry.register(metric.getKey(), metric.getValue()); - } - } - } - - private void initReporters() { - Slf4jReporter slf4jReporter = createSlf4jReporter(); - slf4jReporter.start(60, TimeUnit.SECONDS); // print every 1 min. - - reporterList.add(slf4jReporter); - - if (collectorProperties.isMetricJmxEnable()) { - - final String metricJmxDomainName = collectorProperties.getMetricJmxDomainName(); - Assert.hasLength(metricJmxDomainName, "metricJmxDomainName must not be empty"); - - final JmxReporter jmxReporter = createJmxReporter(metricJmxDomainName); - jmxReporter.start(); - reporterList.add(jmxReporter); - } - } - - private Slf4jReporter createSlf4jReporter() { - Slf4jReporter.Builder builder = Slf4jReporter.forRegistry(metricRegistry); - builder.convertRatesTo(TimeUnit.SECONDS); - builder.convertDurationsTo(TimeUnit.MILLISECONDS); - - Log4jMarkerFactory log4jMarkerFactory = new Log4jMarkerFactory(); - Log4jLoggerFactory log4jLoggerFactory = new Log4jLoggerFactory(log4jMarkerFactory); - - final org.slf4j.Logger reporterLogger = log4jLoggerFactory.getLogger(REPORTER_LOGGER_NAME); - builder.outputTo(reporterLogger); - return builder.build(); - } - - private JmxReporter createJmxReporter(String metricJmxDomainName) { - final JmxReporter.Builder builder = JmxReporter.forRegistry(metricRegistry); - builder.convertRatesTo(TimeUnit.SECONDS); - builder.convertDurationsTo(TimeUnit.MILLISECONDS); - builder.inDomain(metricJmxDomainName); - - return builder.build(); - } - - @PreDestroy - private void shutdown() { - for (Closeable reporter : reporterList) { - IOUtils.closeQuietly(reporter); - } - reporterList = null; - } - -} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/DropwizardThreadPoolExecutorFactory.java b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/DropwizardThreadPoolExecutorFactory.java deleted file mode 100644 index 272158ddf3dc..000000000000 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/DropwizardThreadPoolExecutorFactory.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2023 NAVER Corp. - * - * 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. - * - */ - -package com.navercorp.pinpoint.collector.monitor.dropwizard; - -import com.codahale.metrics.Gauge; -import com.codahale.metrics.Meter; -import com.codahale.metrics.MetricRegistry; -import com.navercorp.pinpoint.collector.monitor.BypassRunnableDecorator; -import com.navercorp.pinpoint.collector.monitor.LoggingRejectedExecutionHandler; -import com.navercorp.pinpoint.collector.monitor.MonitoredThreadPoolExecutor; -import com.navercorp.pinpoint.collector.monitor.MonitoredThreadPoolExecutorFactory; -import com.navercorp.pinpoint.collector.monitor.RejectedExecutionHandlerChain; -import com.navercorp.pinpoint.collector.monitor.RunnableDecorator; - -import java.io.Serializable; -import java.util.Objects; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.RejectedExecutionHandler; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -public class DropwizardThreadPoolExecutorFactory implements Serializable, MonitoredThreadPoolExecutorFactory { - - private final String name; - private final transient MetricRegistry registry; - private final int logRate; - - public DropwizardThreadPoolExecutorFactory(String name, MetricRegistry registry, int logRate) { - this.name = Objects.requireNonNull(name, "name"); - this.registry = registry; - this.logRate = logRate; - } - - @Override - public boolean isEnable() { - return registry != null; - } - - @Override - public ThreadPoolExecutor createExecutor(int corePoolSize, int maxPoolSize, int keepAliveSeconds, BlockingQueue queue, - ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) { - rejectedExecutionHandler = wrapHandlerChain(rejectedExecutionHandler); - - RunnableDecorator runnableDecorator = new BypassRunnableDecorator(name); - - MonitoredThreadPoolExecutor monitoredThreadPoolExecutor = new MonitoredThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveSeconds, TimeUnit.MILLISECONDS, - queue, threadFactory, rejectedExecutionHandler, runnableDecorator); - - Gauge submitGauge = () -> (long) monitoredThreadPoolExecutor.getSubmitCount(); - this.registry.register(MetricRegistry.name(name, "submitted"), submitGauge); - - Gauge runningGauge = () -> (long) monitoredThreadPoolExecutor.getActiveCount(); - this.registry.register(MetricRegistry.name(name, "running"), runningGauge); - - Gauge completedTaskGauge = () -> (long) monitoredThreadPoolExecutor.getCompletedTaskCount(); - this.registry.register(MetricRegistry.name(name, "completed"), completedTaskGauge); - - return monitoredThreadPoolExecutor; - } - - private RejectedExecutionHandler wrapHandlerChain(RejectedExecutionHandler rejectedExecutionHandler) { - - RejectedExecutionHandlerChain.Builder builder = new RejectedExecutionHandlerChain.Builder(); - if (registry != null) { - Meter rejected = registry.meter(MetricRegistry.name(name, "rejected")); - RejectedExecutionHandler countingHandler = new MeterRejectedExecutionHandler(rejected); - builder.addRejectHandler(countingHandler); - } - - if (logRate > -1) { - RejectedExecutionHandler loggingHandler = new LoggingRejectedExecutionHandler(name, logRate); - builder.addRejectHandler(loggingHandler); - } - - // original exception policy - builder.addRejectHandler(rejectedExecutionHandler); - - return builder.build(); - } -} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/DropwizardThreadPoolExecutorFactoryProvider.java b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/DropwizardThreadPoolExecutorFactoryProvider.java deleted file mode 100644 index 44cb10a90f85..000000000000 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/DropwizardThreadPoolExecutorFactoryProvider.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2024 NAVER Corp. - * - * 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. - */ -package com.navercorp.pinpoint.collector.monitor.dropwizard; - -import com.codahale.metrics.MetricRegistry; -import com.navercorp.pinpoint.collector.monitor.MonitoredThreadPoolExecutorFactory; -import com.navercorp.pinpoint.collector.monitor.MonitoredThreadPoolExecutorFactoryProvider; -import com.navercorp.pinpoint.common.server.thread.MonitoringExecutorProperties; -import org.springframework.beans.factory.annotation.Autowired; - -/** - * @author intr3p1d - */ -public class DropwizardThreadPoolExecutorFactoryProvider implements MonitoredThreadPoolExecutorFactoryProvider { - - private final MetricRegistry metricRegistry; - - public DropwizardThreadPoolExecutorFactoryProvider( - @Autowired(required = false) MetricRegistry metricRegistry - ) { - this.metricRegistry = metricRegistry; - } - - public MonitoredThreadPoolExecutorFactory newFactory(String beanName, MonitoringExecutorProperties properties) { - if (properties.isMonitorEnable()) { - return new DropwizardThreadPoolExecutorFactory(beanName, metricRegistry, properties.getLogRate()); - } - return null; - } -} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/MeterRejectedExecutionHandler.java b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/MeterRejectedExecutionHandler.java deleted file mode 100644 index f06b2700e68a..000000000000 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/MeterRejectedExecutionHandler.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2018 NAVER Corp. - * - * 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. - */ - -package com.navercorp.pinpoint.collector.monitor.dropwizard; - -import com.codahale.metrics.Meter; - -import java.util.Objects; -import java.util.concurrent.RejectedExecutionHandler; -import java.util.concurrent.ThreadPoolExecutor; - -/** - * @author Woonduk Kang(emeroad) - */ -public class MeterRejectedExecutionHandler implements RejectedExecutionHandler { - - private final Meter meter; - - public MeterRejectedExecutionHandler(Meter meter) { - this.meter = Objects.requireNonNull(meter, "meter"); - } - - @Override - public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { - meter.mark(); - } -} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/BulkOperationMetrics.java b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/micrometer/BulkOperationMetrics.java similarity index 53% rename from collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/BulkOperationMetrics.java rename to collector/src/main/java/com/navercorp/pinpoint/collector/monitor/micrometer/BulkOperationMetrics.java index 9b32e9c6d93f..cad60072577c 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/BulkOperationMetrics.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/micrometer/BulkOperationMetrics.java @@ -1,11 +1,11 @@ /* - * Copyright 2021 NAVER Corp. + * Copyright 2024 NAVER Corp. * * 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 + * 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, @@ -13,39 +13,35 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package com.navercorp.pinpoint.collector.monitor.micrometer; -package com.navercorp.pinpoint.collector.monitor.dropwizard; - -import com.codahale.metrics.Gauge; -import com.codahale.metrics.Metric; -import com.codahale.metrics.MetricSet; import com.navercorp.pinpoint.collector.dao.hbase.BulkOperationReporter; import com.navercorp.pinpoint.common.util.StringUtils; +import io.micrometer.core.instrument.Gauge; +import io.micrometer.core.instrument.MeterRegistry; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Objects; /** * @author Taejin Koo */ -public class BulkOperationMetrics implements MetricSet { +public class BulkOperationMetrics { private static final String FLUSH_COUNT = ".flush.count"; private static final String FLUSH_LAST_TIME_MILLIS = ".flush.lasttimemillis"; private static final String INCREMENT_REJECT_COUNT= ".increment.reject.count"; private final List bulkOperationReporters; + private final MeterRegistry meterRegistry; - public BulkOperationMetrics(List bulkOperationReporters) { - this.bulkOperationReporters = Objects.requireNonNull(bulkOperationReporters, "monitoredCachedStatisticsDaos"); + public BulkOperationMetrics(List bulkOperationReporters, MeterRegistry meterRegistry) { + this.bulkOperationReporters = Objects.requireNonNull(bulkOperationReporters, "bulkOperationReporters"); + this.meterRegistry = Objects.requireNonNull(meterRegistry, "meterRegistry"); + registerMetrics(); } - @Override - public Map getMetrics() { - final Map metrics = new HashMap<>(bulkOperationReporters.size()); - + private void registerMetrics() { for (BulkOperationReporter bulkOperationReporter : bulkOperationReporters) { String clazzName = bulkOperationReporter.getClass().getSimpleName(); @@ -54,30 +50,14 @@ public Map getMetrics() { clazzName = splittedName[0]; } - metrics.put(clazzName + FLUSH_COUNT, new Gauge() { - @Override - public Long getValue() { - return bulkOperationReporter.getFlushAllCount(); - } - }); - - metrics.put(clazzName + FLUSH_LAST_TIME_MILLIS, new Gauge() { - @Override - public Long getValue() { - return bulkOperationReporter.getLastFlushTimeMillis(); - } - }); + Gauge.builder(clazzName + FLUSH_COUNT, bulkOperationReporter, BulkOperationReporter::getFlushAllCount) + .register(meterRegistry); - metrics.put(clazzName + INCREMENT_REJECT_COUNT, new Gauge() { - @Override - public Long getValue() { - return bulkOperationReporter.getRejectedCount(); - } - }); + Gauge.builder(clazzName + FLUSH_LAST_TIME_MILLIS, bulkOperationReporter, BulkOperationReporter::getLastFlushTimeMillis) + .register(meterRegistry); + Gauge.builder(clazzName + INCREMENT_REJECT_COUNT, bulkOperationReporter, BulkOperationReporter::getRejectedCount) + .register(meterRegistry); } - - return Map.copyOf(metrics); } - } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/HBaseAsyncOperationMetrics.java b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/micrometer/HBaseAsyncOperationMetrics.java similarity index 54% rename from collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/HBaseAsyncOperationMetrics.java rename to collector/src/main/java/com/navercorp/pinpoint/collector/monitor/micrometer/HBaseAsyncOperationMetrics.java index 88b5343da82d..cf2fd2bc2467 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/dropwizard/HBaseAsyncOperationMetrics.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/micrometer/HBaseAsyncOperationMetrics.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 NAVER Corp. + * Copyright 2024 NAVER Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,28 +12,22 @@ * 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. - * */ +package com.navercorp.pinpoint.collector.monitor.micrometer; -package com.navercorp.pinpoint.collector.monitor.dropwizard; - -import com.codahale.metrics.Gauge; -import com.codahale.metrics.Metric; -import com.codahale.metrics.MetricSet; import com.navercorp.pinpoint.common.hbase.counter.HBaseBatchPerformance; +import io.micrometer.core.instrument.Gauge; +import io.micrometer.core.instrument.MeterRegistry; import org.apache.commons.collections4.CollectionUtils; -import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; /** * @author Taejin Koo */ -public class HBaseAsyncOperationMetrics implements MetricSet { +public class HBaseAsyncOperationMetrics { private static final String HBASE_ASYNC_OPS = "hbase.async.ops"; private static final String COUNT = HBASE_ASYNC_OPS + ".count"; @@ -43,56 +37,40 @@ public class HBaseAsyncOperationMetrics implements MetricSet { private static final String AVERAGE_LATENCY = HBASE_ASYNC_OPS + ".latency.value"; private final List hBaseAsyncOperations; + private final MeterRegistry meterRegistry; - public HBaseAsyncOperationMetrics(List hBaseAsyncOperationList) { - Objects.requireNonNull(hBaseAsyncOperationList, "hBaseAsyncOperation"); - - this.hBaseAsyncOperations = hBaseAsyncOperationList.stream() + public HBaseAsyncOperationMetrics(List hBaseAsyncOperationList, MeterRegistry meterRegistry) { + this.hBaseAsyncOperations = Objects.requireNonNull(hBaseAsyncOperationList, "hBaseAsyncOperationList").stream() .filter(HBaseBatchPerformance::isAvailable) .collect(Collectors.toList()); + this.meterRegistry = Objects.requireNonNull(meterRegistry, "meterRegistry"); + registerMetrics(); } - @Override - public Map getMetrics() { + private void registerMetrics() { if (CollectionUtils.isEmpty(hBaseAsyncOperations)) { - return Collections.emptyMap(); + return; } - final Map gauges = new HashMap<>(3); - gauges.put(COUNT, new Gauge() { - @Override - public Long getValue() { - return hBaseAsyncOperations.stream() + Gauge.builder(COUNT, hBaseAsyncOperations, ops -> ops.stream() .mapToLong(HBaseBatchPerformance::getOpsCount) - .sum(); - } - }); - gauges.put(REJECTED_COUNT, new Gauge() { - @Override - public Long getValue() { - return hBaseAsyncOperations.stream() + .sum()) + .register(meterRegistry); + + Gauge.builder(REJECTED_COUNT, hBaseAsyncOperations, ops -> ops.stream() .mapToLong(HBaseBatchPerformance::getOpsRejectedCount) - .sum(); - } - }); - gauges.put(FAILED_COUNT, new Gauge() { - @Override - public Long getValue() { - return hBaseAsyncOperations.stream() + .sum()) + .register(meterRegistry); + + Gauge.builder(FAILED_COUNT, hBaseAsyncOperations, ops -> ops.stream() .mapToLong(HBaseBatchPerformance::getOpsFailedCount) - .sum(); - } - }); - gauges.put(WAITING_COUNT, new Gauge() { - @Override - public Long getValue() { - return hBaseAsyncOperations.stream() - .mapToLong(HBaseBatchPerformance::getCurrentOpsCount) - .sum(); - } - }); + .sum()) + .register(meterRegistry); - return Collections.unmodifiableMap(gauges); + Gauge.builder(WAITING_COUNT, hBaseAsyncOperations, ops -> ops.stream() + .mapToLong(HBaseBatchPerformance::getCurrentOpsCount) + .sum()) + .register(meterRegistry); } } diff --git a/collector/src/main/resources/application.yml b/collector/src/main/resources/application.yml index bff989087dd8..5857ca017b29 100644 --- a/collector/src/main/resources/application.yml +++ b/collector/src/main/resources/application.yml @@ -11,7 +11,5 @@ pinpoint: grpc: ssl: enabled: false - monitor: - metric: dropwizard realtime: enabled: false \ No newline at end of file diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/TestReceiverConfig.java b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/TestReceiverConfig.java index 9b383062b501..f0bf7b58aaba 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/TestReceiverConfig.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/TestReceiverConfig.java @@ -17,12 +17,12 @@ package com.navercorp.pinpoint.collector.grpc.config; -import com.codahale.metrics.MetricRegistry; import com.navercorp.pinpoint.collector.monitor.MonitoredThreadPoolExecutorFactoryProvider; import com.navercorp.pinpoint.collector.monitor.MonitoringExecutors; -import com.navercorp.pinpoint.collector.monitor.dropwizard.DropwizardThreadPoolExecutorFactoryProvider; +import com.navercorp.pinpoint.collector.monitor.micrometer.MicrometerThreadPoolExecutorFactoryProvider; import com.navercorp.pinpoint.common.server.executor.ExecutorCustomizer; import com.navercorp.pinpoint.common.server.executor.ThreadPoolExecutorCustomizer; +import io.micrometer.core.instrument.MeterRegistry; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -42,8 +42,8 @@ public ExecutorCustomizer collectorExecutorCustom @Bean public MonitoredThreadPoolExecutorFactoryProvider dropwizardMonitoredThreadPoolExecutorFactoryProvider( - @Autowired(required = false) MetricRegistry metricRegistry + @Autowired(required = false) MeterRegistry meterRegistry ) { - return new DropwizardThreadPoolExecutorFactoryProvider(metricRegistry); + return new MicrometerThreadPoolExecutorFactoryProvider(meterRegistry); } } diff --git a/flink/src/main/resources/applicationContext-hbase.xml b/flink/src/main/resources/applicationContext-hbase.xml index 905a7e74c7ec..e70684f6977b 100644 --- a/flink/src/main/resources/applicationContext-hbase.xml +++ b/flink/src/main/resources/applicationContext-hbase.xml @@ -7,10 +7,6 @@ - - - - diff --git a/log/log-collector/src/main/java/com/navercorp/pinpoint/log/collector/LogCollectorConfig.java b/log/log-collector/src/main/java/com/navercorp/pinpoint/log/collector/LogCollectorConfig.java index 8d8dd796e9cf..c4d0e97880b6 100644 --- a/log/log-collector/src/main/java/com/navercorp/pinpoint/log/collector/LogCollectorConfig.java +++ b/log/log-collector/src/main/java/com/navercorp/pinpoint/log/collector/LogCollectorConfig.java @@ -15,7 +15,6 @@ */ package com.navercorp.pinpoint.log.collector; -import com.codahale.metrics.MetricRegistry; import com.navercorp.pinpoint.log.collector.grpc.LogCollectorGrpcServerConfig; import com.navercorp.pinpoint.log.collector.redis.LogCollectorRedisServerConfig; import org.springframework.context.annotation.Bean; @@ -29,9 +28,4 @@ @Import({ LogCollectorGrpcServerConfig.class, LogCollectorRedisServerConfig.class }) public class LogCollectorConfig { - @Bean - MetricRegistry metricRegistry() { - return new MetricRegistry(); - } - }