in shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/InfoAction.java [75:218]
public Object execute() throws Exception {
int maxNameLen;
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
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 {
Class< ? > sunOS = Class.forName("com.sun.management.OperatingSystemMXBean");
printValue("Process CPU time", maxNameLen, printDuration(getValueAsLong(sunOS, "getProcessCpuTime") / 1000000));
printValue("Process CPU load", maxNameLen, fmtDec.format(getValueAsDouble(sunOS, "getProcessCpuLoad")));
printValue("System CPU load", maxNameLen, fmtDec.format(getValueAsDouble(sunOS, "getSystemCpuLoad")));
} catch (Throwable t) {
}
try {
Class<?> unixOS = Class.forName("com.sun.management.UnixOperatingSystemMXBean");
printValue("Open file descriptors", maxNameLen, printLong(getValueAsLong(unixOS, "getOpenFileDescriptorCount")));
printValue("Max file descriptors", maxNameLen, printLong(getValueAsLong(unixOS, "getMaxFileDescriptorCount")));
} 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);
}
if (showMemoryPools) {
List<MemoryPoolMXBean> memoryPools = ManagementFactory.getMemoryPoolMXBeans();
System.out.println("Memory Pools");
printValue("Total Memory Pools", maxNameLen, printLong(memoryPools.size()));
String spaces4 = " ";
for (MemoryPoolMXBean pool : memoryPools)
{
String name = pool.getName();
MemoryType type = pool.getType();
printValue(spaces4 + "Pool (" + type + ")", maxNameLen, name);
// PeakUsage/CurrentUsage
MemoryUsage peakUsage = pool.getPeakUsage();
MemoryUsage usage = pool.getUsage();
if (usage != null && peakUsage != null) {
long init = peakUsage.getInit();
long used = peakUsage.getUsed();
long committed = peakUsage.getCommitted();
long max = peakUsage.getMax();
System.out.println(spaces4 + spaces4 + "Peak Usage");
printValue(spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init));
printValue(spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used));
printValue(spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed));
printValue(spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max));
init = usage.getInit();
used = usage.getUsed();
committed = usage.getCommitted();
max = usage.getMax();
System.out.println(spaces4 + spaces4 + "Current Usage");
printValue(spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init));
printValue(spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used));
printValue(spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed));
printValue(spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max));
}
}
}
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;
}