Apache Dubbo线程监控

JDK 1.8

Apache Dubbo 2.7.2和2.7.7

ZK 3.5.9

Apache dubbo-admin (master分支并把dubbo版本修改为2.7.2)

代码地址?https://github.com/skx001/dubbo-samples-metrics

https://github.com/skx001/dubbo-admin

实现效果

具体步骤

1.创建一个apache dubbo项目

这里我是直接从github上下载的dubbo-samples-metrics这个项目,然后做了一些修改,项目架构如下图

生产者配置文件如下:

<dubbo:metrics port=“20882” protocol=“dubbo”/>这个配置必须要,因为在dubboAdmin,在读取服务统计页面信息的时候,会获取生产者的这两个参数,如没有就无法获取生产者和线程池信息

<dubbo:protocol name=“dubbo” port=“20882” threadpool=“cached” threads=“100” dispatcher=“message” corethreads=“50”/>这个配置线程池参数,
这里的线程池数据会直接显示在图表那里

<?xml version="1.0" encoding="UTF-8"?>
<!--
  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.
  -->

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <context:property-placeholder/>

    <dubbo:application name="metrics-provider">
        <dubbo:parameter key="qos.enable" value="true"/>
        <dubbo:parameter key="qos.accept.foreign.ip" value="false"/>
        <dubbo:parameter key="qos.port" value="22221"/>
    </dubbo:application>

    <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
    <dubbo:config-center address="zookeeper://${zookeepr.address:127.0.0.1}:2181" />
    <dubbo:metadata-report address="zookeeper://${zookeeper.address:127.0.0.1}:2181" />

    <dubbo:metrics port="20882" protocol="dubbo"/>
    <dubbo:provider filter="metrics"  group="dubbo"/>

    <bean id="demoService" class="org.apache.dubbo.samples.metrics.impl.DemoServiceImpl"/>

    <dubbo:service interface="org.apache.dubbo.samples.metrics.api.DemoService" ref="demoService" timeout="80000"/>
    <dubbo:protocol name="dubbo" port="20882" threadpool="cached" threads="100" dispatcher="message" corethreads="50"/>
    <!--<dubbo:monitor protocol="registry"/>-->
</beans>

消费者配置文件如下:(没啥好说的)

<?xml version="1.0" encoding="UTF-8"?>
<!--
  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.
  -->

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <context:property-placeholder/>

    <dubbo:application name="metrics-demo-consumer">
        <dubbo:parameter key="qos.enable" value="true"/>
        <dubbo:parameter key="qos.accept.foreign.ip" value="false"/>
        <dubbo:parameter key="qos.port" value="33333"/>
    </dubbo:application>

    <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>

    <dubbo:reference id="demoService" check="true" interface="org.apache.dubbo.samples.metrics.api.DemoService"/>

    <dubbo:metrics port="20882" protocol="dubbo"/>
    <dubbo:consumer filter="metrics" group="dubbo"/>
    <dubbo:protocol name="dubbo" port="20882"/>
    <!--<dubbo:monitor protocol="registry"/>-->

</beans>

pom文件(这里有一个比较坑的地方)

<dubbo.version>2.7.7</dubbo.version>这个设置为2.7.7版本,然后dubbo的版本要设置为2.7.2,因为我试了如果dubbo版本设置成2.7.7就会没有线程池信息,应该是在2.7.2-2.7.7之间的某个版本阉割掉了或者换了一种配置方式,我暂时没找到。具体信息如下.

<?xml version="1.0" encoding="UTF-8"?>
<!--
  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.
  -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>dubbo-samples-all</artifactId>
        <groupId>org.apache.dubbo</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>dubbo-samples-metrics</artifactId>

    <properties>
        <source.level>1.8</source.level>
        <target.level>1.8</target.level>
        <dubbo.version>2.7.7</dubbo.version>
        <junit.version>4.12</junit.version>
        <spring.version>4.3.16.RELEASE</spring.version>
        <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-framework-bom</artifactId>
                <version>${spring.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo-bom</artifactId>
                <version>${dubbo.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo-dependencies-zookeeper</artifactId>
                <version>${dubbo.version}</version>
                <type>pom</type>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>2.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.7.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-monitor-default</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-dependencies-zookeeper</artifactId>
            <type>pom</type>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <profiles>
        <!-- For jdk 11 above JavaEE annotation -->
        <profile>
            <id>javax.annotation</id>
            <activation>
                <jdk>[1.8,)</jdk>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>javax.annotation</groupId>
                    <artifactId>javax.annotation-api</artifactId>
                    <version>1.3.2</version>
                </dependency>
            </dependencies>
        </profile>
    </profiles>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <source>${source.level}</source>
                    <target>${target.level}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

接下来就是启动zk,启动生产者,消费者

cmd窗口打开然后telnet 本机ip 20882 回车,然后 status -l如下图所示,就代表dubbo线程信息可以正常获取,接下来就是搞dubbo—Admin

2.dubbo-Admin安装和使用

直接从上面给的git hub地址下载dubbo-Admin代码(不要用官方那个,那个有很多bug),在idea上面直接运行dubbo-admin-server的main方法,(注意下面几个点)

服务端口号自行设置,这里改了,那么前端dubbo-admin-ui的请求端口也要改成跟这个一样

相对官方的dubbo-admin我这里对获取服务统计信息的接口做了些改动具体如下

启动成功之后访问dubbo-admin首页如下图 账号密码都是root

接下来进入服务统计页面输入ip地址,不要输入127.0.0.1哦,具体的ip可以看

服务详情里面的服务,点开详情可以看ip

好了,大功告成

以上还是有些许问题,后面再加

1.服务统计页面无消费者信息

2.apache-dubbo2.7.2版本之后的线程池数据获取是怎样的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值