DBCP의 POOL 상태를 모니터링 하는 페이지
톰캣에 default 로 설치된 dbcp 라이브러리를 이용하면 org.apache.tomcat.dbcp.dbcp.*
이고 일반적인 dbcp를 다운받아 사용할경우 org.apache.commons.dbcp.* 로 import 하도록 한다.
<%@ page language="java" contentType="text/html; charset=EUC-KR" %>
<%@ page import="
javax.naming.*,
javax.sql.*,
org.apache.tomcat.dbcp.dbcp.*"
%>
<%
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/mydb");
BasicDataSource bds = (BasicDataSource)ds;
String dbname = "caelum";
try {
int bdsNumActive = bds.getNumActive();
int bdsMaxActive = bds.getMaxActive();
int bdsNumIdle = bds.getNumIdle();
long bdsMaxWait = bds.getMaxWait();
String fontcolor = "";
if (bdsNumActive <= 400) {
fontcolor = "<font color='green'>";
} else if (bdsNumActive > 400 && bdsNumActive <= 500) {
fontcolor = "<font color='orange'>";
} else {
fontcolor = "<font color='red'>";
}
%>
<table cellpadding='3' cellspacing='0' border='1'>
<tr>
<td colspan='4' align='center'><b><%=dbname%></b> DataSource</td>
</tr>
<tr>
<td height='24' align='center' alt='connections that are processing'># Active Connections</td>
<td height='24' align='center' alt='total size of pool'>Maximum Active Connections</td>
<td height='24' align='center' alt='connections that are idle in the pool'># of Idle Connections</td>
<td height='24' align='center'>Maxium Wait period before timeout</td>
</tr>
<tr>
<td align='right'><%=fontcolor%><%=bdsNumActive%></font></td>
<td align='right'><%=bdsMaxActive%></td>
<td align='right'><%=bdsNumIdle%></td>
<td align='right'><%=bdsMaxWait%></td>
</tr>
</table>
<%
} catch(Exception e) {
out.println(e.toString());
}
%>
[출처] [본문스크랩] DBCP POOL 모니터링페이지|작성자 메멘토