fix monitor result sample time

This commit is contained in:
fanfuxiaoran 2014-07-03 17:21:58 +08:00
parent 861a37b422
commit 4f94ee5598
5 changed files with 52 additions and 26 deletions

View File

@ -10,14 +10,14 @@ import org.bench4q.master.domain.service.UserService;
import org.bench4q.share.models.master.AgentModel; import org.bench4q.share.models.master.AgentModel;
import org.bench4q.share.models.master.AgentResponseModel; import org.bench4q.share.models.master.AgentResponseModel;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
@Component @Controller
@RequestMapping("/agentManage") @RequestMapping("/agentManage")
public class AgentController extends BaseController { public class AgentController extends BaseController {
private AgentService agentService; private AgentService agentService;

View File

@ -24,6 +24,7 @@ import org.bench4q.master.domain.factory.TestPlanFactory;
import org.bench4q.master.domain.valueobject.datastatistics.TestMonitorSampler; import org.bench4q.master.domain.valueobject.datastatistics.TestMonitorSampler;
import org.bench4q.master.exception.ExceptionLog; import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.master.helper.ApplicationContextHelper; import org.bench4q.master.helper.ApplicationContextHelper;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.monitor.MemoryModel; import org.bench4q.share.models.monitor.MemoryModel;
import org.bench4q.share.models.monitor.MonitorMain; import org.bench4q.share.models.monitor.MonitorMain;
import org.bench4q.share.models.monitor.NetworkInterfaceModel; import org.bench4q.share.models.monitor.NetworkInterfaceModel;
@ -32,6 +33,7 @@ import org.bench4q.share.models.monitor.ProcessModel;
import org.bench4q.share.models.monitor.ProcessModelChild; import org.bench4q.share.models.monitor.ProcessModelChild;
import org.bench4q.share.models.monitor.ProcessorModel; import org.bench4q.share.models.monitor.ProcessorModel;
import org.bench4q.share.models.monitor.ProcessorModelChild; import org.bench4q.share.models.monitor.ProcessorModelChild;
@Entity @Entity
@Table(name = "monitor") @Table(name = "monitor")
public class Monitor { public class Monitor {
@ -118,6 +120,8 @@ public class Monitor {
try { try {
MonitorMain monitorMain = getTestMonitorSampler().getMonitorResult( MonitorMain monitorMain = getTestMonitorSampler().getMonitorResult(
hostName, port); hostName, port);
System.out.println(MarshalHelper.tryMarshal(monitorMain));
List<MonitorResult> monitorResults = this.getTestPlanFactory() List<MonitorResult> monitorResults = this.getTestPlanFactory()
.createMonitorResultListWithOutId(monitorMain, testPlan, .createMonitorResultListWithOutId(monitorMain, testPlan,
this, monitorMain.getSamplingTime()); this, monitorMain.getSamplingTime());
@ -128,7 +132,8 @@ public class Monitor {
return null; return null;
} }
} }
public List<MonitorResult> createFinishedResult(){
public List<MonitorResult> createFinishedResult() {
try { try {
MonitorMain monitorMain = createFinishedMonitorMain(); MonitorMain monitorMain = createFinishedMonitorMain();
List<MonitorResult> monitorResults = this.getTestPlanFactory() List<MonitorResult> monitorResults = this.getTestPlanFactory()
@ -140,51 +145,58 @@ public class Monitor {
logger.error(ExceptionLog.getStackTrace(e)); logger.error(ExceptionLog.getStackTrace(e));
return null; return null;
} }
} }
private MonitorMain createFinishedMonitorMain(){
MonitorMain monitorMain=new MonitorMain(); private MonitorMain createFinishedMonitorMain() {
Date date=new Date(); MonitorMain monitorMain = new MonitorMain();
Date date = new Date();
monitorMain.setSamplingTime(date); monitorMain.setSamplingTime(date);
monitorMain.setFinished(true); monitorMain.setFinished(true);
monitorMain.setMemoryModel(createFinishedMemoryModel(date)); monitorMain.setMemoryModel(createFinishedMemoryModel(date));
monitorMain.setNetworkInterfaceModel(createFinishedNetworkInterfaceModel(date)); monitorMain
.setNetworkInterfaceModel(createFinishedNetworkInterfaceModel(date));
monitorMain.setProcessorModel(createFinishedProcessorModel(date)); monitorMain.setProcessorModel(createFinishedProcessorModel(date));
monitorMain.setPhysicalDiskModel(createFinishedPhysicalDiskModel(date)); monitorMain.setPhysicalDiskModel(createFinishedPhysicalDiskModel(date));
monitorMain.setProcessModel(createFinishedProcessModel(date)); monitorMain.setProcessModel(createFinishedProcessModel(date));
return monitorMain; return monitorMain;
} }
private ProcessorModel createFinishedProcessorModel(Date date){
ProcessorModel processorModel=new ProcessorModel(); private ProcessorModel createFinishedProcessorModel(Date date) {
ProcessorModel processorModel = new ProcessorModel();
processorModel.setSamplingTime(date); processorModel.setSamplingTime(date);
processorModel.setFinished(true); processorModel.setFinished(true);
processorModel.setProcessorModelList(new LinkedList<ProcessorModelChild>()); processorModel
.setProcessorModelList(new LinkedList<ProcessorModelChild>());
processorModel.setCpuInstanceList(new LinkedList<String>()); processorModel.setCpuInstanceList(new LinkedList<String>());
return processorModel; return processorModel;
} }
private MemoryModel createFinishedMemoryModel(Date date){
MemoryModel memoryModel=new MemoryModel(); private MemoryModel createFinishedMemoryModel(Date date) {
MemoryModel memoryModel = new MemoryModel();
memoryModel.setFinished(true); memoryModel.setFinished(true);
memoryModel.setSamplingTime(date); memoryModel.setSamplingTime(date);
return memoryModel; return memoryModel;
} }
private PhysicalDiskModel createFinishedPhysicalDiskModel(Date date){
PhysicalDiskModel physicalDiskModel=new PhysicalDiskModel(); private PhysicalDiskModel createFinishedPhysicalDiskModel(Date date) {
PhysicalDiskModel physicalDiskModel = new PhysicalDiskModel();
physicalDiskModel.setFinished(true); physicalDiskModel.setFinished(true);
physicalDiskModel.setSamplingTime(date); physicalDiskModel.setSamplingTime(date);
return physicalDiskModel; return physicalDiskModel;
} }
private NetworkInterfaceModel createFinishedNetworkInterfaceModel(Date date){
NetworkInterfaceModel networkInterfaceModel=new NetworkInterfaceModel(); private NetworkInterfaceModel createFinishedNetworkInterfaceModel(Date date) {
NetworkInterfaceModel networkInterfaceModel = new NetworkInterfaceModel();
networkInterfaceModel.setFinished(true); networkInterfaceModel.setFinished(true);
networkInterfaceModel.setSamplingTime(date); networkInterfaceModel.setSamplingTime(date);
return networkInterfaceModel; return networkInterfaceModel;
} }
private ProcessModel createFinishedProcessModel(Date date){
private ProcessModel createFinishedProcessModel(Date date) {
ProcessModel processModel=new ProcessModel();
ProcessModel processModel = new ProcessModel();
processModel.setProcessModelList(new LinkedList<ProcessModelChild>()); processModel.setProcessModelList(new LinkedList<ProcessModelChild>());
processModel.setProcessNameList(new LinkedList<String>()); processModel.setProcessNameList(new LinkedList<String>());
processModel.setFinished(true); processModel.setFinished(true);

View File

@ -189,8 +189,8 @@ public class TestPlanFactory {
try { try {
fields[i].setAccessible(true); fields[i].setAccessible(true);
String content=MarshalHelper.marshal( String content = MarshalHelper.marshal(fields[i].getType(),
fields[i].getType(), fields[i].get(scriptResultModel)); fields[i].get(scriptResultModel));
testPlanScriptResult.setResultContent(content); testPlanScriptResult.setResultContent(content);
} catch (IllegalArgumentException | IllegalAccessException } catch (IllegalArgumentException | IllegalAccessException
| JAXBException e) { | JAXBException e) {
@ -222,7 +222,7 @@ public class TestPlanFactory {
fields[i].getType(), fields[i].get(monitorMain))); fields[i].getType(), fields[i].get(monitorMain)));
} catch (IllegalArgumentException | IllegalAccessException } catch (IllegalArgumentException | IllegalAccessException
| JAXBException e) { | JAXBException e) {
Logger.getLogger(MonitorResult.class).info( Logger.getLogger(this.getClass()).info(
ExceptionLog.getStackTrace(e)); ExceptionLog.getStackTrace(e));
return null; return null;
} }

View File

@ -166,6 +166,7 @@ public class AgentRepository extends AbstractRepositoty {
return session.createCriteria(Agent.class) return session.createCriteria(Agent.class)
.addOrder(Order.desc("remainLoad")).list(); .addOrder(Order.desc("remainLoad")).list();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
return null; return null;
} finally { } finally {
releaseSession(session); releaseSession(session);

View File

@ -95,6 +95,19 @@ public class MonitorMessengerImpl implements MonitorMessenger {
} }
public MonitorMain monitorModel(String hostName, int port) { public MonitorMain monitorModel(String hostName, int port) {
return this.getMonitorModel(hostName, port, MonitorMain.class, "all"); MonitorMain monitorMain = this.getMonitorModel(hostName, port,
MonitorMain.class, "all");
monitorMain.getMemoryModel().setSamplingTime(
monitorMain.getSamplingTime());
monitorMain.getNetworkInterfaceModel().setSamplingTime(
monitorMain.getSamplingTime());
monitorMain.getPhysicalDiskModel().setSamplingTime(
monitorMain.getSamplingTime());
monitorMain.getProcessModel().setSamplingTime(
monitorMain.getSamplingTime());
monitorMain.getProcessorModel().setSamplingTime(
monitorMain.getSamplingTime());
return monitorMain;
} }
} }