🎀dubbo QOS介绍及命令
💖简介
- 在
Dubbo
中,QoS
(Quality of Service
)功能是一个非常重要的特性,用于提供对运行时服务的查询和控制能力。 QoS
的概念源自网络设备中的服务质量保障机制,但在Dubbo
中,它被用来实现对服务的动态管理。具体来说,QoS
允许用户通过命令行或HTTP
接口与Dubbo
服务进行交互,以执行诸如查看服务状态、上下线服务等操作。Dubbo
的QoS
模块基于Netty4
实现,并从2.5.8
版本开始默认启用。所有的QoS
命令都被抽象成一个个具体的指令,当这些指令被执行时,会返回相应的结果。
📖官方文档
👉配置参数
qos-enable | 是否启动QoS | true |
---|---|---|
qos-port | 启动QoS绑定的端口 | 22222 |
qos-accept-foreign-ip | 是否允许远程访问 | false |
qos-accept-foreign-ip-whitelist | 支持的远端主机ip地址(段) | (无) |
qos-anonymous-access-permission-level | 支持的匿名访问的权限级别 | PUBLIC(1) |
配置优先级:
系统属性 >dubbo.properties
>XML/Spring-boot
自动装配
⭐常用命令
help
: 显示所有可用命令的帮助信息。ls
: 列出服务提供者和服务消费者的状态。online
: 将某个服务或所有服务上线,即重新注册到注册中心。offline
: 将某个服务或所有服务下线,即从注册中心注销。quit
: 退出当前的QoS会话。
这些命令可以通过
Telnet
或HTTP
协议访问,默认监听端口为22222
(可以通过配置参数qos-port
修改)
🌟全部命令
QoS 命令 | 说明 | telnet 用法示例 | http 用法示例 |
---|---|---|---|
cd | 设定服务上下文,cd 之后所有的命令都是针对该服务 | cd org.demo.DemoService | http://localhost:22222/cd?service=org.demo.DemoService |
count | 展示服务或方法调用次数。暂时只支持 dubbo 协议,不支持 triple 协议;RpcStatus 实现依赖 Active/Limit Filter,需改造 | count org.demo.DemoService count org.demo.DemoService methodName | http://localhost:22222/count?service=org.demo.DemoService&method=methodName |
disableDetailProfiler | 关闭 RPC 调用 profiler 工具(细粒度版本) | disableDetailProfiler | http://localhost:22222/disableDetailProfiler |
disableRouterSnapshot | 关闭 RPC 请求 Router 路由结果跟踪 | disableRouterSnapshot | http://localhost:22222/disableRouterSnapshot |
disableSimpleProfiler | 关闭 RPC 调用 profiler 工具(粗粒度版) | disableSimpleProfiler | http://localhost:22222/disableSimpleProfiler |
enableDetailProfiler | 开启 RPC 调用 profiler 工具(细粒度版本) | enableDetailProfiler | http://localhost:22222/enableDetailProfiler |
enableRouterSnapshot | 开启 RPC 请求 Router 路由结果跟踪,有助于跟踪路由规则执行是否符合预期 | enableRouterSnapshot org.demo.DemoService | http://localhost:22222/enableRouterSnapshot?service=org.demo.DemoService |
enableSimpleProfiler | 开启 RPC 调用 profiler 工具(粗粒度版) | enableSimpleProfiler | http://localhost:22222/enableSimpleProfiler |
getAddress | 查看某个服务的有效 ip 地址列表 | getAddress org.demo.DemoService | http://localhost:22222/getAddress?service=org.demo.DemoService |
getConfig | dump 当前应用的有效配置 | getConfig | http://localhost:22222/getConfig |
getEnabledRouterSnapshot | 查看当前 “启用 Router 路由结果跟踪” 的服务列表 | getEnabledRouterSnapshot | http://localhost:22222/getEnabledRouterSnapshot |
getRecentRouterSnapshot | 查看最近 32 条 “Router 路由结果跟踪” 数据 | getRecentRouterSnapshot | http://localhost:22222/getRecentRouterSnapshot |
gracefulShutdown | 从注册中心下线当前 ip 实例注册的所有服务,与offline的区别是,该命令会同时通过 tcp 连接告知所有消费方停止调用此实例。如要恢复,请执行 online 上线所有服务 | gracefulShutdown | http://localhost:22222/gracefulShutdown |
help | 帮助命令 | help | http://localhost:22222/help |
invoke | 调用某个 RPC 服务 | invoke org.demo.DemoService.methodName(1234, “abcd”, {“prop”:“value”}) | ? |
live | 检查当前进程/服务是否存活,可配置为 kubernetes liveness | live | http://localhost:22222/live |
loggerInfo | 查看当前日志 logger 配置 | loggerInfo | http://localhost:22222/loggerInfo |
ls | 查看当前所有服务列表 | ls | http://localhost:22222/ls |
metrics | 查看 metrics 指标,需开启metrics 统计才能看到数据。什么粒度? | metrics | http://localhost:22222/metrics |
metrics_default | 查看 metrics 指标 ,需开启metrics 统计才能看到数据。什么粒度? | metrics_default | http://localhost:22222/metrics_default |
offline | 从注册中心下线某个或多个服务(包含应用级和接口级地址) | offline offline org.demo.DemoService |
http://localhost:22222/offline http://localhost:22222/offline?service=org.demo.DemoService |
offlineApp | 从注册中心下线某个或多个服务(仅应用级) | offlineApp offlineApp org.demo.DemoService |
http://localhost:22222/offlineApp?service=org.demo.DemoService |
offlineInterface | 从注册中心下线某个或多个服务(仅接口级) | offlineInterface offlineInterface org.demo.DemoService |
http://localhost:22222/offlineInterface?service=org.demo.DemoService |
online | 将一个或多个服务注册到注册中心(包含应用级和接口级地址) | online online org.demo.DemoService |
http://localhost:22222/online?service=org.demo.DemoService |
onlineApp | 将一个或多个服务注册到注册中心(仅应用级) | onlineApp onlineApp org.demo.DemoService |
http://localhost:22222/onlineApp?service=org.demo.DemoService |
onlineInterface | 将一个或多个服务注册到注册中心(仅接口级) | onlineInterface onlineInterface org.demo.DemoService |
http://localhost:22222/onlineInterface?service=org.demo.DemoService |
ps | 查看当前进程信息,包括监听的端口等 | ps | http://localhost:22222/ps |
publishMetadata | 发布或更新当前应用Metadata数据(可用于手动更新应用级服务发现元数据)。publishMetadata 10 表示延迟 10s 发布。在3.3.0之前版本的命令为 publish-metadata | publishMetadata publishMetadata 10 |
http://localhost:22222/publishMetadata |
pwd | 查看当前服务上下文,与 cd 配合使用 | pwd | http://localhost:22222/pwd |
quit | 退出当前 telnet 命令 | quit | 无 |
ready | 检查当前进程/服务是否准备就绪对外服务,可配置为 kubernetes readiness | ready | http://localhost:22222/ready |
select | 调用方法?和invoke的关系? | ? | http://localhost:22222/? |
serializeCheckStatus | 检查当前在序列化白名单中的类列表 | serializeCheckStatus | http://localhost:22222/serializeCheckStatus |
serializeWarnedClasses | 检查当前在序列化警告名单中的类列表 | serializeWarnedClasses | http://localhost:22222/serializeWarnedClasses |
setProfilerWarnPercent | 控制序列化报警频率(仅限在警告名单中的类) | setProfilerWarnPercent 0.75 | http://localhost:22222/setProfilerWarnPercent?k=0.75 |
shutdown | 尝试关闭当前 Dubbo 应用(销毁所有资源,重启前无法恢复) | shutdown | http://localhost:22222/shutdown |
startup | 检查当前进程/服务是否已经正常启动,可配置为 kubernetes startup | startup | http://localhost:22222/startup |
switchLogLevel | 动态调整日志级别 | switchLogLevel debug | http://localhost:22222/switchLogLevel?k=debug |
switchLogger | 切换日志logger组件。可用 logger 组件,可通过 loggerInfo 查看(切换前请务必确保应用已经加入相关组件依赖) | switchLogger log4j2 | http://localhost:22222/switchLogger?k=log4j2 |
version | 查看当前使用的 Dubbo 框架版本 | version | http://localhost:22222/version |
✨使用场景
⚡优雅停机
在需要重启服务前,可以先将服务下线以避免新的请求被分配到即将停止的服务实例上。这有助于实现优雅停机,减少服务中断对用户体验的影响。
⚡查询服务状态
在生产环境中调试问题时,运维人员可以通过QoS实时获取服务状态,而无需重启服务或修改代码
结束