Search in sources :

Example 1 with InfoProvider

use of org.apache.karaf.shell.commands.info.InfoProvider 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;
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) HashMap(java.util.HashMap) InfoProvider(org.apache.karaf.shell.commands.info.InfoProvider) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) ArrayList(java.util.ArrayList) RuntimeMXBean(java.lang.management.RuntimeMXBean) Properties(java.util.Properties) MemoryMXBean(java.lang.management.MemoryMXBean) ClassLoadingMXBean(java.lang.management.ClassLoadingMXBean) HashMap(java.util.HashMap) Map(java.util.Map) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 2 with InfoProvider

use of org.apache.karaf.shell.commands.info.InfoProvider in project karaf by apache.

the class InfoBundleTrackerCustomizer method addingBundle.

/**
     * {@inheritDoc}
     */
@SuppressWarnings("unchecked")
public ServiceRegistration<InfoProvider> addingBundle(Bundle bundle, BundleEvent event) {
    Dictionary headers = bundle.getHeaders();
    String headerEntry = (String) headers.get("Karaf-Info");
    InfoProvider provider = createInfo(headerEntry);
    if (provider == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Ignore incorrect info {} provided by bundle {}", headerEntry, bundle.getSymbolicName());
        }
        return null;
    }
    return bundle.getBundleContext().registerService(InfoProvider.class, provider, null);
}
Also used : Dictionary(java.util.Dictionary) InfoProvider(org.apache.karaf.shell.commands.info.InfoProvider)

Aggregations

InfoProvider (org.apache.karaf.shell.commands.info.InfoProvider)2 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)1 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)1 MemoryMXBean (java.lang.management.MemoryMXBean)1 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)1 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 ArrayList (java.util.ArrayList)1 Dictionary (java.util.Dictionary)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1