当前位置:网站首页>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;
}
边栏推荐
- Alibaba P8 teaches you how to realize multithreading in automated testing? Hurry up and stop
- 数字三角形模型 AcWing 275. 传纸条
- 【MySQL】数据库进阶之触发器内容详解
- Gson converts the entity class to JSON times declare multiple JSON fields named
- FPGA knowledge accumulation [6]
- 串口实验——简单数据收发
- ESP32-ULP协处理器低功耗模式RTC GPIO中断唤醒
- Required String parameter ‘XXX‘ is not present
- Digital triangle model acwing 275 Pass a note
- Interpolation lookup (two methods)
猜你喜欢

Greenplum 6.x common statements

Greenplum 6.x build_ Environment configuration

Nanjing commercial housing sales enabled electronic contracts, and Junzi sign assisted in the online signing and filing of housing transactions

最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼

Output a spiral matrix C language

Digital triangle model acwing 1027 Grid access

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

H3C VXLAN配置

Digital triangle model acwing 275 Pass a note

Routing information protocol rip
随机推荐
Uniapp wechat applet monitoring network
How to realize sliding operation component in fast application
Common operating commands of Linux
Count sort (diagram)
C language for calculating the product of two matrices
Redis fault handling "can't save in background: fork: cannot allocate memory“
Greenplum 6.x build_ Environment configuration
Three usage scenarios of annotation @configurationproperties
MAC OSX php dyld: Library not loaded: /usr/local/xxxx. dylib
【Istio Network CRD VirtualService、Envoyfilter】
注解@ConfigurationProperties的三种使用场景
How to add a mask of a target in a picture
Vagrant failed to mount directory mount: unknown filesystem type 'vboxsf'
年薪50w阿里P8亲自下场,教你如何从测试进阶
模拟卷Leetcode【普通】1705. 吃苹果的最大数目
硬件大熊原创合集(2022/05更新)
ESP32-ULP协处理器低功耗模式RTC GPIO中断唤醒
Introduction to data fragmentation
ncs成都新电面试经验
年薪50w阿裏P8親自下場,教你如何從測試進階