package org.bench4q.monitor.api;

import java.io.IOException;

import org.bench4q.monitor.entiry.MonitorContorlEntity;
import org.bench4q.monitor.model.ProcessModel;
import org.bench4q.monitor.service.linux.ProcessServiceLinux;
import org.bench4q.monitor.service.windows.ProcessServiceWindows;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

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

	@RequestMapping("/Process")
	@ResponseBody
	public ProcessModel getProcessInfo() throws IOException,
			InterruptedException {

		if (this.getOsNameString().contains("windows")) {
			ProcessServiceWindows processServiceWindows = new ProcessServiceWindows();
			return processServiceWindows.getProcessInfo(this.getIdleTime());
		} else if (this.getOsNameString().contains("linux")) {
			ProcessServiceLinux processServiceLinux = new ProcessServiceLinux();
			// ProcessModel processModel =
			// processServiceLinux.getProcessInfo(this
			// .getIdleTime());

			return processServiceLinux.getProcessInfo(this.getIdleTime());
		} else
			return null;
	}

}
