improve monitor support

This commit is contained in:
wenshao
2013-08-17 00:43:37 +08:00
parent 73f72e0f94
commit 8ab0219c4e
9 changed files with 300 additions and 14 deletions
@@ -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();
@@ -23,9 +23,9 @@ public class MonitorContext {
private final Map<String, Object> atrributes = new HashMap<String, Object>();
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;
@@ -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<DruidDataSourceStatValue> dataSourceList) {
save(dataSourceStatBeanInfo, ctx, dataSourceList);
for (DruidDataSourceStatValue dataSourceStatValue : dataSourceList) {
List<JdbcSqlStatValue> 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<String, Object> 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) {
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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)
);
@@ -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);