use of java.lang.management.MemoryMXBean in project ignite by apache.
the class GridManagerMxBeanIllegalArgumentHandleTest method setUp.
/** {@inheritDoc} Changes field to always failing mock */
@Override
public void setUp() throws Exception {
super.setUp();
try {
final MemoryMXBean memoryMXBean = createAlwaysFailingMxBean();
memMxBeanField = createAccessibleMemField();
mxBeanToRestore = memMxBeanField.get(null);
memMxBeanField.set(null, memoryMXBean);
correctSetupOfTestPerformed = memMxBeanField.get(null) == memoryMXBean;
} catch (Exception e) {
e.printStackTrace();
}
}
use of java.lang.management.MemoryMXBean in project karaf by apache.
the class EnvironmentDumpProvider method dumpGCInformation.
private void dumpGCInformation(final PrintWriter outPW) {
final List<GarbageCollectorMXBean> mxBeans = ManagementFactory.getGarbageCollectorMXBeans();
if (null == mxBeans || mxBeans.isEmpty()) {
return;
}
final MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();
if (memoryMxBean != null) {
outPW.printf(INDENT_KEY_VALUE_FORMAT, "pending objects", formatLong(memoryMxBean.getObjectPendingFinalizationCount())).println();
}
final String gcFormat = "'%1$s' collections: %2$s\ttime: %3$s";
outPW.println();
for (final GarbageCollectorMXBean mxBean : mxBeans) {
if (null == mxBean) {
continue;
}
outPW.printf(KEY_VALUE_FORMAT, "Garbage Collectors", String.format(gcFormat, mxBean.getName(), formatLong(mxBean.getCollectionCount()), printDuration(mxBean.getCollectionTime()))).println();
}
}
use of java.lang.management.MemoryMXBean in project karaf by apache.
the class InfoAction method execute.
@Override
public Object execute() throws Exception {
int maxNameLen;
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
ThreadMXBean threads = ManagementFactory.getThreadMXBean();
MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
ClassLoadingMXBean cl = ManagementFactory.getClassLoadingMXBean();
//
// print Karaf informations
//
maxNameLen = 25;
System.out.println("Karaf");
printValue("Karaf version", maxNameLen, System.getProperty("karaf.version"));
printValue("Karaf home", maxNameLen, System.getProperty("karaf.home"));
printValue("Karaf base", maxNameLen, System.getProperty("karaf.base"));
String osgi = getOsgiFramework();
if (osgi != null) {
printValue("OSGi Framework", maxNameLen, osgi);
}
System.out.println();
System.out.println("JVM");
printValue("Java Virtual Machine", maxNameLen, runtime.getVmName() + " version " + runtime.getVmVersion());
printValue("Version", maxNameLen, System.getProperty("java.version"));
printValue("Vendor", maxNameLen, runtime.getVmVendor());
printValue("Pid", maxNameLen, getPid());
printValue("Uptime", maxNameLen, printDuration(runtime.getUptime()));
try {
printValue("Process CPU time", maxNameLen, printDuration(getSunOsValueAsLong(os, "getProcessCpuTime") / 1000000));
} catch (Throwable t) {
}
printValue("Total compile time", maxNameLen, printDuration(ManagementFactory.getCompilationMXBean().getTotalCompilationTime()));
System.out.println("Threads");
printValue("Live threads", maxNameLen, Integer.toString(threads.getThreadCount()));
printValue("Daemon threads", maxNameLen, Integer.toString(threads.getDaemonThreadCount()));
printValue("Peak", maxNameLen, Integer.toString(threads.getPeakThreadCount()));
printValue("Total started", maxNameLen, Long.toString(threads.getTotalStartedThreadCount()));
System.out.println("Memory");
printValue("Current heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getUsed()));
printValue("Maximum heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getMax()));
printValue("Committed heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getCommitted()));
printValue("Pending objects", maxNameLen, Integer.toString(mem.getObjectPendingFinalizationCount()));
for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
String val = "Name = '" + gc.getName() + "', Collections = " + gc.getCollectionCount() + ", Time = " + printDuration(gc.getCollectionTime());
printValue("Garbage collector", maxNameLen, val);
}
System.out.println("Classes");
printValue("Current classes loaded", maxNameLen, printLong(cl.getLoadedClassCount()));
printValue("Total classes loaded", maxNameLen, printLong(cl.getTotalLoadedClassCount()));
printValue("Total classes unloaded", maxNameLen, printLong(cl.getUnloadedClassCount()));
System.out.println("Operating system");
printValue("Name", maxNameLen, os.getName() + " version " + os.getVersion());
printValue("Architecture", maxNameLen, os.getArch());
printValue("Processors", maxNameLen, Integer.toString(os.getAvailableProcessors()));
try {
printValue("Total physical memory", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getTotalPhysicalMemorySize")));
printValue("Free physical memory", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getFreePhysicalMemorySize")));
printValue("Committed virtual memory", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getCommittedVirtualMemorySize")));
printValue("Total swap space", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getTotalSwapSpaceSize")));
printValue("Free swap space", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getFreeSwapSpaceSize")));
} catch (Throwable t) {
}
//Display Information from external information providers.
Map<String, Map<Object, Object>> properties = new HashMap<>();
if (infoProviders != null) {
// dump all properties to Map, KARAF-425
for (InfoProvider provider : infoProviders) {
if (!properties.containsKey(provider.getName())) {
properties.put(provider.getName(), new Properties());
}
properties.get(provider.getName()).putAll(provider.getProperties());
}
List<String> sections = new ArrayList<>(properties.keySet());
Collections.sort(sections);
for (String section : sections) {
List<Object> keys = new ArrayList<>(properties.get(section).keySet());
if (keys.size() > 0) {
System.out.println(section);
keys.sort(Comparator.comparing(String::valueOf));
for (Object key : keys) {
printValue(String.valueOf(key), maxNameLen, String.valueOf(properties.get(section).get(key)));
}
}
}
}
return null;
}
use of java.lang.management.MemoryMXBean in project Gargoyle by callakrsos.
the class CPUUsageTest method showMemory.
/*
* 메모리 사용량
*/
public void showMemory() {
MemoryMXBean membean = ManagementFactory.getMemoryMXBean();
MemoryUsage heap = membean.getHeapMemoryUsage();
System.out.println("Heap Memory: " + heap.toString());
MemoryUsage nonheap = membean.getNonHeapMemoryUsage();
System.out.println("NonHeap Memory: " + nonheap.toString());
}
use of java.lang.management.MemoryMXBean in project storm by apache.
the class SystemBolt method prepare.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void prepare(final Map topoConf, TopologyContext context, OutputCollector collector) {
if (_prepareWasCalled && !"local".equals(topoConf.get(Config.STORM_CLUSTER_MODE))) {
throw new RuntimeException("A single worker should have 1 SystemBolt instance.");
}
_prepareWasCalled = true;
int bucketSize = Utils.getInt(topoConf.get(Config.TOPOLOGY_BUILTIN_METRICS_BUCKET_SIZE_SECS));
final RuntimeMXBean jvmRT = ManagementFactory.getRuntimeMXBean();
context.registerMetric("uptimeSecs", new IMetric() {
@Override
public Object getValueAndReset() {
return jvmRT.getUptime() / 1000.0;
}
}, bucketSize);
context.registerMetric("startTimeSecs", new IMetric() {
@Override
public Object getValueAndReset() {
return jvmRT.getStartTime() / 1000.0;
}
}, bucketSize);
context.registerMetric("newWorkerEvent", new IMetric() {
boolean doEvent = true;
@Override
public Object getValueAndReset() {
if (doEvent) {
doEvent = false;
return 1;
} else
return 0;
}
}, bucketSize);
final MemoryMXBean jvmMemRT = ManagementFactory.getMemoryMXBean();
context.registerMetric("memory/heap", new MemoryUsageMetric(jvmMemRT::getHeapMemoryUsage), bucketSize);
context.registerMetric("memory/nonHeap", new MemoryUsageMetric(jvmMemRT::getNonHeapMemoryUsage), bucketSize);
for (GarbageCollectorMXBean b : ManagementFactory.getGarbageCollectorMXBeans()) {
context.registerMetric("GC/" + b.getName().replaceAll("\\W", ""), new GarbageCollectorMetric(b), bucketSize);
}
registerMetrics(context, (Map<String, String>) topoConf.get(Config.WORKER_METRICS), bucketSize, topoConf);
registerMetrics(context, (Map<String, String>) topoConf.get(Config.TOPOLOGY_WORKER_METRICS), bucketSize, topoConf);
}
Aggregations