mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
jconsole
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@228 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.alibaba.druid.jconsole;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Panel;
|
||||
|
||||
import com.sun.tools.jconsole.JConsoleContext;
|
||||
|
||||
public class DataSourcePanel extends Panel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private JConsoleContext context;
|
||||
|
||||
public DataSourcePanel(JConsoleContext context){
|
||||
this.context = context;
|
||||
|
||||
this.setBackground(Color.RED);
|
||||
}
|
||||
|
||||
public JConsoleContext getJConsoleContext() {
|
||||
return context;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.alibaba.druid.jconsole;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.EventQueue;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
@@ -16,13 +17,18 @@ import javax.management.ObjectInstance;
|
||||
import javax.management.ObjectName;
|
||||
import javax.management.openmbean.CompositeData;
|
||||
import javax.management.openmbean.TabularData;
|
||||
import javax.management.remote.JMXConnector;
|
||||
import javax.management.remote.JMXConnectorFactory;
|
||||
import javax.management.remote.JMXServiceURL;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.JdbcStatManager;
|
||||
@@ -52,13 +58,21 @@ public class DruidPanel extends JPanel {
|
||||
tree = new JTree(rootNode);
|
||||
tree.setRootVisible(false);
|
||||
|
||||
tree.addTreeSelectionListener(new TreeSelectionListener() {
|
||||
|
||||
@Override
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
treeSelect(e);
|
||||
}
|
||||
});
|
||||
|
||||
JScrollPane theScrollPane = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
JPanel treePanel = new JPanel(new BorderLayout());
|
||||
treePanel.add(theScrollPane, BorderLayout.CENTER);
|
||||
mainSplit.add(treePanel, JSplitPane.LEFT, 0);
|
||||
mainSplit.setLeftComponent(treePanel);
|
||||
|
||||
sheet = new JPanel();
|
||||
mainSplit.add(sheet, JSplitPane.RIGHT, 0);
|
||||
mainSplit.setRightComponent(sheet);
|
||||
|
||||
add(mainSplit);
|
||||
|
||||
@@ -67,6 +81,9 @@ public class DruidPanel extends JPanel {
|
||||
// init();
|
||||
}
|
||||
|
||||
private void treeSelect(TreeSelectionEvent e) {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
try {
|
||||
ManagementFactory.getPlatformMBeanServer().registerMBean(JdbcStatManager.getInstance(), new ObjectName("com.alibaba.druid:type=JdbcStatManager"));
|
||||
@@ -93,9 +110,14 @@ public class DruidPanel extends JPanel {
|
||||
}
|
||||
|
||||
protected Object doInBackground(JConsoleContext context) throws Exception {
|
||||
//dataSourcesNode.removeAllChildren();
|
||||
|
||||
MBeanServerConnection conn = context.getMBeanServerConnection();
|
||||
doInBackground(context.getMBeanServerConnection());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void doInBackground(MBeanServerConnection conn) throws Exception {
|
||||
// dataSourcesNode.removeAllChildren();
|
||||
|
||||
List<ObjectInstance> stats = new ArrayList<ObjectInstance>();
|
||||
List<ObjectInstance> dataSourceInstances = new ArrayList<ObjectInstance>();
|
||||
|
||||
@@ -123,7 +145,7 @@ public class DruidPanel extends JPanel {
|
||||
CompositeData rowData = (CompositeData) item;
|
||||
|
||||
DataSourceInfo dataSourceInfo = new DataSourceInfo(rowData);
|
||||
|
||||
|
||||
DefaultMutableTreeNode dataSourceNode = new DefaultMutableTreeNode(dataSourceInfo.getName(), true);
|
||||
dataSourceNode.setUserObject(dataSourceInfo);
|
||||
|
||||
@@ -160,10 +182,36 @@ public class DruidPanel extends JPanel {
|
||||
|
||||
dataSourcesNode.add(dataSource);
|
||||
}
|
||||
|
||||
// TreePath path = new TreePath(dataSourcesNode.children());
|
||||
// tree.scrollPathToVisible(path);
|
||||
|
||||
return null;
|
||||
// TreePath path = new TreePath(dataSourcesNode.children());
|
||||
// tree.scrollPathToVisible(path);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
JFrame frame = new JFrame();
|
||||
|
||||
DruidPanel panel = new DruidPanel();
|
||||
|
||||
frame.getContentPane().add(panel);
|
||||
frame.pack();
|
||||
frame.setSize(1024, 768);
|
||||
|
||||
final String urlPath = "/jndi/rmi://10.20.138.25:9006/jmxrmi";
|
||||
JMXServiceURL jmxUrl = new JMXServiceURL("rmi", "", 0, urlPath);
|
||||
|
||||
JMXConnector connector = JMXConnectorFactory.connect(jmxUrl);
|
||||
panel.doInBackground(connector.getMBeanServerConnection());
|
||||
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,13 +41,13 @@ public class Case1 extends TestCase {
|
||||
private String password;
|
||||
private String driverClass;
|
||||
private int initialSize = 10;
|
||||
private int minPoolSize = 1;
|
||||
private int maxPoolSize = 2;
|
||||
private int maxActive = 2;
|
||||
private int minPoolSize = 10;
|
||||
private int maxPoolSize = 50;
|
||||
private int maxActive = 50;
|
||||
private String validationQuery = "SELECT 1";
|
||||
private int threadCount = 2;
|
||||
private int loopCount = 5;
|
||||
final int LOOP_COUNT = 1000 * 1000;
|
||||
private int threadCount = 10;
|
||||
private int loopCount = 4;
|
||||
final int LOOP_COUNT = 1000 * 100;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
jdbcUrl = "jdbc:fake:dragoon_v25masterdb";
|
||||
@@ -113,7 +113,7 @@ public class Case1 extends TestCase {
|
||||
// dataSource.setMaxOpenPreparedStatements(100);
|
||||
dataSource.setUsername(user);
|
||||
dataSource.setPassword(password);
|
||||
dataSource.setConnectionTestStatement("SELECT 1");
|
||||
//dataSource.setConnectionTestStatement("SELECT 1");
|
||||
dataSource.setPartitionCount(1);
|
||||
dataSource.setAcquireIncrement(5);
|
||||
dataSource.setIdleConnectionTestPeriod(0L);
|
||||
|
||||
@@ -41,13 +41,13 @@ public class Case2 extends TestCase {
|
||||
private String password;
|
||||
private String driverClass;
|
||||
private int initialSize = 10;
|
||||
private int minPoolSize = 1;
|
||||
private int maxPoolSize = 2;
|
||||
private int maxActive = 2;
|
||||
private int minPoolSize = 10;
|
||||
private int maxPoolSize = 50;
|
||||
private int maxActive = 50;
|
||||
private String validationQuery = "SELECT 1";
|
||||
private int threadCount = 1;
|
||||
private int loopCount = 5;
|
||||
final int LOOP_COUNT = 1000 * 1000;
|
||||
private int threadCount = 100;
|
||||
private int executeCount = 4;
|
||||
final int LOOP_COUNT = (1000 * 1000) / executeCount;
|
||||
private boolean testOnBorrow = true;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@@ -73,7 +73,7 @@ public class Case2 extends TestCase {
|
||||
dataSource.setValidationQuery(validationQuery);
|
||||
dataSource.setTestOnBorrow(testOnBorrow);
|
||||
|
||||
for (int i = 0; i < loopCount; ++i) {
|
||||
for (int i = 0; i < executeCount; ++i) {
|
||||
p0(dataSource, "druid", threadCount);
|
||||
}
|
||||
System.out.println();
|
||||
@@ -95,7 +95,7 @@ public class Case2 extends TestCase {
|
||||
dataSource.setValidationQuery("SELECT 1");
|
||||
dataSource.setTestOnBorrow(testOnBorrow);
|
||||
|
||||
for (int i = 0; i < loopCount; ++i) {
|
||||
for (int i = 0; i < executeCount; ++i) {
|
||||
p0(dataSource, "dbcp", threadCount);
|
||||
}
|
||||
System.out.println();
|
||||
@@ -121,7 +121,7 @@ public class Case2 extends TestCase {
|
||||
dataSource.setIdleConnectionTestPeriod(0L);
|
||||
// dataSource.setDisableConnectionTracking(true);
|
||||
|
||||
for (int i = 0; i < loopCount; ++i) {
|
||||
for (int i = 0; i < executeCount; ++i) {
|
||||
p0(dataSource, "boneCP", threadCount);
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
@@ -20,11 +20,11 @@ public class Case3 extends TestCase {
|
||||
private String password;
|
||||
private String driverClass;
|
||||
private int maxIdle = 40;
|
||||
private int maxActive = 140;
|
||||
private int maxWait = 50;
|
||||
private int maxActive = 50;
|
||||
private int maxWait = 500;
|
||||
private String validationQuery = "SELECT 1";
|
||||
private int threadCount = 14;
|
||||
private int loopCount = 5;
|
||||
private int loopCount = 3;
|
||||
final int LOOP_COUNT = 1000 * 100;
|
||||
private boolean testOnBorrow = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user