mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve monitor support
This commit is contained in:
@@ -526,5 +526,24 @@
|
||||
<version>2.0.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.javasimon</groupId>
|
||||
<artifactId>javasimon-spring</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.javasimon</groupId>
|
||||
<artifactId>javasimon-jdbc4</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.javasimon</groupId>
|
||||
<artifactId>javasimon-javaee</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.alibaba.druid.support.monitor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class MonitorContext {
|
||||
|
||||
private String appName;
|
||||
private Date collectTime;
|
||||
|
||||
public String getAppName() {
|
||||
return appName;
|
||||
}
|
||||
|
||||
public void setAppName(String appName) {
|
||||
this.appName = appName;
|
||||
}
|
||||
|
||||
public Date getCollectTime() {
|
||||
return collectTime;
|
||||
}
|
||||
|
||||
public void setCollectTime(Date collectTime) {
|
||||
this.collectTime = collectTime;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.alibaba.druid.support.monitor;
|
||||
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.alibaba.druid.support.monitor.dao.MonitorDao;
|
||||
|
||||
public class MonitorService {
|
||||
|
||||
private final static long DEFAULT_TIME_BETWEEN_COLLECT = 60 * 5;
|
||||
|
||||
private ScheduledExecutorService scheduler;
|
||||
private int schedulerThreadSize = 1;
|
||||
|
||||
private long timeBeetweenSqlCollect = DEFAULT_TIME_BETWEEN_COLLECT;
|
||||
private long timeBeetweenSpringCollect = DEFAULT_TIME_BETWEEN_COLLECT;
|
||||
private long timeBeetweenWebUriCollect = DEFAULT_TIME_BETWEEN_COLLECT;
|
||||
private TimeUnit timeUnit = TimeUnit.SECONDS;
|
||||
|
||||
private MonitorDao dao;
|
||||
|
||||
public void start() {
|
||||
if (scheduler == null) {
|
||||
scheduler = new ScheduledThreadPoolExecutor(schedulerThreadSize);
|
||||
}
|
||||
|
||||
scheduler.scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
collectSql();
|
||||
}
|
||||
}, timeBeetweenSqlCollect, timeBeetweenSqlCollect, timeUnit);
|
||||
|
||||
scheduler.scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
collectSpringMethod();
|
||||
}
|
||||
}, timeBeetweenSpringCollect, timeBeetweenSpringCollect, timeUnit);
|
||||
|
||||
scheduler.scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
collectWebURI();
|
||||
}
|
||||
}, timeBeetweenWebUriCollect, timeBeetweenWebUriCollect, timeUnit);
|
||||
}
|
||||
|
||||
public ScheduledExecutorService getScheduler() {
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
public void setScheduler(ScheduledExecutorService scheduler) {
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
|
||||
private void collectSql() {
|
||||
|
||||
}
|
||||
|
||||
private void collectSpringMethod() {
|
||||
|
||||
}
|
||||
|
||||
private void collectWebURI() {
|
||||
|
||||
}
|
||||
|
||||
public MonitorDao getDao() {
|
||||
return dao;
|
||||
}
|
||||
|
||||
public void setDao(MonitorDao dao) {
|
||||
this.dao = dao;
|
||||
}
|
||||
|
||||
public long getTimeBeetweenSqlCollect() {
|
||||
return timeBeetweenSqlCollect;
|
||||
}
|
||||
|
||||
public void setTimeBeetweenSqlCollect(long timeBeetweenSqlCollect) {
|
||||
this.timeBeetweenSqlCollect = timeBeetweenSqlCollect;
|
||||
}
|
||||
|
||||
public long getTimeBeetweenSpringCollect() {
|
||||
return timeBeetweenSpringCollect;
|
||||
}
|
||||
|
||||
public void setTimeBeetweenSpringCollect(long timeBeetweenSpringCollect) {
|
||||
this.timeBeetweenSpringCollect = timeBeetweenSpringCollect;
|
||||
}
|
||||
|
||||
public long getTimeBeetweenWebUriCollect() {
|
||||
return timeBeetweenWebUriCollect;
|
||||
}
|
||||
|
||||
public void setTimeBeetweenWebUriCollect(long timeBeetweenWebUriCollect) {
|
||||
this.timeBeetweenWebUriCollect = timeBeetweenWebUriCollect;
|
||||
}
|
||||
|
||||
public TimeUnit getTimeUnit() {
|
||||
return timeUnit;
|
||||
}
|
||||
|
||||
public void setTimeUnit(TimeUnit timeUnit) {
|
||||
this.timeUnit = timeUnit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.support.monitor.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.stat.JdbcSqlStatValue;
|
||||
import com.alibaba.druid.support.http.stat.WebURIStatValue;
|
||||
import com.alibaba.druid.support.monitor.MonitorContext;
|
||||
import com.alibaba.druid.support.spring.stat.SpringMethodStatValue;
|
||||
|
||||
public interface MonitorDao {
|
||||
|
||||
void saveSql(MonitorContext ctx, List<JdbcSqlStatValue> sqlList);
|
||||
|
||||
void saveSpringMethod(MonitorContext ctx, List<SpringMethodStatValue> methodList);
|
||||
|
||||
void saveWebURI(MonitorContext ctx, List<WebURIStatValue> uriList);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.alibaba.druid.support.monitor.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.stat.JdbcSqlStatValue;
|
||||
import com.alibaba.druid.support.http.stat.WebURIStatValue;
|
||||
import com.alibaba.druid.support.monitor.MonitorContext;
|
||||
import com.alibaba.druid.support.spring.stat.SpringMethodStatValue;
|
||||
|
||||
public class MonitorDaoJdbcImpl implements MonitorDao {
|
||||
|
||||
@Override
|
||||
public void saveSql(MonitorContext ctx, List<JdbcSqlStatValue> sqlList) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveSpringMethod(MonitorContext ctx, List<SpringMethodStatValue> methodList) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveWebURI(MonitorContext ctx, List<WebURIStatValue> uriList) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user