<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*,javax.management.*,org.apache.tomcat.util.modeler.Registry" %><%! public static String padRight(String s, int n) { return String.format("%1$-" + n + "s", s); } public static String padLeft(String s, int n) { return String.format("%1$" + n + "s", s); } public static String formatTime(Object obj, boolean seconds) { long time = -1L; if (obj instanceof Long) { time = ((Long) obj).longValue(); } else if (obj instanceof Integer) { time = ((Integer) obj).intValue(); } if (seconds) { return ((((float) time ) / 1000) + " s"); } else { return (time + "ms"); } } public static String formatSize(Object obj, boolean mb) { long bytes = -1L; if (obj instanceof Long) { bytes = ((Long) obj).longValue(); } else if (obj instanceof Integer) { bytes = ((Integer) obj).intValue(); } if (mb) { StringBuilder buff = new StringBuilder(); if (bytes < 0) { buff.append('-'); bytes = -bytes; } long mbytes = bytes / (1024 * 1024); long rest = ((bytes - (mbytes * (1024 * 1024))) * 100) / (1024 * 1024); buff.append(mbytes).append('.'); if (rest < 10) { buff.append('0'); } buff.append(rest).append("MiB"); return buff.toString(); } else { return ((bytes / 1024) + "KiB"); } } %> 윈디하나의 솔라나라: TOMCAT - CONNECTION STATUS
수행시간 IP              URL                    호스트명        받음 보냄 커넥터명
-------- --------------- ---------------------- --------------- ---- ---- ---------------
<%
// 아래 소스 참고
// org.apache.catalina.manager.StatusManagerServlet
// org.apache.catalina.manager.StatusTransformer
	MBeanServer mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
	Vector requestProcessors = new Vector();
	String onStr = "*:type=RequestProcessor,*";
	ObjectName objectName = new ObjectName(onStr);
	Set set = mBeanServer.queryMBeans(objectName, null);
	Iterator iterator = set.iterator();
	while (iterator.hasNext()) {
		ObjectInstance oi = iterator.next();
		requestProcessors.addElement(oi.getObjectName());
	}

	Enumeration enumeration = requestProcessors.elements();
	while (enumeration.hasMoreElements()) {
		objectName = (ObjectName) enumeration.nextElement();
		String workerName = objectName.getKeyProperty("worker");
		int stageValue =  (Integer) mBeanServer.getAttribute(objectName, "stage");
		String URL = (String) mBeanServer.getAttribute(objectName, "currentUri");
		if (stageValue >= 1 && stageValue <= 7 && URL != null) {
			String queryString = (String) mBeanServer.getAttribute(objectName, "currentQueryString");
			out.write(padLeft(formatTime(mBeanServer.getAttribute(objectName, "requestProcessingTime"), false), 8));
			out.write(" " + padLeft(((String) mBeanServer.getAttribute(objectName, "remoteAddr")).trim(), 15));
			out.write(" " + padLeft(URL + (queryString != null ? "?" + queryString : ""), 22));
			out.write(" " + padRight(mBeanServer.getAttribute(objectName, "virtualHost").toString(), 10));
			out.write(" " + formatSize(mBeanServer.getAttribute(objectName, "requestBytesReceived").toString(), false));
			out.write(" " + formatSize(mBeanServer.getAttribute(objectName, "requestBytesSent").toString(), false));
			out.write(" " + workerName);
			out.write("\n");
		}
	}
%>