Skip to content

Commit

Permalink
仿照DruidDataSource的监控功能,增加RpcClientStat和RpcServerStat,前台通过/r/DevStat__…
Browse files Browse the repository at this point in the history
…jdbcSqlStats, /r/DevStat__rpcServerStats等链接查看每条sql语句,以及后台每个服务函数的性能统计数据
  • Loading branch information
entropy-cloud committed Feb 20, 2025
1 parent bb3bf1e commit f6dcbfa
Show file tree
Hide file tree
Showing 27 changed files with 828 additions and 48 deletions.
5 changes: 5 additions & 0 deletions docs/dev-guide/error-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,8 @@ ApiResponse的结构类似SmartAdmin中ResponseDTO。response = headers + status
```
"nop.err.my-error?myParam=xx" : "异常消息A"
```

6. 异常消息定制
异常码对应的异常消息可以通过i18n文件进行定制。例如在 `/i18n/zh-CN/error.i18n.yaml`文件中为每个错误码指定对应的错误消息,它会替代错误码定义时所使用的缺省消息。
I18nMessageManager会自动读取`_vfs/i18n/`目录下所有的不以下划线为前缀的`i18n.yaml`文件。Nop平台并没有约定一定要在`error.i18n.yaml`中定制错误消息,这里的名称是自定义的。

10 changes: 10 additions & 0 deletions docs/performance/optimize-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@
* `nop.ioc.app-beans-container.concurrent-start`设置为true, 则启动时在线程池上执行bean容器的初始化操作,不阻塞主线程

## 优化应用运行时性能

* `nop.debug` 设置为false, 就不会在dump目录下产生输出
* `nop.core.component.resource-cache.check-changed`设置为false,则不会检查资源文件是否有变化,不会自动更新缓存的解析结果。
* 将日志级别设置为info,减少日志输出

## 查看统计信息

通过prometheus度量对外暴露了Metrics信息。在quarks框架下使用`/q/metrics`
查看统计信息。在springboot框架下,使用`/actuator/prometheus`查看统计信息。

通过stat链接来查看Nop平台内部的细粒度的统计信息

1. `/r/DevStat__jdbcSqlStats` 查看每一个sql语句的执行时间、执行次数以及时间范围分布
2. `/r/DevStat__rpcServerStats` 查看每一个后台服务函数的执行时间、执行次数,以及时间范围分布
3. `/r/DevStat__rpcClientStats` 查看每一个rpc客户端调用的执行时间、执行次数,以及时间范围分布
42 changes: 42 additions & 0 deletions nop-biz/src/main/java/io/nop/biz/dev/DevStatBizModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.nop.biz.dev;

import io.nop.api.core.annotations.biz.BizModel;
import io.nop.api.core.annotations.biz.BizQuery;
import io.nop.api.core.annotations.core.Description;
import io.nop.api.core.annotations.core.Locale;
import io.nop.api.core.annotations.core.Name;
import io.nop.api.core.annotations.core.Optional;
import io.nop.core.stat.GlobalStatManager;
import io.nop.core.stat.JdbcSqlStatValue;
import io.nop.core.stat.RpcClientStat;
import io.nop.core.stat.RpcServerStat;

import java.util.List;

@Locale("zh-CN")
@BizModel("DevStat")
public class DevStatBizModel {
@BizQuery
@Description("jdbc调用的统计信息")
public List<JdbcSqlStatValue> jdbcSqlStats(@Name("orderByAvgTime") @Optional Boolean orderByAvgTime) {
if (orderByAvgTime == null)
orderByAvgTime = true;
return GlobalStatManager.instance().getAllJdbcSqlStat(orderByAvgTime);
}

@BizQuery
@Description("rpc服务调用的统计信息")
public List<RpcServerStat> rpcServerStats(@Name("orderByAvgTime") @Optional Boolean orderByAvgTime) {
if (orderByAvgTime == null)
orderByAvgTime = true;
return GlobalStatManager.instance().getAllRpcServerStats(orderByAvgTime);
}

@BizQuery
@Description("rpc客户端调用的统计信息")
public List<RpcClientStat> rpcClientStats(@Name("orderByAvgTime") @Optional Boolean orderByAvgTime) {
if (orderByAvgTime == null)
orderByAvgTime = true;
return GlobalStatManager.instance().getAllRpcClientStats(orderByAvgTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@
</ioc:condition>
</bean>

<bean id="nopDevStatBizModel" class="io.nop.biz.dev.DevStatBizModel">
<ioc:condition>
<if-property name="nop.biz.stat.enabled" enableIfMissing="true" />
</ioc:condition>
</bean>

<bean id="nopQueryBeanArgsNormalizer" ioc:default="true" class="io.nop.biz.crud.QueryBeanArgsNormalizer"/>

<bean id="nopFilterArgsNormalizer" class="io.nop.biz.crud.FilterArgsNormalizer"/>
Expand Down
11 changes: 11 additions & 0 deletions nop-core/src/main/java/io/nop/core/CoreConfigs.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ public interface CoreConfigs {
String CFG_COMPONENT_RESOURCE_CACHE_NAMED_REFRESH_MIN_INTERVAL = "nop.core.component.resource-cache.{name}.refresh-min-interval";
String CFG_COMPONENT_RESOURCE_CACHE_NAMED_TIMEOUT = "nop.core.component.resource-cache.{name}.timeout";

@Description("SQL统计条目缓存的最大数量")
IConfigReference<Integer> CFG_CORE_STAT_SQL_CACHE_MAX_SIZE = varRef(s_loc, "nop.core.stat.sql-cache-max-size", Integer.class, 1000);

@Description("RPC客户端调用统计缓存的最大数量")
IConfigReference<Integer> CFG_CORE_STAT_RPC_CLIENT_CACHE_MAX_SIZE = varRef(s_loc, "nop.core.stat.rpc-client-cache-max-size",
Integer.class, 3000);

@Description("RPC服务端调用统计缓存的最大数量")
IConfigReference<Integer> CFG_CORE_STAT_RPC_SERVER_CACHE_MAX_SIZE = varRef(s_loc, "nop.core.stat.rpc-server-cache-max-size",
Integer.class, 10000);

@Description("是否启用命令行支持")
IConfigReference<Boolean> CFG_CORE_NOP_COMMAND_EXECUTOR_ENABLED = varRef(s_loc, "nop.core.nop-command-executor.enabled",
Boolean.class, true);
Expand Down
Loading

0 comments on commit f6dcbfa

Please sign in to comment.