package org.bench4q.monitor.api;

import java.io.IOException;

import org.bench4q.monitor.entiry.MonitorContorlEntity;
import org.bench4q.monitor.model.ProcessorModel;
import org.bench4q.monitor.service.linux.ProcessorServiceLinux;
import org.bench4q.monitor.service.windows.ProcessorServiceWindows;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

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

	@RequestMapping("/Processor")
	@ResponseBody
	public ProcessorModel getProcessorInfo() throws IOException, InterruptedException {

		if (this.getOsNameString().contains("windows")) {
			ProcessorServiceWindows processorServiceWindows=new ProcessorServiceWindows();
			return processorServiceWindows.getProcessorInfo(
					this.getIdleTime());
		} 
		else if (this.getOsNameString().contains("linux")){
			
			ProcessorServiceLinux processorServiceLinux=new ProcessorServiceLinux();
			return processorServiceLinux.getProcessorInfo(
					this.getIdleTime());
		}
		else
			return null;
	}
}
