Dubbo服务的监控和高可用机制
Dubbo给我们提供了dubbo-admin和dubbo-monitor-simple用于监控Dubbo服务,可以用来监控接口暴露,注册情况,也可以显示接口的调用明细和调用时间。dubbo-admin和dubbo-monitor-simple的下载地址为:https://github.com/apache/incubator-dubbo-admin/tree/master,这里简单介绍它们如何使用。
这里我们采用第一种方式,在上一节中的server-provider和server-consumer的配置文件中添加如下配置:
dubbo:
monitor:
protocol: registry
在服务提供方和消费方需要配置如下:
<dubbo:monitor protocol=”registry”/>
protocol为”registry”,表示服务提供方和消费方从注册中心发现监控中心(monitor)地址。
配置好后,依次启动server-provider和server-consumer,接下来开始搭建监控中心。
dubbo-monitor-simple
下载https://github.com/apache/incubator-dubbo-admin/tree/master源码后,使用IDEA导入dubbo-monitor-simple应用,修改其配置文件dubbo.properties内容:
dubbo.container=log4j,spring,registry,jetty-monitor dubbo.application.name=simple-monitor dubbo.application.owner=dubbo dubbo.registry.address=zookeeper://127.0.0.1:2181 dubbo.protocol.port=7070 dubbo.jetty.port=7000 dubbo.jetty.directory=${user.home}/monitor dubbo.charts.directory=${user.home}/monitor/charts dubbo.statistics.directory=${user.home}/monitor/statistics dubbo.log4j.file=logs/dubbo-monitor-simple.log dubbo.log4j.level=WARN
上面主要指定了注册中心地址为zookeeper://127.0.0.1:2181,监控中心协议端口为7070以及监控应用访问端口为7000。
配置好后,运行启动类MonitorStarter的main方法来启动应用,启动后,访问http://localhost:7000便可看到如下页面:
上面主要指定了注册中心地址为zookeeper://127.0.0.1:2181,监控中心协议端口为7070以及监控应用访问端口为7000。
配置好后,运行启动类MonitorStarter
的main方法来启动应用,启动后,访问http://localhost:7000便可看到如下页面:
在线应用信息:
多次访问http://localhost:8081/hello/mrbird后,便可以在监控中心查看服务调用情况:
dubbo-admin
使用IDEA导入dubbo-admin应用,修改其配置文件application.properties:
server.port=7001 spring.velocity.cache=false spring.velocity.charset=UTF-8 spring.velocity.layout-url=/templates/default.vm spring.messages.fallback-to-system-locale=false spring.messages.basename=i18n/message spring.root.password=root spring.guest.password=guest dubbo.registry.address=zookeeper://127.0.0.1:2181
使用dubbo-admin一定要注意修改其注册中心的地址和端口
上面配置主要配置了注册中心地址为zookeeper://127.0.0.1:2181,应用端口号为7001,root和guest账户的密码。 配置好后,启动应用(dubbo-admin使用Spring Boot构建,启动入口类即可),访问http://localhost:7001: QQ截图20190323152110.png QQ截图20190323152133.png QQ截图20190323152146.png QQ截图20190323152215.png duubo提供了新版的dubbo-admin,采用前后端分离的方式,前端由Vue.js构建,UI更为nice,不过还不完善,所以这里就不介绍了。 源码链接:https://github.com/wuyouzhuguli/SpringAll/tree/master/52.Dubbo-OPS-Mointor
4.Dubbo之dubbo-spring-boot-actuator
dubbo-spring-boot-actuator 提供 Production-Ready 特性:
健康检查
控制断点
外部化配置
版本
目前,dubbo-spring-boot-actuator将支持Spring Boot 2.x和1.x两个版本:
0.2.x是Spring Boot 2.x的主流发行版
0.1.x是用于维护Spring Boot 1.x的旧版本
与Maven整合
您可以通过向pom.xml添加以下依赖项,将最新的dubbo-spring-boot-actuator引入到您的项目中,
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-actuator</artifactId>
<version>0.2.0</version>
</dependency>
还依赖
<!-- dubbo actuator 依赖spring boot actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
如果您的项目无法解决依赖关系,请尝试添加以下存储库:
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
健康检查
dubbo-spring-boot-actuator支持标准的Spring Boot健康指示器作为生产就绪特性,它将聚合到Spring Boot的健康中,并在运行MVC (Spring Web MVC)和JMX (Java管理扩展)的HealthEndpoint上导出(如果它们都可用的话)。
Web端点:/health
假设Spring Boot Web应用程序未指定management.server.port,您可以通过Web Client访问http://localhost:8080/actuator/health,你可以可以专门为访问端点设置端口号,通过management.server.port设置。获得JSON格式的响应,如下所示:
{
"status": "UP",
"dubbo": {
"status": "UP",
"memory": {
"source": "management.health.dubbo.status.defaults",
"status": {
"level": "OK",
"message": "max:3641M,total:383M,used:92M,free:291M",
"description": null
}
},
"load": {
"source": "management.health.dubbo.status.extras",
"status": {
"level": "OK",
"message": "load:1.73583984375,cpu:8",
"description": null
}
},
"threadpool": {
"source": "management.health.dubbo.status.extras",
"status": {
"level": "OK",
"message": "Pool status:OK, max:200, core:200, largest:0, active:0, task:0, service port: 12345",
"description": null
}
},
"server": {
"source": "dubbo@ProtocolConfig.getStatus()",
"status": {
"level": "OK",
"message": "/192.168.1.103:12345(clients:0)",
"description": null
}
}
}
// ignore others
}
在上面的例子中,内存,负载,线程池和服务器是Dubbo的内置StatusCheckers。 Dubbo允许应用程序扩展StatusChecker的SPI。
默认,内存和负载将添加到Dubbo的HealthIndicator中,它可以被外部化配置StatusChecker的默认值覆盖。
JMX端点:健康
Health是一个JMX (Java管理扩展)端点,具有ObjectName org.springframework.boot:type=Endpoint,name=Health,它可以由JMX代理管理,例如。JDK工具:jconsole等等。
内置StatusCheckers
META-INF /dubbo/internal/com.alibaba.dubbo.common.status.StatusChecker声明内置StatusCheckers如下:
memory=com.alibaba.dubbo.common.status.support.MemoryStatusChecker
load=com.alibaba.dubbo.common.status.support.LoadStatusChecker
spring=com.alibaba.dubbo.config.spring.status.SpringStatusChecker
datasource=com.alibaba.dubbo.config.spring.status.DataSourceStatusChecker
server=com.alibaba.dubbo.rpc.protocol.dubbo.status.ServerStatusChecker
threadpool=com.alibaba.dubbo.rpc.protocol.dubbo.status.ThreadPoolStatusChecker
registry=com.alibaba.dubbo.registry.status.RegistryStatusChecker
作为StatusChecker名称的属性键可以是外部化配置中的management.health.dubbo.status.*的有效值。
端点
Actuator端点dubbo支持Actuator端点:
ID | Enabled | HTTP URI | HTTP Method | Description | Content Type
---------------- | ------- | -------------------------- | ----------- | --------------------------------- | ----------------
dubbo | true | /actuator/dubbo | GET | Exposes Dubbo's meta data | application/json
dubbo-properties | true | /actuator/dubbo/properties | GET | Exposes all Dubbo's Properties | application/json
dubbo-services | false | /dubbo/services | GET | Exposes all Dubbo's ServiceBean | application/json
dubbo-references | false | /actuator/dubbo/references | GET | Exposes all Dubbo's ReferenceBean | application/json
dubbo-configs | true | /actuator/dubbo/configs | GET | Exposes all Dubbo's *Config | application/json
dubbo-shutdown | false | /actuator/dubbo/shutdown | POST | Shutdown Dubbo services | application/json
# Dubbo Endpoints Default Properties is loaded by @PropertySource with low order,
# those values of properties can be override by higher PropertySource
# @see DubboEndpointsAutoConfiguration
# Set enabled for Dubbo Endpoints
management.endpoint.dubbo.enabled = true
management.endpoint.dubbo-shutdown.enabled = false
management.endpoint.dubbo-configs.enabled = true
management.endpoint.dubbo-services.enabled = false
management.endpoint.dubbo-references.enabled = false
management.endpoint.dubbo-properties.enabled = true
# "management.endpoints.web.base-path" should not be configured in this file
# Re-defines path-mapping of Dubbo Web Endpoints
management.endpoints.web.path-mapping.dubbo-shutdown = dubbo/shutdown
management.endpoints.web.path-mapping.dubbo-configs = dubbo/configs
management.endpoints.web.path-mapping.dubbo-services = dubbo/services
management.endpoints.web.path-mapping.dubbo-references = dubbo/references
management.endpoints.web.path-mapping.dubbo-properties = dubbo/properties
Web端点
/actuator/dubbo
/dubbo暴露了Dubbo的元数据:
{
"timestamp": 1516623290166,
"versions": {
"dubbo-spring-boot": "0.2.0"
"dubbo": "2.6.2"
},
"urls": {
"dubbo": "https://github.com/alibaba/dubbo",
"google-group": "http://groups.google.com/group/dubbo",
"github": "https://github.com/dubbo/dubbo-spring-boot-project",
"issues": "https://github.com/dubbo/dubbo-spring-boot-project/issues",
"git": "https://github.com/dubbo/dubbo-spring-boot-project.git"
}
}
/actuator/dubbo/properties
/actuator/dubbo/properties从Spring Boot外化配置(a.k.a PropertySources)公开所有Dubbo的属性:
{
"dubbo.application.id": "dubbo-provider-demo",
"dubbo.application.name": "dubbo-provider-demo",
"dubbo.application.qos-enable": "false",
"dubbo.application.qos-port": "33333",
"dubbo.protocol.id": "dubbo",
"dubbo.protocol.name": "dubbo",
"dubbo.protocol.port": "12345",
"dubbo.registry.address": "N/A",
"dubbo.registry.id": "my-registry",
"dubbo.scan.basePackages": "com.alibaba.boot.dubbo.demo.provider.service"
}
JSON的结构是简单的Key-Value格式,键是属性名称,值是属性值。
/actuator/dubbo/services
/actuator/dubbo/services公开在Spring ApplicationContext中通过<dubbo:service />或@Service声明的所有Dubbo的ServiceBean
{
"ServiceBean@com.alibaba.boot.dubbo.demo.api.DemoService#defaultDemoService": {
"accesslog": null,
"actives": null,
"cache": null,
"callbacks": null,
"class": "com.alibaba.dubbo.config.spring.ServiceBean",
"cluster": null,
"connections": null,
"delay": null,
"document": null,
"executes": null,
"export": null,
"exported": true,
"filter": "",
"generic": "false",
"group": null,
"id": "com.alibaba.boot.dubbo.demo.api.DemoService",
"interface": "com.alibaba.boot.dubbo.demo.api.DemoService",
"interfaceClass": "com.alibaba.boot.dubbo.demo.api.DemoService",
"layer": null,
"listener": "",
"loadbalance": null,
"local": null,
"merger": null,
"mock": null,
"onconnect": null,
"ondisconnect": null,
"owner": null,
"path": "com.alibaba.boot.dubbo.demo.api.DemoService",
"proxy": null,
"retries": null,
"scope": null,
"sent": null,
"stub": null,
"timeout": null,
"token": null,
"unexported": false,
"uniqueServiceName": "com.alibaba.boot.dubbo.demo.api.DemoService:1.0.0",
"validation": null,
"version": "1.0.0",
"warmup": null,
"weight": null,
"serviceClass": "com.alibaba.boot.dubbo.demo.provider.service.DefaultDemoService"
}
}
关键是ServiceBean的Bean名称,ServiceBean的属性组成值。
/actuator/dubbo/references
/actuator/dubbo/references公开所有通过@Reference on Field或Method声明的Dubbo的ReferenceBean:
{
"private com.alibaba.boot.dubbo.demo.api.DemoService com.alibaba.boot.dubbo.demo.consumer.controller.DemoConsumerController.demoService": {
"actives": null,
"cache": null,
"callbacks": null,
"class": "com.alibaba.dubbo.config.spring.ReferenceBean",
"client": null,
"cluster": null,
"connections": null,
"filter": "",
"generic": null,
"group": null,
"id": "com.alibaba.boot.dubbo.demo.api.DemoService",
"interface": "com.alibaba.boot.dubbo.demo.api.DemoService",
"interfaceClass": "com.alibaba.boot.dubbo.demo.api.DemoService",
"layer": null,
"lazy": null,
"listener": "",
"loadbalance": null,
"local": null,
"merger": null,
"mock": null,
"objectType": "com.alibaba.boot.dubbo.demo.api.DemoService",
"onconnect": null,
"ondisconnect": null,
"owner": null,
"protocol": null,
"proxy": null,
"reconnect": null,
"retries": null,
"scope": null,
"sent": null,
"singleton": true,
"sticky": null,
"stub": null,
"stubevent": null,
"timeout": null,
"uniqueServiceName": "com.alibaba.boot.dubbo.demo.api.DemoService:1.0.0",
"url": "dubbo://localhost:12345",
"validation": null,
"version": "1.0.0",
"invoker": {
"class": "com.alibaba.dubbo.common.bytecode.proxy0"
}
}
}
关键是@Reference Field或Method的字符串表示,ReferenceBean的属性组成值。
/actuator/dubbo/configs
actuator / dubbo / configs暴露所有Dubbo的* Config:
{
"ApplicationConfig": {
"dubbo-consumer-demo": {
"architecture": null,
"class": "com.alibaba.dubbo.config.ApplicationConfig",
"compiler": null,
"dumpDirectory": null,
"environment": null,
"id": "dubbo-consumer-demo",
"logger": null,
"name": "dubbo-consumer-demo",
"organization": null,
"owner": null,
"version": null
}
},
"ConsumerConfig": {
},
"MethodConfig": {
},
"ModuleConfig": {
},
"MonitorConfig": {
},
"ProtocolConfig": {
"dubbo": {
"accepts": null,
"accesslog": null,
"buffer": null,
"charset": null,
"class": "com.alibaba.dubbo.config.ProtocolConfig",
"client": null,
"codec": null,
"contextpath": null,
"dispatcher": null,
"dispather": null,
"exchanger": null,
"heartbeat": null,
"host": null,
"id": "dubbo",
"iothreads": null,
"name": "dubbo",
"networker": null,
"path": null,
"payload": null,
"port": 12345,
"prompt": null,
"queues": null,
"serialization": null,
"server": null,
"status": null,
"telnet": null,
"threadpool": null,
"threads": null,
"transporter": null
}
},
"ProviderConfig": {
},
"ReferenceConfig": {
},
"RegistryConfig": {
},
"ServiceConfig": {
}
}
关键是Dubbo Config类的简单名称,值是Config bean的名称属性映射。
/actuator/dubbo/shutdown
/ actuator / dubbo / shutdown关闭Dubbo的组件,包括注册表,协议,服务和引用:
{
"shutdown.count": {
"registries": 0,
"protocols": 1,
"services": 0,
"references": 1
}
}
“shutdown.count”表示Dubbo组件的关闭计数,该值表示已关闭的组件数。
外部化配置
默认的 StatusChecker
management.health.dubbo.status.defaults是用于设置StatusCheckers名称的属性名称,其值允许为多个值,例如
management.health.dubbo.status.defaults = registry,memory,load
默认值
默认值是
management.health.dubbo.status.defaults = memory,load
StatusChecker额外功能
management.health.dubbo.status.extras用于覆盖[StatusChecker的默认值],多个值由逗号分隔:
management.health.dubbo.status.extras = load,threadpool
健康检查已启用
management.health.dubbo.enabled是一个启用配置来打开或关闭运行状况检查功能,其默认值为true。
如果您要禁用运行状况检查,则应将management.health.dubbo.enabled应用于false:
management.health.dubbo.enabled = false
端点启用
Dubbo Spring Boot提供执行器端点,但其中一些是禁用的。 如果您要启用它们,请将以下属性添加到外部配置中:
# Enables Dubbo All Endpoints
management.endpoint.dubbo.enabled = true
management.endpoint.dubbo-shutdown.enabled = true
management.endpoint.dubbo-configs.enabled = true
management.endpoint.dubbo-services.enabled = true
management.endpoint.dubbo-references.enabled = true
management.endpoint.dubbo-properties.enabled = true
新版 Dubbo Admin 2.7.8 管理控制台搭建教程
官网地址
官网地址:https://github.com/apache/dubbo-admin
中文文档说明:https://github.com/apache/dubbo-admin/blob/develop/README_ZH.md
Dubbo服务swagger地址:http://localhost:8080/swagger-ui.html#/
官网地址
官网地址:https://github.com/apache/dubbo-admin
中文文档说明:https://github.com/apache/dubbo-admin/blob/develop/README_ZH.md
Dubbo服务swagger地址:http://localhost:8080/swagger-ui.html#/
2019年初,官方发布了Dubbo管理控制台0.1版本,结构上采用了前后端分离
的方式,前端使用Vue和Vuetify作为UI框架,后端采用的是SpringBoot框架。
一、修改配置
在下载的 dubbo-admin-develop.zip 文件的解压目录中,修改dubbo-admin-server\server\src\main\resource下的application.properties 配置文件,主要修改此配置文件中的注册中心,配置中心,与元数据中心的 zk 地址。(改成自己服务器或虚拟机的地址,如果是在本地搭建的 则不需要修改)
二、打包(后端)
1、进入dubbo-admin-server 目录,打开cmd窗口,在当前目录下执行以下两条命令
mvn install -Dmaven.test.skip=true //跳过测试环节(如果打包过程中测试环节不报错也可以不加 -Dmaven.test.skip=true)
- 1
2、进入dubbo-admin-server\target 目录,执行jar包
java -jar dubbo-admin-server-0.2.0-SNAPSHOT.jar
- 1
三、安装依赖及启动(前端)
进入到dubbo-admin-ui 目录,打开cmd窗口,在当前目录下分别执行以下两条命令
npm install # 安装依赖
npm run dev # 启动Vue项目
- 1
- 2
- 3
四、启动zookeeper
1、下载:https://zookeeper.apache.org/releases.html
2、解压到本地后,需要修改下配置文件名,进入 conf 目录,将zoo_sample.cfg配置文件复制一份,将复制后的文件重命名为zoo.cfg。如果仅将 zk 做单点来用,那么进入 bin 目录双击 zkServer.cmd 启动服务端,出现以下命令行窗口即运行成功:
zkServer.cmd
- 1
在bin目录下,再启动 zkCli.cmd 启动客户端:
zkCli.cmd
- 1
这时就可以开始在客户端敲命令了,同时服务端也会打印出客户端过来的请求:
客户端:
[zk: localhost:2181(CONNECTED) 2] ls /
[zookeeper]
[zk: localhost:2181(CONNECTED) 3] create /zk hello,world!
Created /zk
[zk: localhost:2181(CONNECTED) 4] ls /
[zk, zookeeper]
[zk: localhost:2181(CONNECTED) 5] get /zk
hello,world!
cZxid = 0x2
ctime = Tue Sep 11 11:22:48 CST 2018
mZxid = 0x2
mtime = Tue Sep 11 11:22:48 CST 2018
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 12
numChildren = 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
服务端:
2018-09-11 11:19:48,064 [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@192] - Accepted socket connection from /0:0:0:0:0:0:0:1:57459
2018-09-11 11:19:48,073 [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@942] - Client attempting to establish new session at /0:0:0:0:0:0:0:1:57459
2018-09-11 11:19:48,076 [myid:] - INFO [SyncThread:0:FileTxnLog@203] - Creating new log file: log.1
2018-09-11 11:19:48,088 [myid:] - INFO [SyncThread:0:ZooKeeperServer@687] - Established session 0x165c6a41e3a0000 with negotiated timeout 30000 for client /0:0:0:0:0:0:0:1:57459
- 1
- 2
- 3
- 4
五、启动dubbo 管理控制台
http://localhost:8082/
默认的账号密码都是root。swagger地址如下:http://localhost:8080/swagger-ui.html#/
posted on 2020-09-01 14:09 luzhouxiaoshuai 阅读(1444) 评论(0) 编辑 收藏 举报