赞
踩
ClassLoadingInfoCollector
- private Map<String, Number> doClassLoadingCollect() {
- ClassLoadingMXBean classLoadingMXBean = ManagementFactory.getClassLoadingMXBean();
- Map<String, Number> map = new LinkedHashMap<String, Number>();
-
- map.put("jvm.classloading.loaded.count", classLoadingMXBean.getLoadedClassCount());
- map.put("jvm.classloading.totalloaded.count", classLoadingMXBean.getTotalLoadedClassCount());
- map.put("jvm.classloading.unloaded.count", classLoadingMXBean.getUnloadedClassCount());
-
- return map;
- }
JvmInfoCollector
- private Set<String> youngGcAlgorithm = new LinkedHashSet<String>() {
- private static final long serialVersionUID = -2953196532584721351L;
-
- {
- add("Copy");
- add("ParNew");
- add("PS Scavenge");
- add("G1 Young Generation");
- }
- };
-
- private Set<String> oldGcAlgorithm = new LinkedHashSet<String>() {
- private static final long serialVersionUID = -8267829533109860610L;
-
- {
- add("MarkSweepCompact");
- add("PS MarkSweep");
- add("ConcurrentMarkSweep");
- add("G1 Old Generation");
- }
- };
-
-
- private Map<String, Number> doGcCollect() {
- long gcCount = 0;
- long gcTime = 0;
- long oldGCount = 0;
- long oldGcTime = 0;
- long youngGcCount = 0;
- long youngGcTime = 0;
- Map<String, Number> map = new LinkedHashMap<String, Number>();
-
- for (final GarbageCollectorMXBean garbageCollector : ManagementFactory.getGarbageCollectorMXBeans()) {
- gcTime += garbageCollector.getCollectionTime();
- gcCount += garbageCollector.getCollectionCount();
- String gcAlgorithm = garbageCollector.getName();
-
- if (youngGcAlgorithm.contains(gcAlgorithm)) {
- youngGcTime += garbageCollector.getCollectionTime();
- youngGcCount += garbageCollector.getCollectionCount();
- } else if (oldGcAlgorithm.contains(gcAlgorithm)) {
- oldGcTime += garbageCollector.getCollectionTime();
- oldGCount += garbageCollector.getCollectionCount();
- } else {
- Cat.logEvent("UnknownGcAlgorithm", gcAlgorithm);
- }
- }
-
- map.put("jvm.gc.count", gcCount - lastGcCount);
- map.put("jvm.gc.time", gcTime - lastGcTime);
- final long value = oldGCount - lastFullGcCount;
-
- if (value > 0) {
- hasOldGc = true;
- }
-
- map.put("jvm.fullgc.count", value);
- map.put("jvm.fullgc.time", oldGcTime - lastFullGcTime);
- map.put("jvm.younggc.count", youngGcCount - lastYoungGcCount);
- map.put("jvm.younggc.time", youngGcTime - lastYoungGcTime);
-
- if (youngGcCount > lastYoungGcCount) {
- map.put("jvm.younggc.meantime", (youngGcTime - lastYoungGcTime) / (youngGcCount - lastYoungGcCount));
- } else {
- map.put("jvm.younggc.meantime", 0);
- }
-
- lastGcCount = gcCount;
- lastGcTime = gcTime;
- lastYoungGcCount = youngGcCount;
- lastYoungGcTime = youngGcTime;
- lastFullGcCount = oldGCount;
- lastFullGcTime = oldGcTime;
-
- return map;
- }
-
- private Map<String, Number> doMemoryCollect() {
- MemoryInformation memInfo = new MemoryInformation();
- Map<String, Number> map = new LinkedHashMap<String, Number>();
-
- map.put("jvm.memory.used", memInfo.getUsedMemory());
- map.put("jvm.memory.used.percent", memInfo.getUsedMemoryPercentage());
- map.put("jvm.memory.nonheap.used", memInfo.getUsedNonHeapMemory());
- map.put("jvm.memory.nonheap.used.percent", memInfo.getUsedNonHeapPercentage());
- map.put("jvm.memory.oldgen.used", memInfo.getUsedOldGen());
- map.put("jvm.memory.oldgen.used.percent", memInfo.getUsedOldGenPercentage());
-
- if (hasOldGc) {
- map.put("jvm.memory.oldgen.used.percent.after.fullgc", memInfo.getUsedOldGenPercentage());
- hasOldGc = false;
- } else {
- map.put("jvm.memory.oldgen.used.percent.after.fullgc", 0);
- }
-
- map.put("jvm.memory.eden.used", memInfo.getUsedEdenSpace());
- map.put("jvm.memory.eden.used.percent", memInfo.getUsedEdenSpacePercentage());
- map.put("jvm.memory.survivor.used", memInfo.getUsedSurvivorSpace());
- map.put("jvm.memory.survivor.used.percent", memInfo.getUsedSurvivorSpacePercentage());
- map.put("jvm.memory.perm.used", memInfo.getUsedPermGen());
- map.put("jvm.memory.perm.used.percent", memInfo.getUsedPermGenPercentage());
- map.put("jvm.memory.metaspace.used", memInfo.getUsedMetaSpace());
- map.put("jvm.memory.metaspace.used.percent", memInfo.getUsedMetaSpacePercentage());
- map.put("jvm.memory.codecache.used", memInfo.getUsedCodeCache());
- map.put("jvm.memory.codecache.used.percent", memInfo.getUsedCodeCachePercentage());
- map.put("jvm.nio.directbuffer.used", memInfo.getUsedDirectBufferSize());
- map.put("jvm.nio.mapped.used", memInfo.getUsedMappedSize());
-
- return map;
- }

