Skip to content

Commit

Permalink
Remplacer threads.total par threads.count et threads.busy
Browse files Browse the repository at this point in the history
  • Loading branch information
vinriviere committed Jun 21, 2017
1 parent 2e0339d commit eb848b4
Showing 1 changed file with 109 additions and 48 deletions.
157 changes: 109 additions & 48 deletions src/java/fr/univparis1/tomcatmonitor/ReadServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ private static class Result {
private long memoryTotal = 0;
private long memoryFree = 0;
private int threadsMax = 0;
private int threadsTotal = 0;
private int threadsCount = 0;
private int threadsBusy = 0;
private int threadsService = 0;
private int threadsKeepalive = 0;
private int threadsOther = 0;
private int threadsReady = 0;
private int threadsHttpMax = 0;
private int threadsHttpTotal = 0;
private int threadsHttpCount = 0;
private int threadsHttpBusy = 0;
private int threadsHttpService = 0;
private int threadsHttpKeepalive = 0;
private int threadsHttpOther = 0;
private int threadsHttpReady = 0;
private int requestsTotal = 0;
private int requestsError = 0;
Expand Down Expand Up @@ -113,12 +113,20 @@ public void setThreadsMax(int threadsMax) {
this.threadsMax = threadsMax;
}

public int getThreadsTotal() {
return threadsTotal;
public int getThreadsCount() {
return threadsCount;
}

public void addThreadsTotal() {
threadsTotal++;
public void setThreadsCount(int threadsCount) {
this.threadsCount = threadsCount;
}

public int getThreadsBusy() {
return threadsBusy;
}

public void setThreadsBusy(int threadsBusy) {
this.threadsBusy = threadsBusy;
}

public int getThreadsService() {
Expand All @@ -137,14 +145,6 @@ public void addThreadsKeepalive() {
threadsKeepalive++;
}

public int getThreadsOther() {
return threadsOther;
}

public void addThreadsOther() {
threadsOther++;
}

public int getThreadsReady() {
return threadsReady;
}
Expand All @@ -153,6 +153,10 @@ public void addThreadsReady() {
threadsReady++;
}

public int getThreadsOther() {
return getThreadsBusy() - getThreadsService() - getThreadsKeepalive();
}

public int getThreadsHttpMax() {
return threadsHttpMax;
}
Expand All @@ -161,12 +165,20 @@ public void setThreadsHttpMax(int threadsHttpMax) {
this.threadsHttpMax = threadsHttpMax;
}

public int getThreadsHttpTotal() {
return threadsHttpTotal;
public int getThreadsHttpCount() {
return threadsHttpCount;
}

public void setThreadsHttpCount(int threadsHttpCount) {
this.threadsHttpCount = threadsHttpCount;
}

public void addThreadsHttpTotal() {
threadsHttpTotal++;
public int getThreadsHttpBusy() {
return threadsHttpBusy;
}

public void setThreadsHttpBusy(int threadsHttpBusy) {
this.threadsHttpBusy = threadsHttpBusy;
}

public int getThreadsHttpService() {
Expand All @@ -185,14 +197,6 @@ public void addThreadsHttpKeepalive() {
threadsHttpKeepalive++;
}

public int getThreadsHttpOther() {
return threadsHttpOther;
}

public void addThreadsHttpOther() {
threadsHttpOther++;
}

public int getThreadsHttpReady() {
return threadsHttpReady;
}
Expand All @@ -201,6 +205,10 @@ public void addThreadsHttpReady() {
threadsHttpReady++;
}

public int getThreadsHttpOther() {
return getThreadsHttpBusy() - getThreadsHttpService() - getThreadsHttpKeepalive();
}

public int getRequestsTotal() {
return requestsTotal;
}
Expand Down Expand Up @@ -388,8 +396,11 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
getConnectorState(result);
out.println("threads.max=" + result.getThreadsMax());

getThreadPoolState(result);
out.println("threads.count=" + result.getThreadsCount());
out.println("threads.busy=" + result.getThreadsBusy());

getThreadsState(result);
out.println("threads.total=" + result.getThreadsTotal());
out.println("threads.service=" + result.getThreadsService());
out.println("threads.keepalive=" + result.getThreadsKeepalive());
out.println("threads.other=" + result.getThreadsOther());
Expand All @@ -398,8 +409,11 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
getConnectorStateHttp(result);
out.println("threads.http.max=" + result.getThreadsHttpMax());

getThreadPoolStateHttp(result);
out.println("threads.http.count=" + result.getThreadsHttpCount());
out.println("threads.http.busy=" + result.getThreadsHttpBusy());

getThreadsStateHttp(result);
out.println("threads.http.total=" + result.getThreadsHttpTotal());
out.println("threads.http.service=" + result.getThreadsHttpService());
out.println("threads.http.keepalive=" + result.getThreadsHttpKeepalive());
out.println("threads.http.other=" + result.getThreadsHttpOther());
Expand Down Expand Up @@ -458,9 +472,13 @@ else if (var.equals("threads.max")) {
getConnectorState(result);
out.println(result.getThreadsMax());
}
else if (var.equals("threads.total")) {
getThreadsState(result);
out.println(result.getThreadsTotal());
else if (var.equals("threads.count")) {
getThreadPoolState(result);
out.println(result.getThreadsCount());
}
else if (var.equals("threads.busy")) {
getThreadPoolState(result);
out.println(result.getThreadsBusy());
}
else if (var.equals("threads.service")) {
getThreadsState(result);
Expand All @@ -471,6 +489,7 @@ else if (var.equals("threads.keepalive")) {
out.println(result.getThreadsKeepalive());
}
else if (var.equals("threads.other")) {
getThreadPoolState(result);
getThreadsState(result);
out.println(result.getThreadsOther());
}
Expand All @@ -482,9 +501,13 @@ else if (var.equals("threads.http.max")) {
getConnectorStateHttp(result);
out.println(result.getThreadsHttpMax());
}
else if (var.equals("threads.http.total")) {
getThreadsStateHttp(result);
out.println(result.getThreadsHttpTotal());
else if (var.equals("threads.http.count")) {
getThreadPoolStateHttp(result);
out.println(result.getThreadsHttpCount());
}
else if (var.equals("threads.http.busy")) {
getThreadPoolStateHttp(result);
out.println(result.getThreadsHttpBusy());
}
else if (var.equals("threads.http.service")) {
getThreadsStateHttp(result);
Expand All @@ -495,6 +518,7 @@ else if (var.equals("threads.http.keepalive")) {
out.println(result.getThreadsHttpKeepalive());
}
else if (var.equals("threads.http.other")) {
getThreadPoolStateHttp(result);
getThreadsStateHttp(result);
out.println(result.getThreadsHttpOther());
}
Expand Down Expand Up @@ -678,8 +702,6 @@ private void getThreadsState(Result result) {
ObjectInstance oi = (ObjectInstance) iterator.next();
ObjectName rpName = oi.getObjectName();

result.addThreadsTotal();

// Voir conversion stage/état dans org.apache.catalina.manager.StatusTransformer.writeProcessorState()
Integer stageValue = (Integer)mBeanServer.getAttribute(rpName, "stage");
int stage = stageValue.intValue();
Expand All @@ -699,10 +721,6 @@ private void getThreadsState(Result result) {
case (7/*org.apache.coyote.Constants.STAGE_ENDED*/):
result.addThreadsReady();
break;

default:
result.addThreadsOther();
break;
}
}
} catch (JMException e) {
Expand All @@ -720,8 +738,6 @@ private void getThreadsStateHttp(Result result) {
ObjectInstance oi = (ObjectInstance) iterator.next();
ObjectName rpName = oi.getObjectName();

result.addThreadsHttpTotal();

// Voir conversion stage/état dans org.apache.catalina.manager.StatusTransformer.writeProcessorState()
Integer stageValue = (Integer)mBeanServer.getAttribute(rpName, "stage");
int stage = stageValue.intValue();
Expand All @@ -741,10 +757,6 @@ private void getThreadsStateHttp(Result result) {
case (7/*org.apache.coyote.Constants.STAGE_ENDED*/):
result.addThreadsHttpReady();
break;

default:
result.addThreadsHttpOther();
break;
}
}
} catch (JMException e) {
Expand Down Expand Up @@ -801,6 +813,55 @@ private void getGlobalRequestProcessorStateHttp(Result result) {
}
}

private void getThreadPoolState(Result result) {
MBeanServer mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
try {
String onStr = "Catalina:type=ThreadPool,name=\"ajp-*\""; // Tomcat 7
ObjectName objectName = new ObjectName(onStr);
Set set = mBeanServer.queryMBeans(objectName, null);
if (set.isEmpty()) {
onStr = "Catalina:type=ThreadPool,name=jk-*"; // Tomcat 6
objectName = new ObjectName(onStr);
set = mBeanServer.queryMBeans(objectName, null);
}
for (Iterator iterator = set.iterator(); iterator.hasNext(); ) {
ObjectInstance oi = (ObjectInstance) iterator.next();
ObjectName rpName = oi.getObjectName();

result.setThreadsCount(((Integer)mBeanServer.getAttribute(rpName, "currentThreadCount")).intValue());
result.setThreadsBusy(((Integer)mBeanServer.getAttribute(rpName, "currentThreadsBusy")).intValue());

// Normalement, il n'y a qu'un seul ThreadPool par type de connecteur
if (iterator.hasNext())
throw new RuntimeException("Plusieurs ThreadPool: " + onStr);
}
} catch (JMException e) {
throw new RuntimeException(e);
}
}

private void getThreadPoolStateHttp(Result result) {
MBeanServer mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
try {
String onStr = "Catalina:type=ThreadPool,name=\"http-*\"";
ObjectName objectName = new ObjectName(onStr);
Set set = mBeanServer.queryMBeans(objectName, null);
for (Iterator iterator = set.iterator(); iterator.hasNext(); ) {
ObjectInstance oi = (ObjectInstance) iterator.next();
ObjectName rpName = oi.getObjectName();

result.setThreadsHttpCount(((Integer)mBeanServer.getAttribute(rpName, "currentThreadCount")).intValue());
result.setThreadsHttpBusy(((Integer)mBeanServer.getAttribute(rpName, "currentThreadsBusy")).intValue());

// Normalement, il n'y a qu'un seul ThreadPool par type de connecteur
if (iterator.hasNext())
throw new RuntimeException("Plusieurs ThreadPool: " + onStr);
}
} catch (JMException e) {
throw new RuntimeException(e);
}
}

private void getC3p0State(Result result, String contextPath) {
if (contextPath == null)
throw new IllegalArgumentException("Missing argument: context");
Expand Down

0 comments on commit eb848b4

Please sign in to comment.