We have a application monitoring page which includes, amongst other
application-specific data, Java memory usage statistics. (To share with the
group I've included the example code below!)
 
I want to include connection statistics for each connector, in particular
the information that the manager app shows (number of connection, threads in
use, number kept alive, etc) and also (if it's stored somewhere) the peak
number of connections since Tomcat was started. Does anyone have some
example JSP code they could share?
 
Thanks
 
Richard
___________________________
Richard Mundell
The Roberts Group
Market Data Expertise that FITS.
+1 212 499 2680 x20 (office)
www.trgrp.com
 
--------------------------------------------------------
 
EXAMPLE CODE FOR MEMORY MONITORING:
 
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.lang.management.*" %>
<%
// MEMORY USAGE
Iterator iter2 = ManagementFactory.getMemoryPoolMXBeans().iterator();
float max;
float used;
 
float heapmax=0;
float heapused=0;
float heappeak=0;
String paddedName="";
String memoryString="";
String heapMemory="";
int problem=0;
 
while (iter2.hasNext()) {
 MemoryPoolMXBean item2 = (MemoryPoolMXBean) iter2.next();
 
 if (item2.getType().toString().toUpperCase().equals("NON-HEAP MEMORY")) {
  paddedName=item2.getName().toString();
  while (paddedName.length()<18) {
   paddedName+=" ";
  }
     memoryString+=paddedName + "\t";
     max = new Long(item2.getUsage().getMax()).floatValue();
     used = new Long(item2.getUsage().getUsed()).floatValue();
     memoryString+=new Float(max/1048576).shortValue() + "MB max, ";
     memoryString+=new Float((max-used)/1048576).shortValue() + "MB";
     memoryString+="(" + new Float(((max-used)/max)*100).shortValue()+"%)
free, ";
     memoryString+=new
Float(item2.getPeakUsage().getUsed()/1048576).shortValue() +"MB peak
usage\n";
     
  if (new Float(((max-used)/max)*100).shortValue()<20) {
   problem=1;
   memoryString+="<FONT COLOR=RED><B>WARNING: " + item2.getName()+ " IS
<20%</FONT>\n";
  }
 } else {
  heapmax += item2.getUsage().getMax();
  heapused += item2.getUsage().getUsed();
  heappeak += item2.getPeakUsage().getUsed();
 }   
}
 
String heapmemory;
heapmemory="Main memory (heap)\t";
heapmemory+=new Float(heapmax/1048576).shortValue() + "MB max, ";
heapmemory+=new Float((heapmax-heapused)/1048576).shortValue() + "MB";
heapmemory+="(" + new
Float(((heapmax-heapused)/heapmax)*100).shortValue()+"%) free, ";
heapmemory+=new Float(heappeak/1048576).shortValue() +"MB peak usage\n";
if (new Float(((heapmax-heapused)/heapmax)*100).shortValue()<20) {
 problem=1;
 heapmemory+="<FONT COLOR=RED><B>WARNING: Main Memory (heap) IS
<20%</FONT>\n";
}
 
memoryString=heapmemory+memoryString;
 
out.print("<PRE>" + memoryString);
%>

Reply via email to