当前位置:网站首页>Druid monitoring - Introduction to JMX usage and principle
Druid monitoring - Introduction to JMX usage and principle
2022-07-07 08:57:00 【bboyzqh】
Recently focused on business , There is little time to update the blog , A while ago, it was a big promotion druid Something is wrong , By the way druid Implementation of monitoring , Don't say here druid The principle of connection pool and JMX Basic knowledge of . To configure Druid There are two main ways of monitoring :
- Mode one : adopt DruidStatManagerFacade To get DruidDataSource Relevant monitoring data ( This method is not used JMX The way ), External data related to such exposure monitoring , The user can directly create an instance and use the method to obtain . The sample code is as follows :
public class DruidStatController {
@GetMapping("/durid/stat")
public Object druidStat(){
// DruidStatManagerFacade#getDataSourceStatDataList This method can obtain the monitoring data of all data sources , besides DruidStatManagerFacade There are also some other ways , You can choose to use .
return DruidStatManagerFacade.getInstance().getDataSourceStatDataList();
}
} - Mode two : adopt http Request internal use JMX To obtain monitoring data , In essence, it's also through DruidStatManagerFa- cade To get DruidDataSource Relevant monitoring data . The configuration is as follows :
The first point :java The project startup parameters are as follows , Open port for web End view :
-Djava.net.preferIPv4Stack=true
-Dcom.sun.management.jmxremote
-Djava.rmi.server.hostname=10.8.3.221
-Dcom.sun.management.jmxremote.port=9004
-Dcom.sun.management.jmxremote.authenticate=falseSecond point :web In Engineering web.xml The configuration is as follows :
<!-- Druid, Monitoring the database , as well as WEB Access connection information -->
<!-- Reference resources : https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_%E9%85%8D%E7%BD%AEWebStatFilter -->
<filter>
<filter-name>DruidWebStatFilter</filter-name>
<filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>
<init-param>
<param-name>exclusions</param-name>
<param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,*.jsp,/druid/*,/download/*</param-value>
</init-param>
<init-param>
<param-name>sessionStatMaxCount</param-name>
<param-value>2000</param-value>
</init-param>
<init-param>
<param-name>sessionStatEnable</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>principalSessionName</param-name>
<param-value>session_user_key</param-value>
</init-param>
<init-param>
<param-name>profileEnable</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>DruidWebStatFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- To configure Druid Monitoring information display page -->
<servlet>
<servlet-name>DruidStatView</servlet-name>
<servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
<init-param>
<!-- Allow to clear Statistics -->
<param-name>resetEnable</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<!-- user name -->
<param-name>loginUsername</param-name>
<param-value>druid</param-value>
</init-param>
<init-param>
<!-- password -->
<param-name>loginPassword</param-name>
<param-value>druid</param-value>
</init-param>
<!-- The remote access JavaSE Project use jmx Connect -->
<init-param>
<param-name>jmxUrl</param-name>
<param-value>service:jmx:rmi:///jndi/rmi://10.8.3.221:9004/jmxrmi</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DruidStatView</servlet-name>
<url-pattern>/druid/*</url-pattern>
</servlet-mapping>
</web-app>
The main logic of this way is StatViewServlet in , If configured jmxUrl Properties will go remote JMX, The process is as follows :

Core source code reference :
/**
* StatViewServlet Class . The program first determines whether it exists jmx Connection address , If it doesn't exist , Then call the local duird service ; If there is , Then call remote jmx service . It's going on jmx signal communication , First of all, let's judge jmx Whether the connection has been established successfully , If it has been established successfully ,
Then communicate directly , If it has not been successfully established before , Will try to rebuild .
* @param url Service address to connect
* @return Returned after calling the service json character string
*/
protected String process(String url) {
String resp = null;
if (jmxUrl == null) {
resp = statService.service(url);
} else {
if (conn == null) {// Connection creation failed during initialization
try {// Try to reconnect
initJmxConn();
} catch (IOException e) {
LOG.error("init jmx connection error", e);
resp = DruidStatService.returnJSONResult(DruidStatService.RESULT_CODE_ERROR,
"init jmx connection error" + e.getMessage());
}
if (conn != null) {// Successful connection
try {
resp = getJmxResult(conn, url);
} catch (Exception e) {
LOG.error("get jmx data error", e);
resp = DruidStatService.returnJSONResult(DruidStatService.RESULT_CODE_ERROR, "get data error:"+ e.getMessage());
}
}
} else {// Successful connection
try {
resp = getJmxResult(conn, url);
} catch (Exception e) {
LOG.error("get jmx data error", e);
resp = DruidStatService.returnJSONResult(DruidStatService.RESULT_CODE_ERROR,
"get data error" + e.getMessage());
}
}
}
return resp;
}
边栏推荐
- 【ChaosBlade:节点磁盘填充、杀节点上指定进程、挂起节点上指定进程】
- go mod module declares its path as: gtihub. com/xxx-xx but was required as:xx-xx
- Cmake command line use
- 数字三角形模型 AcWing 1027. 方格取数
- 年薪50w阿里P8亲自下场,教你如何从测试进阶
- Synchronized underlying principle, volatile keyword analysis
- leetcode134. gas station
- How to realize sliding operation component in fast application
- 对API接口或H5接口做签名认证
- Redis summary
猜你喜欢

Goldbach conjecture C language
![Data analysis methodology and previous experience summary 2 [notes dry goods]](/img/e1/643e847a777e1effcbd39f8b009e2b.png)
Data analysis methodology and previous experience summary 2 [notes dry goods]

Unityshader introduction essentials personal summary -- Basic chapter (I)
![FPGA knowledge accumulation [6]](/img/db/c3721c3e842ddf4c1088a3f54e9f2a.jpg)
FPGA knowledge accumulation [6]

Markdown编辑器Editor.md插件的使用

Routing information protocol rip
![[MySQL] detailed explanation of trigger content of database advanced](/img/6c/8aad649e4ba1160db3aea857ecf4a1.png)
[MySQL] detailed explanation of trigger content of database advanced

Lenovo hybrid cloud Lenovo xcloud: 4 major product lines +it service portal

MySQL master-slave delay solution

Mountaineering team (DFS)
随机推荐
let const
Greenplum6.x搭建_环境配置
RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
Isomorphic C language
xray的简单使用
STM32串口寄存器库函数配置方法
【istio简介、架构、组件】
Problems encountered in the use of go micro
测试人一定要会的技能:selenium的三种等待方式解读,清晰明了
阿里p8推荐,测试覆盖率工具—Jacoco,实用性极佳
MySQL partition explanation and operation statement
leetcode135. Distribute candy
OpenGL frame buffer
平台化,强链补链的一个支点
2022-07-06 unity core 9 - 3D animation
Simple use of Xray
Platformization, a fulcrum of strong chain complementing chain
阿里p8手把手教你,自动化测试应该如何实现多线程?赶紧码住
Lenovo hybrid cloud Lenovo xcloud: 4 major product lines +it service portal
Other 7 features of TCP [sliding window mechanism ▲]