当前位置:网站首页>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=false
Second 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;
}
边栏推荐
- Vagrant failed to mount directory mount: unknown filesystem type 'vboxsf'
- Greenplum 6.x version change record common manual
- Selenium automation integration, eight years of testing experience, soft test engineer, an article to teach you
- 9c09730c0eea36d495c3ff6efe3708d8
- Implement custom memory allocator
- LeetCode 715. Range 模块
- Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022
- UnityShader入门精要个人总结--基础篇(一)
- Frequently Asked Coding Problems
- Alibaba P8 teaches you how to realize multithreading in automated testing? Hurry up and stop
猜你喜欢
Digital triangle model acwing 1027 Grid access
leetcode135. Distribute candy
NCS Chengdu New Electric interview Experience
Goldbach conjecture C language
H3C VXLAN配置
Esp32-ulp coprocessor low power mode RTC GPIO interrupt wake up
Greenplum6.x常用语句
Quick sorting (detailed illustration of single way, double way, three way)
Routing information protocol rip
LeetCode 736. LISP syntax parsing
随机推荐
ChaosBlade:混沌工程简介(一)
Output all composite numbers between 6 and 1000
OpenGL帧缓冲
MAC OSX php dyld: Library not loaded: /usr/local/xxxx. dylib
实现自定义内存分配器
ncs成都新电面试经验
UnityShader入门精要个人总结--基础篇(一)
阿里p8手把手教你,自动化测试应该如何实现多线程?赶紧码住
How to add a mask of a target in a picture
Opencv converts 16 bit image data to 8 bits and 8 to 16
The longest ascending subsequence model acwing 1017 Strange thief Kidd's glider
Greenplum6.x搭建_安装
数字三角形模型 AcWing 1027. 方格取数
Lenovo hybrid cloud Lenovo xcloud: 4 major product lines +it service portal
NCS Chengdu Xindian interview experience
Platformization, a fulcrum of strong chain complementing chain
Why choose cloud native database
Sign and authenticate API interface or H5 interface
Cmake command line use
NCS Chengdu New Electric interview Experience