package com.walmartlabs.mupd8.application.statistics;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.OperatingSystemMXBean;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class NodeStatisticsCollector extends AbstractStatisticsCollector
		implements NodeStatisticsCollectorMXBean {

	public static final NodeStatisticsCollector INSTANCE = new NodeStatisticsCollector();

	private static final OperatingSystemMXBean opBean = ManagementFactory
			.getOperatingSystemMXBean();

	private static final MemoryMXBean memBean = ManagementFactory
			.getMemoryMXBean();

	private NodeStatisticsCollector() {
		super("walmartlabs.com:" + "name" + "=" + " node_statistics" + " for "
				+ getHostIPAddress());
	}

	@Override
	public String getNodeLoadAvg() {
		return "" + opBean.getSystemLoadAverage();
	}

	@Override
	public String getNodeHeapMemoryUsage() {
		return "" + memBean.getHeapMemoryUsage();
	}

	private static String getHostIPAddress() {
		String hostname;
		try {
			InetAddress addr = InetAddress.getLocalHost();
			byte[] ipAddr = addr.getAddress();
			hostname = addr.getHostName();
			return hostname + "_" + new String(ipAddr);
		} catch (UnknownHostException e) {
			System.out.println(" Exception in obtaining hostname/IpAddress!");
			return null;
		}
	}
}

@@ -1038,35 +1038,16 @@
 ) %7B%0A
-%09%09String hostname;%0A
 %09%09try %7B%0A
 %09%09%09I
@@ -1042,16 +1042,16 @@
 %09%09try %7B%0A
+
 %09%09%09InetA
@@ -1099,121 +1099,62 @@
 %0A%09%09%09
-byte%5B%5D ipAddr = addr.getAddress();%0A%09%09%09hostname = addr.getHostName();%0A%09%09%09return hostname + %22_%22 + new String(ipAddr
+return addr.getHostName() + %22_%22 + addr.getHostAddress(
 );%0A%09

fix hostname in statistics