dubbo metrics to springboot endpoints (#10997)
This commit is contained in:
parent
6118dd8145
commit
b23cfa8c07
|
|
@ -89,6 +89,12 @@ public abstract class AbstractMetricsReporter implements MetricsReporter {
|
|||
protected void addMeterRegistry(MeterRegistry registry) {
|
||||
compositeRegistry.add(registry);
|
||||
}
|
||||
private void addDubboMeterRegistry(){
|
||||
MeterRegistry globalRegistry = DubboMetrics.globalRegistry;
|
||||
if(globalRegistry != null){
|
||||
compositeRegistry.add(globalRegistry);
|
||||
}
|
||||
}
|
||||
|
||||
protected ApplicationModel getApplicationModel() {
|
||||
return applicationModel;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 org.apache.dubbo.metrics;
|
||||
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.core.instrument.binder.MeterBinder;
|
||||
|
||||
|
||||
public class DubboMetrics implements MeterBinder {
|
||||
|
||||
protected static volatile MeterRegistry globalRegistry = null;
|
||||
@Override
|
||||
public void bindTo(MeterRegistry registry) {
|
||||
this.globalRegistry = registry;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -145,6 +145,11 @@
|
|||
<artifactId>junit-platform-runner</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-metrics-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 org.apache.dubbo.spring.boot.actuate.autoconfigure;
|
||||
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import org.apache.dubbo.metrics.DubboMetrics;
|
||||
import org.apache.dubbo.spring.boot.actuate.mertics.DubboMetricsBinder;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
|
||||
@Configuration(
|
||||
proxyBeanMethods = false
|
||||
)
|
||||
@ConditionalOnWebApplication
|
||||
@ConditionalOnClass({DubboMetrics.class})
|
||||
public class DubboMetricsAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnBean({MeterRegistry.class})
|
||||
@ConditionalOnMissingBean({DubboMetrics.class, DubboMetricsBinder.class})
|
||||
public DubboMetricsBinder tomcatMetricsBinder(MeterRegistry meterRegistry) {
|
||||
return new DubboMetricsBinder(meterRegistry);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 org.apache.dubbo.spring.boot.actuate.mertics;
|
||||
|
||||
import org.apache.dubbo.metrics.DubboMetrics;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
|
||||
|
||||
public class DubboMetricsBinder implements ApplicationListener<ApplicationStartedEvent>, DisposableBean {
|
||||
private final MeterRegistry meterRegistry;
|
||||
private volatile DubboMetrics dubboMetrics;
|
||||
|
||||
public DubboMetricsBinder(MeterRegistry meterRegistry) {
|
||||
this.meterRegistry = meterRegistry;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationStartedEvent applicationStartedEvent) {
|
||||
dubboMetrics = new DubboMetrics();
|
||||
dubboMetrics.bindTo(meterRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
dubboMetrics.destroy();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboEndpointAnnotationAutoConfiguration
|
||||
org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboEndpointAnnotationAutoConfiguration,\
|
||||
org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboMetricsAutoConfiguration
|
||||
|
|
|
|||
Loading…
Reference in New Issue