package org.bench4q.monitor.api;

import java.io.IOException;

import org.bench4q.monitor.entiry.MonitorContorlEntity;
import org.bench4q.monitor.model.MemoryModel;
import org.bench4q.monitor.service.linux.MemoryServiceLinux;
import org.bench4q.monitor.service.windows.MemoryServiceWindows;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/Monitor")
public class MemoryController extends MonitorContorlEntity {

	@RequestMapping(value = "/Memory", method = { RequestMethod.GET,
			RequestMethod.POST })
	@ResponseBody
	public MemoryModel getMemoryInfo() throws NumberFormatException,
			IOException {
		if (this.getOsNameString().contains("windows")) {
			MemoryServiceWindows memoryServiceWindows = new MemoryServiceWindows();

			return memoryServiceWindows.getMemoryInfo(this.getIdleTime());
		} else if (this.getOsNameString().contains("linux")) {
			MemoryServiceLinux memoryServiceLinux = new MemoryServiceLinux();
			return memoryServiceLinux.getMemoryInfo(this.getIdleTime());
		} else
			return null;
	}
}
