Co-authored-by: x-shadow-man <1494445739@qq.com>
This commit is contained in:
wxbty 2023-03-17 13:02:56 +08:00 committed by GitHub
parent af3f75aced
commit ec9eecfc82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -17,6 +17,7 @@
package org.apache.dubbo.metrics.report;
import io.micrometer.core.instrument.binder.MeterBinder;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.beans.factory.ScopeBeanFactory;
import org.apache.dubbo.common.constants.MetricsConstants;
@ -65,6 +66,8 @@ public abstract class AbstractMetricsReporter implements MetricsReporter {
protected final URL url;
@SuppressWarnings("rawtypes")
protected final List<MetricsCollector> collectors = new ArrayList<>();
// Avoid instances being gc due to weak references
protected final List<MeterBinder> instanceHolder = new ArrayList<>();
public static final CompositeMeterRegistry compositeRegistry = new CompositeMeterRegistry();
private final ApplicationModel applicationModel;
@ -116,12 +119,17 @@ public abstract class AbstractMetricsReporter implements MetricsReporter {
jvmGcMetrics.bindTo(compositeRegistry);
Runtime.getRuntime().addShutdownHook(new Thread(jvmGcMetrics::close));
new ProcessorMetrics(extraTags).bindTo(compositeRegistry);
bindTo(new ProcessorMetrics(extraTags));
new JvmThreadMetrics(extraTags).bindTo(compositeRegistry);
new UptimeMetrics(extraTags).bindTo(compositeRegistry);
bindTo(new UptimeMetrics(extraTags));
}
}
private void bindTo(MeterBinder binder) {
binder.bindTo(compositeRegistry);
instanceHolder.add(binder);
}
@SuppressWarnings("rawtypes")
private void initCollectors() {
ScopeBeanFactory beanFactory = applicationModel.getBeanFactory();