forked from alibaba/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/com/alibaba/druid/support/monitor/MonitorContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
110 changes: 110 additions & 0 deletions
110
src/main/java/com/alibaba/druid/support/monitor/MonitorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/alibaba/druid/support/monitor/dao/MonitorDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/alibaba/druid/support/monitor/dao/MonitorDaoJdbcImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
|
||
} | ||
|
||
} |