通过JMX技术来监控Oracle的JVM
Druid是一个JDBC组件,它包括三部分:
DruidDriver 代理Driver,能够提供基于Filter-Chain模式的插件体系。
DruidDataSource 高效可管理的数据库连接池。
SQLParser
Druid可以做什么?
1) 可以监控数据库访问性能,Druid内置提供了一个功能强大的StatFilter插件,能够详细统计SQL的执行性能,这对于线上分析数据库访问性能有帮助。
2) 替换DBCP和C3P0。Druid提供了一个高效、功能强大、可扩展性好的数据库连接池。
3) 数据库密码加密。直接把数据库密码写在配置文件中,这是不好的行为,容易导致安全问题。DruidDruiver和DruidDataSource都支持PasswordCallback。
4) SQL执行日志,Druid提供了不同的LogFilter,能够支持Common-Logging、Log4j和JdkLog,你可以按需要选择相应的LogFilter,监控你应用的数据库访问情况。
扩展JDBC,如果你要对JDBC层有编程的需求,可以通过Druid提供的Filter-Chain机制,很方便编写JDBC层的扩展插件。
监控jboss数据库连接池的实现import java.util.Iterator
import java.util.Properties
import java.util.Set
import javax.management.MBeanInfo
import javax.management.MBeanOperationInfo
import javax.management.MBeanParameterInfo
import javax.management.ObjectInstance
import javax.management.ObjectName
import javax.naming.InitialContext
import org.jboss.jmx.adaptor.rmi.RMIAdaptor
public class DataSourceManger {
public static void main(String[] args) {
// TODO 自动生成方法存根
try {
// Get RMIAdaptor Object
Properties pro = new Properties()
pro.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory")
pro.setProperty("java.naming.provider.url", "jnp://localhost:1099")
pro.setProperty("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces")
InitialContext ic = new InitialContext(pro)
RMIAdaptor server = (RMIAdaptor) ic.lookup("jmx/rmi/RMIAdaptor")
ObjectName name = new ObjectName(
"jboss.jca:name=jdbc/baosigpo,service=ManagedConnectionPool")
ObjectName lname = new ObjectName(
"jboss.jca:name=jdbc/baosigpo,service=LocalTxCM")
String AvailableConnectionCount = server.getAttribute(name,
"AvailableConnectionCount").toString()
System.out.println("===========avlide============"
+ AvailableConnectionCount)
String InUseConnectionCount = server.getAttribute(name,
"InUseConnectionCount").toString()
System.out.println("===========InUseConnectionCount============"
+ InUseConnectionCount)
String ConnectionCreatedCount = server.getAttribute(name,
"ConnectionCreatedCount").toString()
System.out.println("===========ConnectionCreatedCount============"
+ ConnectionCreatedCount)
String ConnectionDestroyedCount = server.getAttribute(name,
"ConnectionDestroyedCount").toString()
System.out
.println("===========ConnectionDestroyedCount============"
+ ConnectionDestroyedCount)
ConnectionDestroyedCount = server.getAttribute(name,
"ConnectionDestroyedCount").toString()
System.out
.println("===========ConnectionDestroyedCount============"
+ ConnectionDestroyedCount)
String[] argTypes = new String[0]
int i = 0
i = Integer.parseInt(AvailableConnectionCount)
Object opReturn = null
if (i <1) {//监控可用连接数。
StringBuffer sb = new StringBuffer()
sb.append("oper before DataSource Pool info : \r\n")
sb.append(" AvailableConnectionCount="
+ AvailableConnectionCount)
sb.append(" InUseConnectionCount=" + InUseConnectionCount)
sb.append(" ConnectionCreatedCount="
+ ConnectionCreatedCount)
sb.append(" ConnectionDestroyedCount="
+ ConnectionDestroyedCount)
sb.append("\r\n")
//opReturn = server.invoke(name, "flush", argTypes, argTypes)
/*调用mbean的方法释放连接 begin 本实现方法对应jboss3.2.3
对于jboss4以后的版本只需调用
//opReturn = server.invoke(name, "flush", argTypes, argTypes)
**/
opReturn = server.invoke(name, "stop", argTypes, argTypes)
opReturn = server.invoke(name, "start", argTypes, argTypes)
opReturn = server.invoke(lname, "stop", argTypes, argTypes)
opReturn = server.invoke(lname, "start", argTypes, argTypes)
/*调用mbean的方法释放连接 end
**/
AvailableConnectionCount = server.getAttribute(name,
"AvailableConnectionCount").toString()
InUseConnectionCount = server.getAttribute(name,
"InUseConnectionCount").toString()
ConnectionCreatedCount = server.getAttribute(name,
"ConnectionCreatedCount").toString()
ConnectionDestroyedCount = server.getAttribute(name,
"ConnectionDestroyedCount").toString()
ConnectionDestroyedCount = server.getAttribute(name,
"ConnectionDestroyedCount").toString()
sb.append("oper afer DataSource Pool info :\r\n")
sb.append(" AvailableConnectionCount="
+ AvailableConnectionCount)
sb.append(" InUseConnectionCount=" + InUseConnectionCount)
sb.append(" ConnectionCreatedCount="
+ ConnectionCreatedCount)
sb.append(" ConnectionDestroyedCount="
+ ConnectionDestroyedCount)
//writeLog(sb.toString()) *** 作日志信息
System.out.println("===========op SUCCESS============")
}
} catch (Exception ex) {
ex.printStackTrace()
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)