diff --git a/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlExprParser.java b/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlExprParser.java index 4c9d13bc0f..87303587d2 100644 --- a/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlExprParser.java +++ b/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlExprParser.java @@ -727,6 +727,10 @@ public class MySqlExprParser extends SQLExprParser { if (lexer.token() == Token.KEY) { lexer.nextToken(); } + + if (lexer.token() == Token.INDEX) { + lexer.nextToken(); + } MySqlUnique unique = new MySqlUnique(); diff --git a/src/main/java/com/alibaba/druid/support/monitor/MonitorContext.java b/src/main/java/com/alibaba/druid/support/monitor/MonitorContext.java index 3ae60f3389..1737d723c4 100644 --- a/src/main/java/com/alibaba/druid/support/monitor/MonitorContext.java +++ b/src/main/java/com/alibaba/druid/support/monitor/MonitorContext.java @@ -23,9 +23,9 @@ public class MonitorContext { private final Map atrributes = new HashMap(); - private String domainName = "defaultDomain"; - private String appName = "defaultApp"; - private String clusterName = "defaultCluster"; + private String domainName = "default"; + private String appName = "default"; + private String clusterName = "default"; private String host; private int pid; diff --git a/src/main/java/com/alibaba/druid/support/monitor/dao/MonitorDaoJdbcImpl.java b/src/main/java/com/alibaba/druid/support/monitor/dao/MonitorDaoJdbcImpl.java index d2741c0fa4..5cbaf877eb 100644 --- a/src/main/java/com/alibaba/druid/support/monitor/dao/MonitorDaoJdbcImpl.java +++ b/src/main/java/com/alibaba/druid/support/monitor/dao/MonitorDaoJdbcImpl.java @@ -56,6 +56,7 @@ public class MonitorDaoJdbcImpl implements MonitorDao { private DataSource dataSource; + private BeanInfo dataSourceStatBeanInfo = new BeanInfo(DruidDataSourceStatValue.class); private BeanInfo sqlStatBeanInfo = new BeanInfo(JdbcSqlStatValue.class); private BeanInfo springMethodStatBeanInfo = new BeanInfo(SpringMethodStatValue.class); private BeanInfo webURIStatBeanInfo = new BeanInfo(WebURIStatValue.class); @@ -65,7 +66,8 @@ public class MonitorDaoJdbcImpl implements MonitorDao { } public void createTables(String dbType) { - String[] resources = new String[] { "const.sql", // + String[] resources = new String[] { "basic.sql", // + "const.sql", // "datasource.sql", // "springmethod.sql", // "sql.sql", // @@ -96,6 +98,8 @@ public class MonitorDaoJdbcImpl implements MonitorDao { @Override public void saveSql(MonitorContext ctx, List dataSourceList) { + save(dataSourceStatBeanInfo, ctx, dataSourceList); + for (DruidDataSourceStatValue dataSourceStatValue : dataSourceList) { List sqlList = dataSourceStatValue.getSqlList(); save(sqlStatBeanInfo, ctx, sqlList); @@ -232,16 +236,16 @@ public class MonitorDaoJdbcImpl implements MonitorDao { String domain = (String) filters.get("domain"); if (StringUtils.isEmpty(domain)) { - domain = "defaultDomain"; + domain = "default"; } String app = (String) filters.get("app"); if (StringUtils.isEmpty(app)) { - app = "defaultApp"; + app = "default"; } String cluster = (String) filters.get("cluster"); if (StringUtils.isEmpty(cluster)) { - cluster = "defaultCluster"; + cluster = "default"; } String host = (String) filters.get("host"); @@ -364,11 +368,11 @@ public class MonitorDaoJdbcImpl implements MonitorDao { private void loadHashValue(FieldInfo hashField, List list, Map filters) { String domain = (String) filters.get("domain"); if (StringUtils.isEmpty(domain)) { - domain = "defaultDomain"; + domain = "default"; } String app = (String) filters.get("app"); if (StringUtils.isEmpty(app)) { - app = "defaultApp"; + app = "default"; } for (Object statValue : list) { diff --git a/src/main/java/com/alibaba/druid/support/monitor/entity/MonitorApp.java b/src/main/java/com/alibaba/druid/support/monitor/entity/MonitorApp.java new file mode 100644 index 0000000000..55efcdb236 --- /dev/null +++ b/src/main/java/com/alibaba/druid/support/monitor/entity/MonitorApp.java @@ -0,0 +1,47 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.druid.support.monitor.entity; + +public class MonitorApp { + + private long id; + private String domain; + private String app; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getDomain() { + return domain; + } + + public void setDomain(String domain) { + this.domain = domain; + } + + public String getApp() { + return app; + } + + public void setApp(String app) { + this.app = app; + } +} diff --git a/src/main/java/com/alibaba/druid/support/monitor/entity/MonitorCluster.java b/src/main/java/com/alibaba/druid/support/monitor/entity/MonitorCluster.java new file mode 100644 index 0000000000..cddcb4eb5f --- /dev/null +++ b/src/main/java/com/alibaba/druid/support/monitor/entity/MonitorCluster.java @@ -0,0 +1,57 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.druid.support.monitor.entity; + +public class MonitorCluster { + + private long id; + private String domain; + private String app; + private String cluster; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getDomain() { + return domain; + } + + public void setDomain(String domain) { + this.domain = domain; + } + + public String getApp() { + return app; + } + + public void setApp(String app) { + this.app = app; + } + + public String getCluster() { + return cluster; + } + + public void setCluster(String cluster) { + this.cluster = cluster; + } + +} diff --git a/src/main/java/com/alibaba/druid/support/monitor/entity/MonitorDomain.java b/src/main/java/com/alibaba/druid/support/monitor/entity/MonitorDomain.java new file mode 100644 index 0000000000..f502dd761c --- /dev/null +++ b/src/main/java/com/alibaba/druid/support/monitor/entity/MonitorDomain.java @@ -0,0 +1,39 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.druid.support.monitor.entity; + +public class MonitorDomain { + + private long id; + private String domain; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getDomain() { + return domain; + } + + public void setDomain(String domain) { + this.domain = domain; + } + +} diff --git a/src/main/java/com/alibaba/druid/support/monitor/entity/MonitorInstance.java b/src/main/java/com/alibaba/druid/support/monitor/entity/MonitorInstance.java new file mode 100644 index 0000000000..d4536bd0ca --- /dev/null +++ b/src/main/java/com/alibaba/druid/support/monitor/entity/MonitorInstance.java @@ -0,0 +1,95 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.druid.support.monitor.entity; + +import java.util.Date; + +public class MonitorInstance { + + private long id; + private String domain; + private String app; + private String cluster; + private String host; + private String ip; + private Date lastActiveTime; + private Long lastPID; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getDomain() { + return domain; + } + + public void setDomain(String domain) { + this.domain = domain; + } + + public String getApp() { + return app; + } + + public void setApp(String app) { + this.app = app; + } + + public String getCluster() { + return cluster; + } + + public void setCluster(String cluster) { + this.cluster = cluster; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public Date getLastActiveTime() { + return lastActiveTime; + } + + public void setLastActiveTime(Date lastActiveTime) { + this.lastActiveTime = lastActiveTime; + } + + public Long getLastPID() { + return lastPID; + } + + public void setLastPID(Long lastPID) { + this.lastPID = lastPID; + } + +} diff --git a/src/main/resources/support/monitor/mysql/basic.sql b/src/main/resources/support/monitor/mysql/basic.sql new file mode 100644 index 0000000000..cbebb2319a --- /dev/null +++ b/src/main/resources/support/monitor/mysql/basic.sql @@ -0,0 +1,42 @@ +create table druid_domain ( + id bigint(20) AUTO_INCREMENT NOT NULL, + domain varchar(45) NOT NULL, + PRIMARY KEY (id), + UNIQUE INDEX (domain) +); + +insert into druid_domain (domain) values ('default'); + +create table druid_app ( + id bigint(20) AUTO_INCREMENT NOT NULL, + domain varchar(45) NOT NULL, + app varchar(45) NOT NULL, + PRIMARY KEY (id), + UNIQUE (domain, app) +); + +insert into druid_app (domain, app) values ('default', 'default'); + +create table druid_cluster ( + id bigint(20) AUTO_INCREMENT NOT NULL, + domain varchar(45) NOT NULL, + app varchar(45) NOT NULL, + cluster varchar(45) NOT NULL, + PRIMARY KEY (id), + UNIQUE (domain, app, cluster) +); + +insert into druid_cluster (domain, app, cluster) values ('default', 'default', 'default'); + +create table druid_instance ( + id bigint(20) AUTO_INCREMENT NOT NULL, + app varchar(45) NOT NULL, + domain varchar(45) NOT NULL, + cluster varchar(45) NOT NULL, + host varchar(128) NOT NULL, + ip varchar(32) NOT NULL, + lastActiveTime datetime NOT NULL, + lastPID int(10) NOT NULL, + PRIMARY KEY (id), + UNIQUE (domain, app, cluster, host) +); \ No newline at end of file diff --git a/src/test/java/com/alibaba/druid/bvt/support/monitor/MonitorDaoJdbcImplTest.java b/src/test/java/com/alibaba/druid/bvt/support/monitor/MonitorDaoJdbcImplTest.java index e40d90a706..9888a82960 100644 --- a/src/test/java/com/alibaba/druid/bvt/support/monitor/MonitorDaoJdbcImplTest.java +++ b/src/test/java/com/alibaba/druid/bvt/support/monitor/MonitorDaoJdbcImplTest.java @@ -6,8 +6,6 @@ import java.util.List; import junit.framework.TestCase; -import org.junit.Assert; - import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.stat.JdbcSqlStatValue; import com.alibaba.druid.support.monitor.MonitorClient; @@ -23,8 +21,8 @@ public class MonitorDaoJdbcImplTest extends TestCase { @Override protected void setUp() throws Exception { dataSource = new DruidDataSource(); -// dataSource.setUrl("jdbc:h2:mem:test"); - dataSource.setUrl("jdbc:mysql://localhost:3306/druid-monitor"); + dataSource.setUrl("jdbc:h2:mem:test"); +// dataSource.setUrl("jdbc:mysql://localhost:3306/druid-monitor"); dataSource.setUsername("druid"); dataSource.setPassword("druid"); dataSource.setInitialSize(1); @@ -42,7 +40,7 @@ public class MonitorDaoJdbcImplTest extends TestCase { MonitorDaoJdbcImpl dao = new MonitorDaoJdbcImpl(); dao.setDataSource(dataSource); -// dao.createTables("mysql"); + dao.createTables("mysql"); MonitorClient client = new MonitorClient(); client.setDao(dao);