ThreadInfoCollector
- private Map<String, Number> doThreadCollect() {
- final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
- Map<String, Number> map = new LinkedHashMap<String, Number>();
- map.put("jvm.thread.count", threadBean.getThreadCount());
- map.put("jvm.thread.daemon.count", threadBean.getDaemonThreadCount());
- map.put("jvm.thread.totalstarted.count", threadBean.getTotalStartedThreadCount());
- ThreadInfo[] threadInfos = threadBean.getThreadInfo(threadBean.getAllThreadIds());
-
- int newThreadCount = 0;
- int runnableThreadCount = 0;
- int blockedThreadCount = 0;
- int waitThreadCount = 0;
- int timeWaitThreadCount = 0;
- int terminatedThreadCount = 0;
-
- if (threadInfos != null) {
- for (ThreadInfo threadInfo : threadInfos) {
- if (threadInfo != null) {
- switch (threadInfo.getThreadState()) {
- case NEW:
- newThreadCount++;
- break;
- case RUNNABLE:
- runnableThreadCount++;
- break;
- case BLOCKED:
- blockedThreadCount++;
- break;
- case WAITING:
- waitThreadCount++;
- break;
- case TIMED_WAITING:
- timeWaitThreadCount++;
- break;
- case TERMINATED:
- terminatedThreadCount++;
- break;
- default:
- break;
- }
- } else {
- /**
- * If a thread of a given ID is not alive or does not exist, the corresponding element in the returned array will,
- * contain null,because is mut exist ,so the thread is terminated
- */
- terminatedThreadCount++;
- }
- }
- }
-
- map.put("jvm.thread.new.count", newThreadCount);
- map.put("jvm.thread.runnable.count", runnableThreadCount);
- map.put("jvm.thread.blocked.count", blockedThreadCount);
- map.put("jvm.thread.waiting.count", waitThreadCount);
- map.put("jvm.thread.time_waiting.count", timeWaitThreadCount);
- map.put("jvm.thread.terminated.count", terminatedThreadCount);
-
- long[] ids = threadBean.findDeadlockedThreads();
-
- map.put("jvm.thread.deadlock.count", ids == null ? 0 : ids.length);
-
- if (threadInfos != null) {
- int tomcatThreadsCount = countThreadsByPrefix(threadInfos, "http-", "catalina-exec-");
- int jettyThreadsCount = countThreadsBySubstring(threadInfos, "@qtp");
-
- map.put("jvm.thread.http.count", tomcatThreadsCount + jettyThreadsCount);
- map.put("jvm.thread.cat.count", countThreadsByPrefix(threadInfos, "Cat-", "cat-"));
- map.put("jvm.thread.pigeon.count",
- countThreadsByPrefix(threadInfos, "Pigeon-", "DPSF-", "Client-ResponseProcessor"));
- }
-
- return map;
- }

ProcessorInfoCollector
- private Map<String, Number> doProcessCollect() {
- Map<String, Number> map = new LinkedHashMap<String, Number>();
- OperatingSystemMXBean operatingSystem = ManagementFactory.getOperatingSystemMXBean();
-
- map.put("system.load.average", operatingSystem.getSystemLoadAverage());
-
- if (operatingSystem instanceof com.sun.management.OperatingSystemMXBean) {
- com.sun.management.OperatingSystemMXBean osBean = (com.sun.management.OperatingSystemMXBean) operatingSystem;
-
- map.put("cpu.system.load.percent", osBean.getSystemCpuLoad() * 100);
- map.put("cpu.jvm.load.percent", osBean.getProcessCpuLoad() * 100);
- map.put("system.process.used.phyical.memory",
- osBean.getTotalPhysicalMemorySize() - osBean.getFreePhysicalMemorySize());
- map.put("system.process.used.swap.size", osBean.getTotalSwapSpaceSize() - osBean.getFreeSwapSpaceSize());
- }
-
- if (isSunOsMBean(operatingSystem)) {
- if (operatingSystem instanceof com.sun.management.UnixOperatingSystemMXBean) {
- final com.sun.management.UnixOperatingSystemMXBean unixOsBean = (com.sun.management.UnixOperatingSystemMXBean) operatingSystem;
- try {
- map.put("jvm.process.filedescriptors", unixOsBean.getOpenFileDescriptorCount());
- } catch (final Error e) {
- // pour issue 16 (using jsvc on ubuntu or debian)
- }
- }
- final com.sun.management.OperatingSystemMXBean osBean = (com.sun.management.OperatingSystemMXBean) operatingSystem;
- long processCpuTime = osBean.getProcessCpuTime() / 1000000;
- map.put("jvm.process.cputime", processCpuTime - lastProcessCputime);
-
- lastProcessCputime = processCpuTime;
- }
-
- return map;
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。