当前位置:   article > 正文

cat 中几个统计jvm 和system 的类_jvm.memory:jvm.memory.used.percent

jvm.memory:jvm.memory.used.percent
ClassLoadingInfoCollector
  1. private Map<String, Number> doClassLoadingCollect() {
  2. ClassLoadingMXBean classLoadingMXBean = ManagementFactory.getClassLoadingMXBean();
  3. Map<String, Number> map = new LinkedHashMap<String, Number>();
  4. map.put("jvm.classloading.loaded.count", classLoadingMXBean.getLoadedClassCount());
  5. map.put("jvm.classloading.totalloaded.count", classLoadingMXBean.getTotalLoadedClassCount());
  6. map.put("jvm.classloading.unloaded.count", classLoadingMXBean.getUnloadedClassCount());
  7. return map;
  8. }
JvmInfoCollector
  1. private Set<String> youngGcAlgorithm = new LinkedHashSet<String>() {
  2. private static final long serialVersionUID = -2953196532584721351L;
  3. {
  4. add("Copy");
  5. add("ParNew");
  6. add("PS Scavenge");
  7. add("G1 Young Generation");
  8. }
  9. };
  10. private Set<String> oldGcAlgorithm = new LinkedHashSet<String>() {
  11. private static final long serialVersionUID = -8267829533109860610L;
  12. {
  13. add("MarkSweepCompact");
  14. add("PS MarkSweep");
  15. add("ConcurrentMarkSweep");
  16. add("G1 Old Generation");
  17. }
  18. };
  19. private Map<String, Number> doGcCollect() {
  20. long gcCount = 0;
  21. long gcTime = 0;
  22. long oldGCount = 0;
  23. long oldGcTime = 0;
  24. long youngGcCount = 0;
  25. long youngGcTime = 0;
  26. Map<String, Number> map = new LinkedHashMap<String, Number>();
  27. for (final GarbageCollectorMXBean garbageCollector : ManagementFactory.getGarbageCollectorMXBeans()) {
  28. gcTime += garbageCollector.getCollectionTime();
  29. gcCount += garbageCollector.getCollectionCount();
  30. String gcAlgorithm = garbageCollector.getName();
  31. if (youngGcAlgorithm.contains(gcAlgorithm)) {
  32. youngGcTime += garbageCollector.getCollectionTime();
  33. youngGcCount += garbageCollector.getCollectionCount();
  34. } else if (oldGcAlgorithm.contains(gcAlgorithm)) {
  35. oldGcTime += garbageCollector.getCollectionTime();
  36. oldGCount += garbageCollector.getCollectionCount();
  37. } else {
  38. Cat.logEvent("UnknownGcAlgorithm", gcAlgorithm);
  39. }
  40. }
  41. map.put("jvm.gc.count", gcCount - lastGcCount);
  42. map.put("jvm.gc.time", gcTime - lastGcTime);
  43. final long value = oldGCount - lastFullGcCount;
  44. if (value > 0) {
  45. hasOldGc = true;
  46. }
  47. map.put("jvm.fullgc.count", value);
  48. map.put("jvm.fullgc.time", oldGcTime - lastFullGcTime);
  49. map.put("jvm.younggc.count", youngGcCount - lastYoungGcCount);
  50. map.put("jvm.younggc.time", youngGcTime - lastYoungGcTime);
  51. if (youngGcCount > lastYoungGcCount) {
  52. map.put("jvm.younggc.meantime", (youngGcTime - lastYoungGcTime) / (youngGcCount - lastYoungGcCount));
  53. } else {
  54. map.put("jvm.younggc.meantime", 0);
  55. }
  56. lastGcCount = gcCount;
  57. lastGcTime = gcTime;
  58. lastYoungGcCount = youngGcCount;
  59. lastYoungGcTime = youngGcTime;
  60. lastFullGcCount = oldGCount;
  61. lastFullGcTime = oldGcTime;
  62. return map;
  63. }
  64. private Map<String, Number> doMemoryCollect() {
  65. MemoryInformation memInfo = new MemoryInformation();
  66. Map<String, Number> map = new LinkedHashMap<String, Number>();
  67. map.put("jvm.memory.used", memInfo.getUsedMemory());
  68. map.put("jvm.memory.used.percent", memInfo.getUsedMemoryPercentage());
  69. map.put("jvm.memory.nonheap.used", memInfo.getUsedNonHeapMemory());
  70. map.put("jvm.memory.nonheap.used.percent", memInfo.getUsedNonHeapPercentage());
  71. map.put("jvm.memory.oldgen.used", memInfo.getUsedOldGen());
  72. map.put("jvm.memory.oldgen.used.percent", memInfo.getUsedOldGenPercentage());
  73. if (hasOldGc) {
  74. map.put("jvm.memory.oldgen.used.percent.after.fullgc", memInfo.getUsedOldGenPercentage());
  75. hasOldGc = false;
  76. } else {
  77. map.put("jvm.memory.oldgen.used.percent.after.fullgc", 0);
  78. }
  79. map.put("jvm.memory.eden.used", memInfo.getUsedEdenSpace());
  80. map.put("jvm.memory.eden.used.percent", memInfo.getUsedEdenSpacePercentage());
  81. map.put("jvm.memory.survivor.used", memInfo.getUsedSurvivorSpace());
  82. map.put("jvm.memory.survivor.used.percent", memInfo.getUsedSurvivorSpacePercentage());
  83. map.put("jvm.memory.perm.used", memInfo.getUsedPermGen());
  84. map.put("jvm.memory.perm.used.percent", memInfo.getUsedPermGenPercentage());
  85. map.put("jvm.memory.metaspace.used", memInfo.getUsedMetaSpace());
  86. map.put("jvm.memory.metaspace.used.percent", memInfo.getUsedMetaSpacePercentage());
  87. map.put("jvm.memory.codecache.used", memInfo.getUsedCodeCache());
  88. map.put("jvm.memory.codecache.used.percent", memInfo.getUsedCodeCachePercentage());
  89. map.put("jvm.nio.directbuffer.used", memInfo.getUsedDirectBufferSize());
  90. map.put("jvm.nio.mapped.used", memInfo.getUsedMappedSize());
  91. return map;
  92. }
