Commit e7489513 e748951369dffc4b6e6c51a4bbf435b952907e3a by Christian Gerdes

Stabil version av liljm.jar påbörjar JmxMonREST getData

1 parent d873e5f5
......@@ -12,5 +12,6 @@
<classpathentry kind="lib" path="lib/javax.servlet.jar"/>
<classpathentry kind="lib" path="lib/javax.servlet.jsp.jar"/>
<classpathentry kind="lib" path="lib/javax.servlet.jsp.jstl.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/LILJM Library"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
......
No preview for this file type
/OraMonRESTgetMetrics.class
/JmxMonRESTgetData.class
/OraMonRESTgetData.class
/OraMonRESTgetMetrics.class
......
import java.io.IOException;
import javax.management.remote.JMXServiceURL;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import se.lil.jm.JmxMon;
import se.lil.jm.Registry;
/**
* Servlet implementation class JmxMonRESTgetData
*/
@WebServlet(description = "Calls getData on an existing JmxMon object or creates and calls it", urlPatterns = { "/JmxMonREST/getData" })
public class JmxMonRESTgetData extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public JmxMonRESTgetData() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json");
try {
StringBuffer sb = new StringBuffer();
int age = 0;
if(request.getParameterMap().containsKey("age")) {
try {
age = Integer.parseInt(request.getParameter("age"));
} catch (Exception e) {
response.setStatus(400);
response.getWriter().println("{\"error\":true,\"msg\":\"The specified age parameter is not a valid integer number\"}");
return;
}
}
if(request.getParameterMap().containsKey("connectionString")) {
// We have a connection string, find the monitor or create it and call getData() on the monitor
// Check that we have a valid connection string
try {
JMXServiceURL url = new JMXServiceURL(request.getParameter("connectionString"));
} catch (Exception e) {
// Error, we need a correct connection string
response.setStatus(400);
response.getWriter().println("{\"error\":true,\"msg\":\"connectionString is not a correct JMX Service URL\"}");
return;
}
// Try to find the monitor in our list
JmxMon monitor = Registry.findOrCreate(request.getParameter("connectionString"));
// Call getData()
boolean didUpdate = monitor.getData(age);
String name = monitor.getServerName();
if(didUpdate) {
sb.append("{\"error\":false,\"msg\":\"Sucessfully collected data on instance '" + name + "'\"");
sb.append(",\"ms\":"+monitor.getLastRTms()+"}");
} else {
response.setStatus(HttpServletResponse.SC_ACCEPTED);
sb.append("{\"error\":false");
sb.append(",\"msg\":\"Data does not need to be updated on instance '" + name + "' either because another thread did concurrently update the monitor and we just waited for it to complete, or because the age (if) specified was higher than the monitors data age.\"");
sb.append(",\"age\":"+monitor.getAgeTs()+"}");
}
} else {
// No input, just return the list of monitors
sb.append("{\"count\":" + Registry.getList().size() + "}");
}
response.getWriter().println(sb.toString());
} catch (Throwable e) {
response.setStatus(500);
response.getWriter().println("{\"error\":true,\"msg\":\""+e.toString().replace("\n"," ").replace("\"","\\\"").trim()+"\"}");
e.printStackTrace();
}
}
}
javaw.exe -Dcom.sun.management.jmxremote.ssl=false -cp "wls-10.3.6.0.12.1/wljmxclient.jar;jconsole.1.8.0_91.jar" sun.tools.jconsole.JConsole "service:jmx:rmi:///jndi/iiop://u30009:26732/weblogic.management.mbeanservers.runtime"
\ No newline at end of file
javaw.exe -Dcom.sun.management.jmxremote.ssl=false -cp "wls-10.3.6.0.161018.2/wljmxclient.jar;jconsole.1.8.0_91.jar" sun.tools.jconsole.JConsole "service:jmx:rmi:///jndi/iiop://u30009:26732/weblogic.management.mbeanservers.runtime"
\ No newline at end of file
......
......@@ -374,60 +374,8 @@ public class JmxMon {
}
}
public double getHeapUsedPercent() {
LongDelta ldu = getLongDelta("java.lang:type=Memory:HeapMemoryUsage:used");
LongDelta ldm = getLongDelta("java.lang:type=Memory:HeapMemoryUsage:max");
if(ldu != null && ldm != null) {
return ((double)ldu.getCurrentValue()/(double)ldm.getCurrentValue()) * 100D;
} else {
return 0;
}
}
public double getHeapAllocationRateMBps() {
LongDelta ldu = getLongDelta("java.lang:type=Memory:HeapMemoryUsage:used");
if(ldu != null) {
if(ldu.getPerSecondValue() > 0) {
return ldu.getPerSecondValue()/(1024D*1024D);
} else {
// negative delta, means we had a major GC in the delta, get the last heap size before GC and add it to the last (previous) value
Long beforeGC = null;
if(isGCType(JmxMon.CMS)) {
LongDelta ld1 = getLongDelta("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep:LastGcInfo:memoryUsageBeforeGc:CMS Old Gen:used");
LongDelta ld2 = getLongDelta("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep:LastGcInfo:memoryUsageBeforeGc:Par Eden Space:used");
LongDelta ld3 = getLongDelta("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep:LastGcInfo:memoryUsageBeforeGc:Par Survivor Space:used");
if(ld1 != null && ld2 != null && ld3 != null)
beforeGC = ld1.getCurrentValue() + ld2.getCurrentValue() + ld3.getCurrentValue();
} else
if(isGCType(JmxMon.PS)) {
LongDelta ld1 = getLongDelta("java.lang:type=GarbageCollector,name=PS MarkSweep:LastGcInfo:memoryUsageBeforeGc:PS Old Gen:used");
LongDelta ld2 = getLongDelta("java.lang:type=GarbageCollector,name=PS MarkSweep:LastGcInfo:memoryUsageBeforeGc:PS Eden Space:used");
LongDelta ld3 = getLongDelta("java.lang:type=GarbageCollector,name=PS MarkSweep:LastGcInfo:memoryUsageBeforeGc:PS Survivor Space:used");
if(ld1 != null && ld2 != null && ld3 != null)
beforeGC = ld1.getCurrentValue() + ld2.getCurrentValue() + ld3.getCurrentValue();
}
if(beforeGC == null) return 0;
if(ldu.lastValue == null) return 0;
ldu.lastValue = beforeGC + ldu.lastValue;
System.out.println("Adjusted heap size with " + beforeGC + " bytes");
return ldu.getPerSecondValue()/(1024D*1024D);
}
} else {
return 0;
}
}
public double getPSOldGenUsedMB() {
LongDelta ld = getLongDelta("java.lang:type=MemoryPool,name=PS Old Gen:Usage:used");
if(ld != null) {
return (double)ld.getCurrentValue() / (1024D*1024D);
} else {
return 0;
}
}
public double getCMSOldGenUsedMB() {
LongDelta ld = getLongDelta("java.lang:type=MemoryPool,name=CMS Old Gen:Usage:used");
public double getHeapCommittedMB() {
LongDelta ld = getLongDelta("java.lang:type=Memory:HeapMemoryUsage:committed");
if(ld != null) {
return (double)ld.getCurrentValue() / (1024D*1024D);
} else {
......@@ -435,9 +383,9 @@ public class JmxMon {
}
}
public double getPSOldGenUsedPercent() {
LongDelta ldu = getLongDelta("java.lang:type=MemoryPool,name=PS Old Gen:Usage:used");
LongDelta ldm = getLongDelta("java.lang:type=MemoryPool,name=PS Old Gen:Usage:max");
public double getHeapUsedPercent() {
LongDelta ldu = getLongDelta("java.lang:type=Memory:HeapMemoryUsage:used");
LongDelta ldm = getLongDelta("java.lang:type=Memory:HeapMemoryUsage:max");
if(ldu != null && ldm != null) {
return ((double)ldu.getCurrentValue()/(double)ldm.getCurrentValue()) * 100D;
} else {
......@@ -445,18 +393,30 @@ public class JmxMon {
}
}
public double getCMSOldGenUsedPercent() {
LongDelta ldu = getLongDelta("java.lang:type=MemoryPool,name=CMS Old Gen:Usage:used");
LongDelta ldm = getLongDelta("java.lang:type=MemoryPool,name=CMS Old Gen:Usage:max");
if(ldu != null && ldm != null) {
return ((double)ldu.getCurrentValue()/(double)ldm.getCurrentValue()) * 100D;
public double getGCOverhead() {
LongDelta ld1 = null;
LongDelta ld2 = null;
if(isGCType(JmxMon.PS)) {
ld1 = getLongDelta("java.lang:type=GarbageCollector,name=PS MarkSweep:CollectionTime");
ld2 = getLongDelta("java.lang:type=GarbageCollector,name=PS Scavenge:CollectionTime");
}
if(isGCType(JmxMon.CMS)) {
ld1 = getLongDelta("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep:CollectionTime");
ld2 = getLongDelta("java.lang:type=GarbageCollector,name=ParNew:CollectionTime");
}
if(ld1 != null && ld2 != null) {
return (ld1.getPerSecondValue() + ld2.getPerSecondValue())/10D;
} else {
return 0;
}
}
public double getPSMarkSweepOldGenAfterGCMB() {
LongDelta ld = getLongDelta("java.lang:type=GarbageCollector,name=PS MarkSweep:LastGcInfo:memoryUsageAfterGc:PS Old Gen:used");
public double getOldGenUsedMB() {
LongDelta ld = null;
if(isGCType(JmxMon.PS))
ld = getLongDelta("java.lang:type=MemoryPool,name=PS Old Gen:Usage:used");
if(isGCType(JmxMon.CMS))
ld = getLongDelta("java.lang:type=MemoryPool,name=CMS Old Gen:Usage:used");
if(ld != null) {
return (double)ld.getCurrentValue() / (1024D*1024D);
} else {
......@@ -464,17 +424,31 @@ public class JmxMon {
}
}
public double getCMSMarkSweepOldGenAfterGCMB() {
LongDelta ld = getLongDelta("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep:LastGcInfo:memoryUsageAfterGc:CMS Old Gen:used");
if(ld != null) {
return (double)ld.getCurrentValue() / (1024D*1024D);
public double getOldGenUsedPercent() {
LongDelta ldu = null;
LongDelta ldm = null;
if(isGCType(JmxMon.PS)) {
ldu = getLongDelta("java.lang:type=MemoryPool,name=PS Old Gen:Usage:used");
ldm = getLongDelta("java.lang:type=MemoryPool,name=PS Old Gen:Usage:max");
}
if(isGCType(JmxMon.CMS)) {
ldu = getLongDelta("java.lang:type=MemoryPool,name=CMS Old Gen:Usage:used");
ldm = getLongDelta("java.lang:type=MemoryPool,name=CMS Old Gen:Usage:max");
}
if(ldu != null && ldm != null) {
return ((double)ldu.getCurrentValue()/(double)ldm.getCurrentValue()) * 100D;
} else {
return 0;
}
}
public double getPSMarkSweepPermGenAfterGCMB() {
LongDelta ld = getLongDelta("java.lang:type=GarbageCollector,name=PS MarkSweep:LastGcInfo:memoryUsageAfterGc:PS Perm Gen:used");
public double getOldGenAfterGCMB() {
LongDelta ld = null;
if(isGCType(JmxMon.PS))
ld = getLongDelta("java.lang:type=GarbageCollector,name=PS MarkSweep:LastGcInfo:memoryUsageAfterGc:PS Old Gen:used");
if(isGCType(JmxMon.CMS))
ld = getLongDelta("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep:LastGcInfo:memoryUsageAfterGc:CMS Old Gen:used");
if(ld != null) {
return (double)ld.getCurrentValue() / (1024D*1024D);
} else {
......@@ -482,8 +456,12 @@ public class JmxMon {
}
}
public double getCMSMarkSweepPermGenAfterGCMB() {
LongDelta ld = getLongDelta("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep:LastGcInfo:memoryUsageAfterGc:CMS Perm Gen:used");
public double getPermGenAfterGCMB() {
LongDelta ld = null;
if(isGCType(JmxMon.PS))
ld = getLongDelta("java.lang:type=GarbageCollector,name=PS MarkSweep:LastGcInfo:memoryUsageAfterGc:PS Perm Gen:used");
if(isGCType(JmxMon.CMS))
ld = getLongDelta("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep:LastGcInfo:memoryUsageAfterGc:CMS Perm Gen:used");
if(ld != null) {
return (double)ld.getCurrentValue() / (1024D*1024D);
} else {
......
......@@ -21,10 +21,11 @@ public class TestRunner {
//JmxMon mon1 = new JmxMon("service:jmx:iiop:///jndi/iiop://u30457:29722/weblogic.management.mbeanservers.runtime"); // 10.3.6.0.161018.2
//JmxMon mon1 = new JmxMon("service:jmx:rmi:///jndi/iiop://u30128:23032/weblogic.management.mbeanservers.runtime"); // 10.3.6.0.161018.2
//JmxMon mon2 = new JmxMon("service:jmx:rmi:///jndi/iiop://u30009:26732/weblogic.management.mbeanservers.runtime"); // 10.3.6.0.12.1
JmxMon mon1 = new JmxMon("service:jmx:rmi:///jndi/iiop://u30009:26732/weblogic.management.mbeanservers.runtime"); // 10.3.6.0.12.1
//JmxMon mon1 = new JmxMon("service:jmx:rmi:///jndi/iiop://u30009:2673/weblogic.management.mbeanservers.runtime"); // Fel port
//JmxMon mon1 = new JmxMon("service:jmx:rmi:///jndi/iiop://u02878.ht.kap.rsv.se:17040/weblogic.management.mbeanservers.runtime"); // 10.3.6.0.161018.2 PS
//JmxMon mon1 = new JmxMon("service:jmx:rmi:///jndi/iiop://u01891.ef.kap.rsv.se:17020/weblogic.management.mbeanservers.runtime"); // 10.3.6.0.161018.2 CMS
JmxMon mon1 = new JmxMon("service:jmx:rmi:///jndi/iiop://u30450:34502/weblogic.management.mbeanservers.runtime"); // CMS
//JmxMon mon1 = new JmxMon("service:jmx:rmi:///jndi/iiop://u30450:34502/weblogic.management.mbeanservers.runtime"); // CMS
mon1.open();
//mon2.open();
jmxList.add(mon1);
......@@ -44,25 +45,19 @@ public class TestRunner {
mon.getData();
time = System.currentTimeMillis() - ts1;
System.out.println(mon.getServerName() + " called in " + time + "ms");
System.out.println(" Process CPU %: " + mon.getCPUPercent());
System.out.println(" Number of processors #: " + mon.getNumberOfCPUs());
System.out.println(" Process CPU Used %: " + mon.getCPUPercent());
System.out.println(" Process Threads #: " + mon.getThreads());
System.out.println(" Process Loaded Classes #: " + mon.getLoadedClassCount());
System.out.println(" Process File Descriptors %: " + mon.getSystemFileDescriptorsPercentUsed());
System.out.println(" Process Heap Used %: " + mon.getHeapUsedPercent());
System.out.println(" Process Heap Committed MB: " + mon.getHeapCommittedMB());
System.out.println(" Process Heap Used MB: " + mon.getHeapUsedMB());
System.out.println(" Allocation Rate MB/s: " + mon.getHeapAllocationRateMBps());
if(mon.isGCType(JmxMon.PS)) {
System.out.println(" PS OldGen Used %: " + mon.getPSOldGenUsedPercent());
System.out.println(" PS OldGen Used MB: " + mon.getPSOldGenUsedMB());
System.out.println(" PS OldGen After Major GC MB: " + mon.getPSMarkSweepOldGenAfterGCMB());
System.out.println(" PS PermGen After Major GC MB: " + mon.getPSMarkSweepPermGenAfterGCMB());
}
if(mon.isGCType(JmxMon.CMS)) {
System.out.println(" CMS OldGen Used %: " + mon.getCMSOldGenUsedPercent());
System.out.println(" CMS OldGen Used MB: " + mon.getCMSOldGenUsedMB());
System.out.println(" CMS OldGen After Major GC MB: " + mon.getCMSMarkSweepOldGenAfterGCMB());
System.out.println("CMS PermGen After Major GC MB: " + mon.getCMSMarkSweepPermGenAfterGCMB());
}
System.out.println(" Process Heap Used %: " + mon.getHeapUsedPercent());
System.out.println(" OldGen Used MB: " + mon.getOldGenUsedMB());
System.out.println(" OldGen Used %: " + mon.getOldGenUsedPercent());
System.out.println(" OldGen After Last GC MB: " + mon.getOldGenAfterGCMB());
System.out.println(" PermGen After Last GC MB: " + mon.getPermGenAfterGCMB());
System.out.println(" GC Time (Overhead) %: " + mon.getGCOverhead());
System.out.println(" System Load (per cpu): " + mon.getAverageLoadPerCpu());
System.out.println(" System Load (total): " + mon.getAverageLoad());
System.out.println(" System Memory %: " + mon.getSystemMemoryPercentUsed());
......