public void execute(MicroContext context, Map configuration) throws ControllerException {
Map<String, Object> systemInfo = new HashMap<String, Object>();
Map<String, Object> osMap = new HashMap<String, Object>();
MBeanServerConnection mbeanServer = ManagementFactory.getPlatformMBeanServer();
OperatingSystemMXBean sunOperatingSystemMXBean = null;
try {
sunOperatingSystemMXBean = ManagementFactory.newPlatformMXBeanProxy(
mbeanServer, ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class);
} catch (IOException e) {
throw new ControllerException(e.getMessage());
}
Runtime rt = Runtime.getRuntime();
long totalMemory = rt.totalMemory() / MEGA_BYTE;
long freeMemory = rt.freeMemory() / MEGA_BYTE;
long usedMemory = totalMemory - freeMemory;
final long p100 = (int) Math.round(((double) freeMemory / (double) totalMemory) * 100);
Map<String, Long> memInfo = new HashMap<String, Long>();
memInfo.put("total", totalMemory);
memInfo.put("used", usedMemory);
memInfo.put("free", freeMemory);
memInfo.put("percent_free", p100);
systemInfo.put("memory", memInfo);
systemInfo.put("powered_by", POWERED_BY_MICRO);
//cpu usage in milli secs
long currentCpuUsage = sunOperatingSystemMXBean.getProcessCpuTime() / 1000000;
osMap.put("cpu_usage", currentCpuUsage);
osMap.put("available_processors", sunOperatingSystemMXBean.getAvailableProcessors());
osMap.put("system_load_average", sunOperatingSystemMXBean.getSystemLoadAverage());
osMap.put("committed_virtual_memory_size", sunOperatingSystemMXBean.getCommittedVirtualMemorySize());
osMap.put("free_physical_memory_size", sunOperatingSystemMXBean.getFreePhysicalMemorySize());
osMap.put("total_physical_memory_size", sunOperatingSystemMXBean.getTotalPhysicalMemorySize());
osMap.put("free_swap_space_size", sunOperatingSystemMXBean.getFreeSwapSpaceSize());
osMap.put("total_swap_space_size", sunOperatingSystemMXBean.getTotalSwapSpaceSize());
systemInfo.put("os", osMap);
List<GarbageCollectorMXBean> gc = ManagementFactory.getGarbageCollectorMXBeans();