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.AgentResponseModel;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Component
@Controller
@RequestMapping("/agentManage")
public class AgentController extends BaseController {
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.exception.ExceptionLog;
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.MonitorMain;
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.ProcessorModel;
import org.bench4q.share.models.monitor.ProcessorModelChild;
@Entity
@Table(name = "monitor")
public class Monitor {
@ -118,6 +120,8 @@ public class Monitor {
try {
MonitorMain monitorMain = getTestMonitorSampler().getMonitorResult(
hostName, port);
System.out.println(MarshalHelper.tryMarshal(monitorMain));
List<MonitorResult> monitorResults = this.getTestPlanFactory()
.createMonitorResultListWithOutId(monitorMain, testPlan,
this, monitorMain.getSamplingTime());
@ -128,7 +132,8 @@ public class Monitor {
return null;
}
}
public List<MonitorResult> createFinishedResult(){
public List<MonitorResult> createFinishedResult() {
try {
MonitorMain monitorMain = createFinishedMonitorMain();
List<MonitorResult> monitorResults = this.getTestPlanFactory()
@ -142,49 +147,56 @@ public class Monitor {
}
}
private MonitorMain createFinishedMonitorMain(){
MonitorMain monitorMain=new MonitorMain();
Date date=new Date();
private MonitorMain createFinishedMonitorMain() {
MonitorMain monitorMain = new MonitorMain();
Date date = new Date();
monitorMain.setSamplingTime(date);
monitorMain.setFinished(true);
monitorMain.setMemoryModel(createFinishedMemoryModel(date));
monitorMain.setNetworkInterfaceModel(createFinishedNetworkInterfaceModel(date));
monitorMain
.setNetworkInterfaceModel(createFinishedNetworkInterfaceModel(date));
monitorMain.setProcessorModel(createFinishedProcessorModel(date));
monitorMain.setPhysicalDiskModel(createFinishedPhysicalDiskModel(date));
monitorMain.setProcessModel(createFinishedProcessModel(date));
return monitorMain;
}
private ProcessorModel createFinishedProcessorModel(Date date){
ProcessorModel processorModel=new ProcessorModel();
private ProcessorModel createFinishedProcessorModel(Date date) {
ProcessorModel processorModel = new ProcessorModel();
processorModel.setSamplingTime(date);
processorModel.setFinished(true);
processorModel.setProcessorModelList(new LinkedList<ProcessorModelChild>());
processorModel
.setProcessorModelList(new LinkedList<ProcessorModelChild>());
processorModel.setCpuInstanceList(new LinkedList<String>());
return processorModel;
}
private MemoryModel createFinishedMemoryModel(Date date){
MemoryModel memoryModel=new MemoryModel();
private MemoryModel createFinishedMemoryModel(Date date) {
MemoryModel memoryModel = new MemoryModel();
memoryModel.setFinished(true);
memoryModel.setSamplingTime(date);
return memoryModel;
}
private PhysicalDiskModel createFinishedPhysicalDiskModel(Date date){
PhysicalDiskModel physicalDiskModel=new PhysicalDiskModel();
private PhysicalDiskModel createFinishedPhysicalDiskModel(Date date) {
PhysicalDiskModel physicalDiskModel = new PhysicalDiskModel();
physicalDiskModel.setFinished(true);
physicalDiskModel.setSamplingTime(date);
return physicalDiskModel;
}
private NetworkInterfaceModel createFinishedNetworkInterfaceModel(Date date){
NetworkInterfaceModel networkInterfaceModel=new NetworkInterfaceModel();
private NetworkInterfaceModel createFinishedNetworkInterfaceModel(Date date) {
NetworkInterfaceModel networkInterfaceModel = new NetworkInterfaceModel();
networkInterfaceModel.setFinished(true);
networkInterfaceModel.setSamplingTime(date);
return networkInterfaceModel;
}
private ProcessModel createFinishedProcessModel(Date date){
ProcessModel processModel=new ProcessModel();
private ProcessModel createFinishedProcessModel(Date date) {
ProcessModel processModel = new ProcessModel();
processModel.setProcessModelList(new LinkedList<ProcessModelChild>());
processModel.setProcessNameList(new LinkedList<String>());
processModel.setFinished(true);

View File

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

View File

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

View File

@ -95,6 +95,19 @@ public class MonitorMessengerImpl implements MonitorMessenger {
}
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;
}
}