/*
 * Copyright (C) 2012 - 2012 NHN Corporation
 * All rights reserved.
 *
 * This file is part of The nGrinder software distribution. Refer to
 * the file LICENSE which is part of The nGrinder distribution for
 * licensing details. The nGrinder distribution is available on the
 * Internet at http://nhnopensource.org/ngrinder
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package org.ngrinder.monitor.agent.collector;

import org.apache.commons.lang.SystemUtils;
import org.hyperic.sigar.OperatingSystem;
import org.hyperic.sigar.Sigar;
import org.ngrinder.monitor.MonitorConstants;
import org.ngrinder.monitor.agent.mxbean.SystemMonitoringData;
import org.ngrinder.monitor.share.domain.SystemInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AgentSystemDataCollector extends AgentDataCollector {
	private static final Logger LOG = LoggerFactory.getLogger(AgentSystemDataCollector.class);

	private long failedCount = 0;
	private Sigar sigar = new Sigar();

	@Override
	public synchronized void refresh() {

	}

	@Override
	public void run() {
		SystemMonitoringData systemMonitoringData = (SystemMonitoringData) getMXBean(MonitorConstants.SYSTEM);
		SystemInfo systemInfo = execute();
		systemMonitoringData.addNotification(systemInfo);
		systemMonitoringData.setSystemInfo(systemInfo);
	}

	public synchronized SystemInfo execute() {
		SystemInfo systemInfo = new SystemInfo();
		try {
			systemInfo.setCPUUsedPercentage((float) sigar.getCpuPerc().getCombined() * 100);
			systemInfo.setTotalMemory(sigar.getMem().getTotal() / 1024);
			systemInfo.setFreeMemory(sigar.getMem().getFree() / 1024);
			systemInfo.setSystem(OperatingSystem.IS_WIN32 ? SystemInfo.System.WINDOW : SystemInfo.System.LINUX);
		} catch (Exception e) {
			if ((failedCount++) % 60 == 0) {
				if (SystemUtils.IS_OS_WINDOWS) {
					LOG.error("Error while getting system perf data");
					LOG.error("You should run agent in administrator permission");
				} else {
					LOG.error("Error while getting system perf data", e);
				}
			}
		}
		systemInfo.setCollectTime(System.currentTimeMillis());
		return systemInfo;
	}
}

@@ -1172,52 +1172,8 @@
 r;%0A%0A
-import org.apache.commons.lang.SystemUtils;%0A
 impo
@@ -1210,16 +1210,16 @@
 System;%0A
+
 import o
@@ -1739,17 +1739,16 @@
 esh() %7B%0A
-%0A
 %09%7D%0A%0A%09@Ov
@@ -2465,17 +2465,16 @@
 %7B%0A%09%09%09if 
-(
 (failedC
@@ -2483,18 +2483,13 @@
 nt++
-) %25 60
  == 
+6
 0) %7B
@@ -2497,42 +2497,25 @@
 %09%09%09%09
-if (SystemUtils.IS_OS_WINDOWS) %7B%0A%09
+failedCount = 0;%0A
 %09%09%09%09
@@ -2566,156 +2566,63 @@
 ata%22
-);%0A%09%09%09%09%09LOG.error(%22You should run agent in administrator permission%22);%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09LOG.error(%22Error while getting system perf data%22, e);%0A%09%09%09%09%7D
+, e.getMessage());%0A%09%09%09%09LOG.debug(%22Error trace is %22, e);
 %0A%09%09%09

Make a experimental implementation on sigar - delete unnecessary part