Commit e7489513 e748951369dffc4b6e6c51a4bbf435b952907e3a by Christian Gerdes

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

1 parent d873e5f5
...@@ -12,5 +12,6 @@ ...@@ -12,5 +12,6 @@
12 <classpathentry kind="lib" path="lib/javax.servlet.jar"/> 12 <classpathentry kind="lib" path="lib/javax.servlet.jar"/>
13 <classpathentry kind="lib" path="lib/javax.servlet.jsp.jar"/> 13 <classpathentry kind="lib" path="lib/javax.servlet.jsp.jar"/>
14 <classpathentry kind="lib" path="lib/javax.servlet.jsp.jstl.jar"/> 14 <classpathentry kind="lib" path="lib/javax.servlet.jsp.jstl.jar"/>
15 <classpathentry combineaccessrules="false" kind="src" path="/LILJM Library"/>
15 <classpathentry kind="output" path="build/classes"/> 16 <classpathentry kind="output" path="build/classes"/>
16 </classpath> 17 </classpath>
......
No preview for this file type
1 /OraMonRESTgetMetrics.class 1 /JmxMonRESTgetData.class
2 /OraMonRESTgetData.class 2 /OraMonRESTgetData.class
3 /OraMonRESTgetMetrics.class
......
1
2
3 import java.io.IOException;
4
5 import javax.management.remote.JMXServiceURL;
6 import javax.servlet.ServletException;
7 import javax.servlet.annotation.WebServlet;
8 import javax.servlet.http.HttpServlet;
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11
12 import se.lil.jm.JmxMon;
13 import se.lil.jm.Registry;
14
15 /**
16 * Servlet implementation class JmxMonRESTgetData
17 */
18 @WebServlet(description = "Calls getData on an existing JmxMon object or creates and calls it", urlPatterns = { "/JmxMonREST/getData" })
19 public class JmxMonRESTgetData extends HttpServlet {
20 private static final long serialVersionUID = 1L;
21
22 /**
23 * @see HttpServlet#HttpServlet()
24 */
25 public JmxMonRESTgetData() {
26 super();
27 // TODO Auto-generated constructor stub
28 }
29
30 /**
31 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
32 */
33 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
34 response.setContentType("application/json");
35 try {
36 StringBuffer sb = new StringBuffer();
37 int age = 0;
38 if(request.getParameterMap().containsKey("age")) {
39 try {
40 age = Integer.parseInt(request.getParameter("age"));
41 } catch (Exception e) {
42 response.setStatus(400);
43 response.getWriter().println("{\"error\":true,\"msg\":\"The specified age parameter is not a valid integer number\"}");
44 return;
45 }
46 }
47
48 if(request.getParameterMap().containsKey("connectionString")) {
49 // We have a connection string, find the monitor or create it and call getData() on the monitor
50
51 // Check that we have a valid connection string
52 try {
53 JMXServiceURL url = new JMXServiceURL(request.getParameter("connectionString"));
54 } catch (Exception e) {
55 // Error, we need a correct connection string
56 response.setStatus(400);
57 response.getWriter().println("{\"error\":true,\"msg\":\"connectionString is not a correct JMX Service URL\"}");
58 return;
59 }
60
61 // Try to find the monitor in our list
62 JmxMon monitor = Registry.findOrCreate(request.getParameter("connectionString"));
63
64 // Call getData()
65 boolean didUpdate = monitor.getData(age);
66 String name = monitor.getServerName();
67 if(didUpdate) {
68 sb.append("{\"error\":false,\"msg\":\"Sucessfully collected data on instance '" + name + "'\"");
69 sb.append(",\"ms\":"+monitor.getLastRTms()+"}");
70 } else {
71 response.setStatus(HttpServletResponse.SC_ACCEPTED);
72 sb.append("{\"error\":false");
73 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.\"");
74 sb.append(",\"age\":"+monitor.getAgeTs()+"}");
75 }
76
77 } else {
78 // No input, just return the list of monitors
79 sb.append("{\"count\":" + Registry.getList().size() + "}");
80 }
81
82 response.getWriter().println(sb.toString());
83
84 } catch (Throwable e) {
85 response.setStatus(500);
86 response.getWriter().println("{\"error\":true,\"msg\":\""+e.toString().replace("\n"," ").replace("\"","\\\"").trim()+"\"}");
87 e.printStackTrace();
88 }
89 }
90 }
1 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 ...\ No newline at end of file
1 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 ...\ No newline at end of file
......
...@@ -374,60 +374,8 @@ public class JmxMon { ...@@ -374,60 +374,8 @@ public class JmxMon {
374 } 374 }
375 } 375 }
376 376
377 public double getHeapUsedPercent() { 377 public double getHeapCommittedMB() {
378 LongDelta ldu = getLongDelta("java.lang:type=Memory:HeapMemoryUsage:used"); 378 LongDelta ld = getLongDelta("java.lang:type=Memory:HeapMemoryUsage:committed");
379 LongDelta ldm = getLongDelta("java.lang:type=Memory:HeapMemoryUsage:max");
380 if(ldu != null && ldm != null) {
381 return ((double)ldu.getCurrentValue()/(double)ldm.getCurrentValue()) * 100D;
382 } else {
383 return 0;
384 }
385 }
386
387 public double getHeapAllocationRateMBps() {
388 LongDelta ldu = getLongDelta("java.lang:type=Memory:HeapMemoryUsage:used");
389 if(ldu != null) {
390 if(ldu.getPerSecondValue() > 0) {
391 return ldu.getPerSecondValue()/(1024D*1024D);
392 } else {
393 // 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
394 Long beforeGC = null;
395 if(isGCType(JmxMon.CMS)) {
396 LongDelta ld1 = getLongDelta("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep:LastGcInfo:memoryUsageBeforeGc:CMS Old Gen:used");
397 LongDelta ld2 = getLongDelta("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep:LastGcInfo:memoryUsageBeforeGc:Par Eden Space:used");
398 LongDelta ld3 = getLongDelta("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep:LastGcInfo:memoryUsageBeforeGc:Par Survivor Space:used");
399 if(ld1 != null && ld2 != null && ld3 != null)
400 beforeGC = ld1.getCurrentValue() + ld2.getCurrentValue() + ld3.getCurrentValue();
401 } else
402 if(isGCType(JmxMon.PS)) {
403 LongDelta ld1 = getLongDelta("java.lang:type=GarbageCollector,name=PS MarkSweep:LastGcInfo:memoryUsageBeforeGc:PS Old Gen:used");
404 LongDelta ld2 = getLongDelta("java.lang:type=GarbageCollector,name=PS MarkSweep:LastGcInfo:memoryUsageBeforeGc:PS Eden Space:used");
405 LongDelta ld3 = getLongDelta("java.lang:type=GarbageCollector,name=PS MarkSweep:LastGcInfo:memoryUsageBeforeGc:PS Survivor Space:used");
406 if(ld1 != null && ld2 != null && ld3 != null)
407 beforeGC = ld1.getCurrentValue() + ld2.getCurrentValue() + ld3.getCurrentValue();
408 }
409 if(beforeGC == null) return 0;
410 if(ldu.lastValue == null) return 0;
411 ldu.lastValue = beforeGC + ldu.lastValue;
412 System.out.println("Adjusted heap size with " + beforeGC + " bytes");
413 return ldu.getPerSecondValue()/(1024D*1024D);
414 }
415 } else {
416 return 0;
417 }
418 }
419
420 public double getPSOldGenUsedMB() {
421 LongDelta ld = getLongDelta("java.lang:type=MemoryPool,name=PS Old Gen:Usage:used");
422 if(ld != null) {
423 return (double)ld.getCurrentValue() / (1024D*1024D);
424 } else {
425 return 0;
426 }
427 }
428
429 public double getCMSOldGenUsedMB() {
430 LongDelta ld = getLongDelta("java.lang:type=MemoryPool,name=CMS Old Gen:Usage:used");
431 if(ld != null) { 379 if(ld != null) {
432 return (double)ld.getCurrentValue() / (1024D*1024D); 380 return (double)ld.getCurrentValue() / (1024D*1024D);
433 } else { 381 } else {
...@@ -435,9 +383,9 @@ public class JmxMon { ...@@ -435,9 +383,9 @@ public class JmxMon {
435 } 383 }
436 } 384 }
437 385
438 public double getPSOldGenUsedPercent() { 386 public double getHeapUsedPercent() {
439 LongDelta ldu = getLongDelta("java.lang:type=MemoryPool,name=PS Old Gen:Usage:used"); 387 LongDelta ldu = getLongDelta("java.lang:type=Memory:HeapMemoryUsage:used");
440 LongDelta ldm = getLongDelta("java.lang:type=MemoryPool,name=PS Old Gen:Usage:max"); 388 LongDelta ldm = getLongDelta("java.lang:type=Memory:HeapMemoryUsage:max");
441 if(ldu != null && ldm != null) { 389 if(ldu != null && ldm != null) {
442 return ((double)ldu.getCurrentValue()/(double)ldm.getCurrentValue()) * 100D; 390 return ((double)ldu.getCurrentValue()/(double)ldm.getCurrentValue()) * 100D;
443 } else { 391 } else {
...@@ -445,18 +393,30 @@ public class JmxMon { ...@@ -445,18 +393,30 @@ public class JmxMon {
445 } 393 }
446 } 394 }
447 395
448 public double getCMSOldGenUsedPercent() { 396 public double getGCOverhead() {
449 LongDelta ldu = getLongDelta("java.lang:type=MemoryPool,name=CMS Old Gen:Usage:used"); 397 LongDelta ld1 = null;
450 LongDelta ldm = getLongDelta("java.lang:type=MemoryPool,name=CMS Old Gen:Usage:max"); 398 LongDelta ld2 = null;
451 if(ldu != null && ldm != null) { 399 if(isGCType(JmxMon.PS)) {
452 return ((double)ldu.getCurrentValue()/(double)ldm.getCurrentValue()) * 100D; 400 ld1 = getLongDelta("java.lang:type=GarbageCollector,name=PS MarkSweep:CollectionTime");
401 ld2 = getLongDelta("java.lang:type=GarbageCollector,name=PS Scavenge:CollectionTime");
402 }
403 if(isGCType(JmxMon.CMS)) {
404 ld1 = getLongDelta("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep:CollectionTime");
405 ld2 = getLongDelta("java.lang:type=GarbageCollector,name=ParNew:CollectionTime");
406 }
407 if(ld1 != null && ld2 != null) {
408 return (ld1.getPerSecondValue() + ld2.getPerSecondValue())/10D;
453 } else { 409 } else {
454 return 0; 410 return 0;
455 } 411 }
456 } 412 }
457 413
458 public double getPSMarkSweepOldGenAfterGCMB() { 414 public double getOldGenUsedMB() {
459 LongDelta ld = getLongDelta("java.lang:type=GarbageCollector,name=PS MarkSweep:LastGcInfo:memoryUsageAfterGc:PS Old Gen:used"); 415 LongDelta ld = null;
416 if(isGCType(JmxMon.PS))
417 ld = getLongDelta("java.lang:type=MemoryPool,name=PS Old Gen:Usage:used");
418 if(isGCType(JmxMon.CMS))
419 ld = getLongDelta("java.lang:type=MemoryPool,name=CMS Old Gen:Usage:used");
460 if(ld != null) { 420 if(ld != null) {
461 return (double)ld.getCurrentValue() / (1024D*1024D); 421 return (double)ld.getCurrentValue() / (1024D*1024D);
462 } else { 422 } else {
...@@ -464,17 +424,31 @@ public class JmxMon { ...@@ -464,17 +424,31 @@ public class JmxMon {
464 } 424 }
465 } 425 }
466 426
467 public double getCMSMarkSweepOldGenAfterGCMB() { 427 public double getOldGenUsedPercent() {
468 LongDelta ld = getLongDelta("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep:LastGcInfo:memoryUsageAfterGc:CMS Old Gen:used"); 428 LongDelta ldu = null;
469 if(ld != null) { 429 LongDelta ldm = null;
470 return (double)ld.getCurrentValue() / (1024D*1024D); 430
431 if(isGCType(JmxMon.PS)) {
432 ldu = getLongDelta("java.lang:type=MemoryPool,name=PS Old Gen:Usage:used");
433 ldm = getLongDelta("java.lang:type=MemoryPool,name=PS Old Gen:Usage:max");
434 }
435 if(isGCType(JmxMon.CMS)) {
436 ldu = getLongDelta("java.lang:type=MemoryPool,name=CMS Old Gen:Usage:used");
437 ldm = getLongDelta("java.lang:type=MemoryPool,name=CMS Old Gen:Usage:max");
438 }
439 if(ldu != null && ldm != null) {
440 return ((double)ldu.getCurrentValue()/(double)ldm.getCurrentValue()) * 100D;
471 } else { 441 } else {
472 return 0; 442 return 0;
473 } 443 }
474 } 444 }
475 445
476 public double getPSMarkSweepPermGenAfterGCMB() { 446 public double getOldGenAfterGCMB() {
477 LongDelta ld = getLongDelta("java.lang:type=GarbageCollector,name=PS MarkSweep:LastGcInfo:memoryUsageAfterGc:PS Perm Gen:used"); 447 LongDelta ld = null;
448 if(isGCType(JmxMon.PS))
449 ld = getLongDelta("java.lang:type=GarbageCollector,name=PS MarkSweep:LastGcInfo:memoryUsageAfterGc:PS Old Gen:used");
450 if(isGCType(JmxMon.CMS))
451 ld = getLongDelta("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep:LastGcInfo:memoryUsageAfterGc:CMS Old Gen:used");
478 if(ld != null) { 452 if(ld != null) {
479 return (double)ld.getCurrentValue() / (1024D*1024D); 453 return (double)ld.getCurrentValue() / (1024D*1024D);
480 } else { 454 } else {
...@@ -482,8 +456,12 @@ public class JmxMon { ...@@ -482,8 +456,12 @@ public class JmxMon {
482 } 456 }
483 } 457 }
484 458
485 public double getCMSMarkSweepPermGenAfterGCMB() { 459 public double getPermGenAfterGCMB() {
486 LongDelta ld = getLongDelta("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep:LastGcInfo:memoryUsageAfterGc:CMS Perm Gen:used"); 460 LongDelta ld = null;
461 if(isGCType(JmxMon.PS))
462 ld = getLongDelta("java.lang:type=GarbageCollector,name=PS MarkSweep:LastGcInfo:memoryUsageAfterGc:PS Perm Gen:used");
463 if(isGCType(JmxMon.CMS))
464 ld = getLongDelta("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep:LastGcInfo:memoryUsageAfterGc:CMS Perm Gen:used");
487 if(ld != null) { 465 if(ld != null) {
488 return (double)ld.getCurrentValue() / (1024D*1024D); 466 return (double)ld.getCurrentValue() / (1024D*1024D);
489 } else { 467 } else {
......
...@@ -21,10 +21,11 @@ public class TestRunner { ...@@ -21,10 +21,11 @@ public class TestRunner {
21 21
22 //JmxMon mon1 = new JmxMon("service:jmx:iiop:///jndi/iiop://u30457:29722/weblogic.management.mbeanservers.runtime"); // 10.3.6.0.161018.2 22 //JmxMon mon1 = new JmxMon("service:jmx:iiop:///jndi/iiop://u30457:29722/weblogic.management.mbeanservers.runtime"); // 10.3.6.0.161018.2
23 //JmxMon mon1 = new JmxMon("service:jmx:rmi:///jndi/iiop://u30128:23032/weblogic.management.mbeanservers.runtime"); // 10.3.6.0.161018.2 23 //JmxMon mon1 = new JmxMon("service:jmx:rmi:///jndi/iiop://u30128:23032/weblogic.management.mbeanservers.runtime"); // 10.3.6.0.161018.2
24 //JmxMon mon2 = new JmxMon("service:jmx:rmi:///jndi/iiop://u30009:26732/weblogic.management.mbeanservers.runtime"); // 10.3.6.0.12.1 24 JmxMon mon1 = new JmxMon("service:jmx:rmi:///jndi/iiop://u30009:26732/weblogic.management.mbeanservers.runtime"); // 10.3.6.0.12.1
25 //JmxMon mon1 = new JmxMon("service:jmx:rmi:///jndi/iiop://u30009:2673/weblogic.management.mbeanservers.runtime"); // Fel port
25 //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 26 //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
26 //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 27 //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
27 JmxMon mon1 = new JmxMon("service:jmx:rmi:///jndi/iiop://u30450:34502/weblogic.management.mbeanservers.runtime"); // CMS 28 //JmxMon mon1 = new JmxMon("service:jmx:rmi:///jndi/iiop://u30450:34502/weblogic.management.mbeanservers.runtime"); // CMS
28 mon1.open(); 29 mon1.open();
29 //mon2.open(); 30 //mon2.open();
30 jmxList.add(mon1); 31 jmxList.add(mon1);
...@@ -44,25 +45,19 @@ public class TestRunner { ...@@ -44,25 +45,19 @@ public class TestRunner {
44 mon.getData(); 45 mon.getData();
45 time = System.currentTimeMillis() - ts1; 46 time = System.currentTimeMillis() - ts1;
46 System.out.println(mon.getServerName() + " called in " + time + "ms"); 47 System.out.println(mon.getServerName() + " called in " + time + "ms");
47 System.out.println(" Process CPU %: " + mon.getCPUPercent()); 48 System.out.println(" Number of processors #: " + mon.getNumberOfCPUs());
49 System.out.println(" Process CPU Used %: " + mon.getCPUPercent());
48 System.out.println(" Process Threads #: " + mon.getThreads()); 50 System.out.println(" Process Threads #: " + mon.getThreads());
49 System.out.println(" Process Loaded Classes #: " + mon.getLoadedClassCount()); 51 System.out.println(" Process Loaded Classes #: " + mon.getLoadedClassCount());
50 System.out.println(" Process File Descriptors %: " + mon.getSystemFileDescriptorsPercentUsed()); 52 System.out.println(" Process File Descriptors %: " + mon.getSystemFileDescriptorsPercentUsed());
51 System.out.println(" Process Heap Used %: " + mon.getHeapUsedPercent()); 53 System.out.println(" Process Heap Committed MB: " + mon.getHeapCommittedMB());
52 System.out.println(" Process Heap Used MB: " + mon.getHeapUsedMB()); 54 System.out.println(" Process Heap Used MB: " + mon.getHeapUsedMB());
53 System.out.println(" Allocation Rate MB/s: " + mon.getHeapAllocationRateMBps()); 55 System.out.println(" Process Heap Used %: " + mon.getHeapUsedPercent());
54 if(mon.isGCType(JmxMon.PS)) { 56 System.out.println(" OldGen Used MB: " + mon.getOldGenUsedMB());
55 System.out.println(" PS OldGen Used %: " + mon.getPSOldGenUsedPercent()); 57 System.out.println(" OldGen Used %: " + mon.getOldGenUsedPercent());
56 System.out.println(" PS OldGen Used MB: " + mon.getPSOldGenUsedMB()); 58 System.out.println(" OldGen After Last GC MB: " + mon.getOldGenAfterGCMB());
57 System.out.println(" PS OldGen After Major GC MB: " + mon.getPSMarkSweepOldGenAfterGCMB()); 59 System.out.println(" PermGen After Last GC MB: " + mon.getPermGenAfterGCMB());
58 System.out.println(" PS PermGen After Major GC MB: " + mon.getPSMarkSweepPermGenAfterGCMB()); 60 System.out.println(" GC Time (Overhead) %: " + mon.getGCOverhead());
59 }
60 if(mon.isGCType(JmxMon.CMS)) {
61 System.out.println(" CMS OldGen Used %: " + mon.getCMSOldGenUsedPercent());
62 System.out.println(" CMS OldGen Used MB: " + mon.getCMSOldGenUsedMB());
63 System.out.println(" CMS OldGen After Major GC MB: " + mon.getCMSMarkSweepOldGenAfterGCMB());
64 System.out.println("CMS PermGen After Major GC MB: " + mon.getCMSMarkSweepPermGenAfterGCMB());
65 }
66 System.out.println(" System Load (per cpu): " + mon.getAverageLoadPerCpu()); 61 System.out.println(" System Load (per cpu): " + mon.getAverageLoadPerCpu());
67 System.out.println(" System Load (total): " + mon.getAverageLoad()); 62 System.out.println(" System Load (total): " + mon.getAverageLoad());
68 System.out.println(" System Memory %: " + mon.getSystemMemoryPercentUsed()); 63 System.out.println(" System Memory %: " + mon.getSystemMemoryPercentUsed());
......