編寫自定義的proxool statistics

標簽: 瀏覽(11874)  日期:2007-04-26
 調用自定義的proxool statistics

StatisticsListenerIF myStatisticsListener = new MyStatisticsListener();

try {

ProxoolFacade.addStatisticsListener("instant_alias",myStatisticsListener);

} catch (ProxoolException e1) {

e1.printStackTrace();

}


自定義的proxool statistics:


class MyStatisticsListener implements StatisticsListenerIF {

static Logger log = Logger.getLogger("Businesslog");

private static final DateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm:ss");

public void statistics(String alias, StatisticsIF statistics) {

double activecount = statistics.getAverageActiveCount();

double activetime = statistics.getAverageActiveTime();

long refusedcount = statistics.getRefusedCount();

double refusedcountpersecond = statistics.getRefusedPerSecond();

long servedcount = statistics.getServedCount();

double servedcountpersecond = statistics.getServedPerSecond();

StringBuffer connectionsBuffer = new StringBuffer();

connectionsBuffer.append("Average Active Count:");

connectionsBuffer.append(activecount);

connectionsBuffer.append(",Average Active Time Per Connection:");

connectionsBuffer.append(activetime);

connectionsBuffer.append(",Refused Count:");

connectionsBuffer.append(refusedcount);

connectionsBuffer.append(",Refused Per Second:");

connectionsBuffer.append(refusedcountpersecond);

connectionsBuffer.append(",Served Count:");

connectionsBuffer.append(servedcount);

connectionsBuffer.append(",Served Per Second:");

connectionsBuffer.append(servedcountpersecond);

connectionsBuffer.append(" \n ");

try {

SnapshotIF snapshot = ProxoolFacade.getSnapshot("instant_alias", true);


connectionsBuffer.append(snapshot.getActiveConnectionCount());

connectionsBuffer.append(" (active), ");

connectionsBuffer.append(snapshot.getAvailableConnectionCount());

connectionsBuffer.append(" (available), ");

if (snapshot.getOfflineConnectionCount() > 0) {

connectionsBuffer.append(snapshot.getOfflineConnectionCount());

connectionsBuffer.append(" (offline), ");

}

connectionsBuffer.append(snapshot.getMaximumConnectionCount());

connectionsBuffer.append(" (max)");

connectionsBuffer.append("\n");


ConnectionInfoIF[] connectionInfos = snapshot.getConnectionInfos();

connectionsBuffer.append("#");

connectionsBuffer.append("\t");

connectionsBuffer.append("born");

connectionsBuffer.append("\t");

connectionsBuffer.append("last start");

connectionsBuffer.append("\t");

connectionsBuffer.append("lap(ms)");

connectionsBuffer.append("\t");

connectionsBuffer.append("thread");

connectionsBuffer.append("\n");

for (int i = 0; i < connectionInfos.length; i++) {

ConnectionInfoIF connectionInfo = connectionInfos[i];

connectionsBuffer.append(connectionInfo.getId());

connectionsBuffer.append("\t");

connectionsBuffer.append(TIME_FORMAT.format(connectionInfo.getBirthDate()));

connectionsBuffer.append("\t");

connectionsBuffer.append(connectionInfo.getTimeLastStartActive() > 0 ? TIME_FORMAT.format(new Date(connectionInfo.getTimeLastStartActive())) : "-");

connectionsBuffer.append("\t");

String active = "&nbsp;";

if (connectionInfo.getTimeLastStopActive() > 0) {

active = String.valueOf((int) (connectionInfo.getTimeLastStopActive() - connectionInfo.getTimeLastStartActive()));

} else if (connectionInfo.getTimeLastStartActive() > 0) {

active = String.valueOf((int) (snapshot.getSnapshotDate().getTime() - connectionInfo.getTimeLastStartActive()));

}

connectionsBuffer.append(active);

connectionsBuffer.append("\t");

connectionsBuffer.append(connectionInfo.getRequester() != null ? connectionInfo.getRequester() : "-");

connectionsBuffer.append("\n");


String[] sqlCalls = connectionInfo.getSqlCalls();

for (int j = 0; sqlCalls != null && i < sqlCalls.length; i++) {

String sqlCall = sqlCalls[i];

connectionsBuffer.append("SQL=");

connectionsBuffer.append(sqlCall);

connectionsBuffer.append("\n");

}

connectionsBuffer.append("proxy=");

connectionsBuffer.append(connectionInfo.getProxyHashcode());

connectionsBuffer.append("\n");

connectionsBuffer.append("delegate=");

connectionsBuffer.append(connectionInfo.getDelegateHashcode());

connectionsBuffer.append("\n");

connectionsBuffer.append("url=");

connectionsBuffer.append(connectionInfo.getDelegateUrl());

connectionsBuffer.append("\n");

}

} catch (ProxoolException e) {

e.printStackTrace();

}

log.info(connectionsBuffer.toString());

}

}




-------------------------------------------------
上一篇:数据库连接池的选型:DBCP vs C3P0 下一篇:Mysql 安裝步驟

martin   2007-04-26

不错啊。谢谢。



  
Are you Bot? How you know that?ofcz no.