ThreadInfoCollector
  1. private Map<String, Number> doThreadCollect() {
  2. final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
  3. Map<String, Number> map = new LinkedHashMap<String, Number>();
  4. map.put("jvm.thread.count", threadBean.getThreadCount());
  5. map.put("jvm.thread.daemon.count", threadBean.getDaemonThreadCount());
  6. map.put("jvm.thread.totalstarted.count", threadBean.getTotalStartedThreadCount());
  7. ThreadInfo[] threadInfos = threadBean.getThreadInfo(threadBean.getAllThreadIds());
  8. int newThreadCount = 0;
  9. int runnableThreadCount = 0;
  10. int blockedThreadCount = 0;
  11. int waitThreadCount = 0;
  12. int timeWaitThreadCount = 0;
  13. int terminatedThreadCount = 0;
  14. if (threadInfos != null) {
  15. for (ThreadInfo threadInfo : threadInfos) {
  16. if (threadInfo != null) {
  17. switch (threadInfo.getThreadState()) {
  18. case NEW:
  19. newThreadCount++;
  20. break;
  21. case RUNNABLE:
  22. runnableThreadCount++;
  23. break;
  24. case BLOCKED:
  25. blockedThreadCount++;
  26. break;
  27. case WAITING:
  28. waitThreadCount++;
  29. break;
  30. case TIMED_WAITING:
  31. timeWaitThreadCount++;
  32. break;
  33. case TERMINATED:
  34. terminatedThreadCount++;
  35. break;
  36. default:
  37. break;
  38. }
  39. } else {
  40. /**
  41. * If a thread of a given ID is not alive or does not exist, the corresponding element in the returned array will,
  42. * contain null,because is mut exist ,so the thread is terminated
  43. */
  44. terminatedThreadCount++;
  45. }
  46. }
  47. }
  48. map.put("jvm.thread.new.count", newThreadCount);
  49. map.put("jvm.thread.runnable.count", runnableThreadCount);
  50. map.put("jvm.thread.blocked.count", blockedThreadCount);
  51. map.put("jvm.thread.waiting.count", waitThreadCount);
  52. map.put("jvm.thread.time_waiting.count", timeWaitThreadCount);
  53. map.put("jvm.thread.terminated.count", terminatedThreadCount);
  54. long[] ids = threadBean.findDeadlockedThreads();
  55. map.put("jvm.thread.deadlock.count", ids == null ? 0 : ids.length);
  56. if (threadInfos != null) {
  57. int tomcatThreadsCount = countThreadsByPrefix(threadInfos, "http-", "catalina-exec-");
  58. int jettyThreadsCount = countThreadsBySubstring(threadInfos, "@qtp");
  59. map.put("jvm.thread.http.count", tomcatThreadsCount + jettyThreadsCount);
  60. map.put("jvm.thread.cat.count", countThreadsByPrefix(threadInfos, "Cat-", "cat-"));
  61. map.put("jvm.thread.pigeon.count",
  62. countThreadsByPrefix(threadInfos, "Pigeon-", "DPSF-", "Client-ResponseProcessor"));
  63. }
  64. return map;
  65. }
ProcessorInfoCollector
  1. private Map<String, Number> doProcessCollect() {
  2. Map<String, Number> map = new LinkedHashMap<String, Number>();
  3. OperatingSystemMXBean operatingSystem = ManagementFactory.getOperatingSystemMXBean();
  4. map.put("system.load.average", operatingSystem.getSystemLoadAverage());
  5. if (operatingSystem instanceof com.sun.management.OperatingSystemMXBean) {
  6. com.sun.management.OperatingSystemMXBean osBean = (com.sun.management.OperatingSystemMXBean) operatingSystem;
  7. map.put("cpu.system.load.percent", osBean.getSystemCpuLoad() * 100);
  8. map.put("cpu.jvm.load.percent", osBean.getProcessCpuLoad() * 100);
  9. map.put("system.process.used.phyical.memory",
  10. osBean.getTotalPhysicalMemorySize() - osBean.getFreePhysicalMemorySize());
  11. map.put("system.process.used.swap.size", osBean.getTotalSwapSpaceSize() - osBean.getFreeSwapSpaceSize());
  12. }
  13. if (isSunOsMBean(operatingSystem)) {
  14. if (operatingSystem instanceof com.sun.management.UnixOperatingSystemMXBean) {
  15. final com.sun.management.UnixOperatingSystemMXBean unixOsBean = (com.sun.management.UnixOperatingSystemMXBean) operatingSystem;
  16. try {
  17. map.put("jvm.process.filedescriptors", unixOsBean.getOpenFileDescriptorCount());
  18. } catch (final Error e) {
  19. // pour issue 16 (using jsvc on ubuntu or debian)
  20. }
  21. }
  22. final com.sun.management.OperatingSystemMXBean osBean = (com.sun.management.OperatingSystemMXBean) operatingSystem;
  23. long processCpuTime = osBean.getProcessCpuTime() / 1000000;
  24. map.put("jvm.process.cputime", processCpuTime - lastProcessCputime);
  25. lastProcessCputime = processCpuTime;
  26. }
  27. return map;
  28. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/58905
推荐阅读
相关标签
  

闽ICP备14008679号