diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/api/MonitorController.java b/Bench4Q-Master/src/main/java/org/bench4q/master/api/MonitorController.java index 6079fb3c..24d458bf 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/api/MonitorController.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/api/MonitorController.java @@ -98,13 +98,14 @@ public class MonitorController extends BaseController { return ret == null ? new MonitorNetworkReponseModel() : ret; } - @RequestMapping(value = "/getLimitableFields") + @RequestMapping(value = "/getLimitableFields/{hostName}/{port}") @ResponseBody - public LimitableFieldsModel getLimitableFields(@ModelAttribute("accessToken") String accessToken) throws Bench4QException{ + public LimitableFieldsModel getLimitableFields(@ModelAttribute("accessToken") String accessToken, + @PathVariable String hostName, @PathVariable int port) throws Bench4QException{ if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { throw new Bench4QException(400 + "", "not permitted", "/networkInfo"); } - return this.getMonitorResultService().getLimitableFields(); + return this.getMonitorResultService().getLimitableFields(hostName, port); } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/Monitor.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/Monitor.java index 7103cb2d..9c918e15 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/Monitor.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/Monitor.java @@ -122,7 +122,7 @@ public class Monitor { public List doAfterRun(Date sampeTime) { try { MonitorMain monitorMain = getTestMonitorSampler().getMonitorResult( - hostName, port); + hostName, port, this.testPlan.getTestPlanRunId()); System.out.println(MarshalHelper.tryMarshal(monitorMain)); //tell test plan has to stop itself testPlan.setHasToStop(monitorMain.isTouchLimit()); @@ -137,8 +137,8 @@ public class Monitor { } } - public void start(UUID testPlanId, String limitModel){ - this.getTestMonitorSampler().startMonitor(hostName, port, testPlanId, limitModel); + public void start(){ + this.getTestMonitorSampler().startMonitor(hostName, port, this.testPlan.getTestPlanRunId(), this.testPlan.getLimitModel()); } public List createFinishedResult() { diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlan.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlan.java index cebcae9a..2b808f13 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlan.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlan.java @@ -225,6 +225,8 @@ public class TestPlan implements IAggregate { result = false; } } + getTestResultSave().update(TestPlan.this, + collectResult(new Date())); this.setCurrentStatus(TestPlanStatus.Complete.name()); return result; } @@ -262,10 +264,9 @@ public class TestPlan implements IAggregate { testPlanScript.run(); } //start monitor to check the limit - UUID testPlanIdUuid = UUID.fromString(this.testPlanRunId); if (getMonitors() != null && this.limitModel != null) { for (Monitor monitor : getMonitors()) { - monitor.start(testPlanIdUuid, this.limitModel); + monitor.start(); } } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/MonitorResultService.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/MonitorResultService.java index a631f9e7..17ea1115 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/MonitorResultService.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/MonitorResultService.java @@ -12,6 +12,7 @@ import org.bench4q.master.domain.repository.TestPlanRepository; import org.bench4q.master.exception.Bench4QException; import org.bench4q.master.exception.ExceptionLog; import org.bench4q.master.helper.SessionHelper; +import org.bench4q.master.infrastructure.communication.MonitorMessenger; import org.bench4q.recorder.httpcapture.generator.HtmlDocumentParser; import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.models.master.MonitorMemoryResponseModel; @@ -28,6 +29,7 @@ import org.bench4q.share.models.monitor.ProcessorModel; import org.hibernate.Session; import org.hibernate.criterion.Order; import org.hibernate.criterion.Restrictions; +import org.python.antlr.PythonParser.return_stmt_return; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -36,6 +38,8 @@ public class MonitorResultService { private TestPlanRepository testPlanRepository; private SessionHelper sessionHelper; private LimitableFieldsModel limitableField = null; + @Autowired + private MonitorMessenger monitorMessenger; private static Logger logger = Logger.getLogger(MonitorResult.class); private TestPlanRepository getTestPlanRepository() { @@ -199,10 +203,7 @@ public class MonitorResultService { e.printStackTrace(); } } - public LimitableFieldsModel getLimitableFields(){ - if(limitableField == null){ - initLimitableFields(); - } - return limitableField; + public LimitableFieldsModel getLimitableFields(String hostName, int port){ + return monitorMessenger.getLimitableFields(hostName, port); } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/valueobject/datastatistics/TestMonitorSampler.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/valueobject/datastatistics/TestMonitorSampler.java index 4db96168..38dda3f8 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/valueobject/datastatistics/TestMonitorSampler.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/valueobject/datastatistics/TestMonitorSampler.java @@ -1,7 +1,5 @@ package org.bench4q.master.domain.valueobject.datastatistics; -import java.util.UUID; - import org.bench4q.master.infrastructure.communication.MonitorMessenger; import org.bench4q.share.models.monitor.MonitorMain; import org.springframework.beans.factory.annotation.Autowired; @@ -17,11 +15,15 @@ public class TestMonitorSampler { this.monitorMessenger = monitorMessenger; } + public MonitorMain getMonitorResult(String hostName, int port, String testPlanId) { + return this.monitorMessenger.monitorModel(hostName, port, testPlanId); + } + public MonitorMain getMonitorResult(String hostName, int port) { return this.monitorMessenger.monitorModel(hostName, port); } - - public boolean startMonitor(String hostName, int port, UUID testPlanId, String limitModel){ + + public boolean startMonitor(String hostName, int port, String testPlanId, String limitModel){ return this.monitorMessenger.startMonitor(hostName, port, testPlanId, limitModel); } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/MonitorMessenger.java b/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/MonitorMessenger.java index ac7702af..ee33dfcc 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/MonitorMessenger.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/MonitorMessenger.java @@ -1,7 +1,6 @@ package org.bench4q.master.infrastructure.communication; -import java.util.UUID; - +import org.bench4q.share.models.monitor.LimitableFieldsModel; import org.bench4q.share.models.monitor.MemoryModel; import org.bench4q.share.models.monitor.MonitorMain; import org.bench4q.share.models.monitor.NetworkInterfaceModel; @@ -10,6 +9,8 @@ import org.bench4q.share.models.monitor.ProcessModel; import org.bench4q.share.models.monitor.ProcessorModel; public interface MonitorMessenger { + public MonitorMain monitorModel(String hostName, int port, String testPlanId); + public MonitorMain monitorModel(String hostName, int port); public PhysicalDiskModel physicalDisk(String hostName, int port); @@ -22,6 +23,8 @@ public interface MonitorMessenger { public ProcessModel process(String hostName, int port); - public boolean startMonitor(String hostName, int port, UUID testPlanId, String limitModel) ; + public boolean startMonitor(String hostName, int port, String testPlanId, String limitModel) ; + + public LimitableFieldsModel getLimitableFields(String hostName, int port); } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/impl/MonitorMessengerImpl.java b/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/impl/MonitorMessengerImpl.java index 054ee246..60f23d38 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/impl/MonitorMessengerImpl.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/impl/MonitorMessengerImpl.java @@ -2,7 +2,6 @@ package org.bench4q.master.infrastructure.communication.impl; import java.io.IOException; import java.util.Date; -import java.util.UUID; import org.apache.log4j.Logger; import org.bench4q.master.exception.ExceptionLog; @@ -11,6 +10,7 @@ import org.bench4q.share.communication.HttpRequester; import org.bench4q.share.communication.HttpRequester.HttpResponse; import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.models.master.statistics.SampleModel; +import org.bench4q.share.models.monitor.LimitableFieldsModel; import org.bench4q.share.models.monitor.MemoryModel; import org.bench4q.share.models.monitor.MonitorMain; import org.bench4q.share.models.monitor.NetworkInterfaceModel; @@ -86,7 +86,24 @@ public class MonitorMessengerImpl implements MonitorMessenger { public MonitorMain monitorModel(String hostName, int port) { MonitorMain monitorMain = this.getMonitorModel(hostName, port, - MonitorMain.class, "all"); + 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; + } + + public MonitorMain monitorModel(String hostName, int port, String testPlanId) { + MonitorMain monitorMain = this.getMonitorModel(hostName, port, + MonitorMain.class, "/brief/"+testPlanId); monitorMain.getMemoryModel().setSamplingTime( monitorMain.getSamplingTime()); monitorMain.getNetworkInterfaceModel().setSamplingTime( @@ -101,7 +118,7 @@ public class MonitorMessengerImpl implements MonitorMessenger { return monitorMain; } - public boolean startMonitor(String hostName, int port, UUID testPlanId, String limitModel) { + public boolean startMonitor(String hostName, int port, String testPlanId, String limitModel) { HttpResponse httpResponse; try { httpResponse = this.getHttpRequester().sendPutXml( @@ -120,4 +137,22 @@ public class MonitorMessengerImpl implements MonitorMessenger { } + public LimitableFieldsModel getLimitableFields(String hostName, int port) { + try { + HttpResponse httpResponse = this.getHttpRequester().sendGet( + buildUrl(hostName, port, "/monitor/limitableFields" ), + null, null); + if (HttpRequester.isInvalidResponse(httpResponse)) { + logger.info("The httpResponse is invalid "); + return null; + } + LimitableFieldsModel model = MarshalHelper.unmarshal(LimitableFieldsModel.class, + httpResponse.getContent()); + return model; + } catch (Exception e) { + logger.error(ExceptionLog.getStackTrace(e)); + return null; + } + } + } diff --git a/Bench4Q-Master/src/test/java/stubs/Mock_MonitorMessenger.java b/Bench4Q-Master/src/test/java/stubs/Mock_MonitorMessenger.java index e50de992..0f9f6159 100644 --- a/Bench4Q-Master/src/test/java/stubs/Mock_MonitorMessenger.java +++ b/Bench4Q-Master/src/test/java/stubs/Mock_MonitorMessenger.java @@ -4,6 +4,7 @@ import java.util.Date; import java.util.UUID; import org.bench4q.master.infrastructure.communication.MonitorMessenger; +import org.bench4q.share.models.monitor.LimitableFieldsModel; import org.bench4q.share.models.monitor.MemoryModel; import org.bench4q.share.models.monitor.MonitorMain; import org.bench4q.share.models.monitor.NetworkInterfaceModel; @@ -53,5 +54,21 @@ public class Mock_MonitorMessenger implements MonitorMessenger { return false; } + public MonitorMain monitorModel(String hostName, int port, String testPlanId) { + // TODO Auto-generated method stub + return null; + } + + public boolean startMonitor(String hostName, int port, String testPlanId, + String limitModel) { + // TODO Auto-generated method stub + return false; + } + + public LimitableFieldsModel getLimitableFields(String hostName, int port) { + // TODO Auto-generated method stub + return null; + } + } diff --git a/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/LimitableFieldsModel.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/LimitableFieldsModel.java index c0291a98..b4bd1d5d 100644 --- a/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/LimitableFieldsModel.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/LimitableFieldsModel.java @@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; -@XmlRootElement +@XmlRootElement(name = "limitableFields") public class LimitableFieldsModel { private List fields; diff --git a/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MonitorMain.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MonitorMain.java index ba69a868..b6a26662 100644 --- a/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MonitorMain.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MonitorMain.java @@ -28,7 +28,6 @@ public class MonitorMain extends SampleModel { private NetworkInterfaceModel networkInterfaceModel; @XmlElement(name = "process_info") private ProcessModel processModel; - @XmlElement(name = "reach_limit") private boolean isReachLimit; private SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd-HH-mm-ss"); @@ -81,6 +80,8 @@ public class MonitorMain extends SampleModel { System.out.println(System.currentTimeMillis() - startTime); } + + @XmlElement(name = "touch_limit") public boolean getIsReachLimit() { return isReachLimit; } diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/api/MonitorController.java b/Bench4Q-Web/src/main/java/org/bench4q/web/api/MonitorController.java index cf73cd4d..dff45a07 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/api/MonitorController.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/api/MonitorController.java @@ -26,6 +26,7 @@ public class MonitorController extends BaseController { private MonitorMessager monitorMessager; private final String port = "5556"; + private final String localHostName = "127.0.0.1"; private MonitorService monitorService; public MonitorMessager getMonitorMessager() { @@ -194,7 +195,7 @@ public class MonitorController extends BaseController { @ResponseBody public Map getLimitableFields(@ModelAttribute("accessToken") String accessToken){ Map map = new HashMap(); - LimitableFieldsModel limitableFieldsModel = this.getMonitorMessager().getLimitableFields(accessToken); + LimitableFieldsModel limitableFieldsModel = this.getMonitorMessager().getLimitableFields(accessToken,localHostName, port); if(limitableFieldsModel == null){ return fail(map, SERVER_ERROR); } diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/MonitorMessager.java b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/MonitorMessager.java index b6d7fe52..7220fc4e 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/MonitorMessager.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/MonitorMessager.java @@ -122,8 +122,8 @@ public class MonitorMessager extends MasterMessager { } } - public LimitableFieldsModel getLimitableFields(String accessToken){ - String url = this.baseUrl + "/getLimitableFields"; + public LimitableFieldsModel getLimitableFields(String accessToken, String localHostName, String port){ + String url = this.baseUrl + "/getLimitableFields"+"/"+localHostName+"/"+port; HttpResponse httpResponse = null; try { httpResponse = this.getHttpRequester().sendGet(url, null, diff --git a/Bench4Q-Web/src/main/webapp/i18n/i18n.properties b/Bench4Q-Web/src/main/webapp/i18n/i18n.properties index 8af7b292..2bb0b224 100644 --- a/Bench4Q-Web/src/main/webapp/i18n/i18n.properties +++ b/Bench4Q-Web/src/main/webapp/i18n/i18n.properties @@ -51,4 +51,8 @@ stopRecordingMessage=Please click stop recording failed-connect-server=failed to connect server close-proxy-setting=clear the proxy setting custom-mode=custom mode -target-mode=target mode \ No newline at end of file +target-mode=target mode +memoryUsedPercent=Memory(%) +processorTimePercent=Processor Time(%) +userTimePercent=User Time(%) +privilegedTimePercent=Privileged Time(%) \ No newline at end of file diff --git a/Bench4Q-Web/src/main/webapp/i18n/i18n_zh-CN.properties b/Bench4Q-Web/src/main/webapp/i18n/i18n_zh-CN.properties index 13e2e1e1..968a998e 100644 --- a/Bench4Q-Web/src/main/webapp/i18n/i18n_zh-CN.properties +++ b/Bench4Q-Web/src/main/webapp/i18n/i18n_zh-CN.properties @@ -47,4 +47,8 @@ stopRecordingMessage=\u8bf7\u70b9\u51fb\u505c\u6b62\u5f55\u5236 failed-connect-server=\u8FDE\u63A5\u670D\u52A1\u5668\u5931\u8D25\uFF01 close-proxy-setting=\u8BF7\u5173\u95ED\u4EE3\u7406 custom-mode=\u5E38\u89C4\u6A21\u5F0F -target-mode=\u76EE\u6807\u6A21\u5F0F \ No newline at end of file +target-mode=\u76EE\u6807\u6A21\u5F0F +memoryUsedPercent=\u5185\u5B58% +processorTimePercent=\u5904\u7406\u673A\u65F6\u95F4% +userTimePercent=\u7528\u6237\u65F6\u95F4% +privilegedTimePercent=\u6743\u9650\u65F6\u95F4% \ No newline at end of file diff --git a/Bench4Q-Web/src/main/webapp/script/TestPlan/TestPlanServer.js b/Bench4Q-Web/src/main/webapp/script/TestPlan/TestPlanServer.js index d6ce8162..6ef55910 100644 --- a/Bench4Q-Web/src/main/webapp/script/TestPlan/TestPlanServer.js +++ b/Bench4Q-Web/src/main/webapp/script/TestPlan/TestPlanServer.js @@ -172,7 +172,7 @@ function loadLimitableFields(){ script.push(data[i]); var tbodyNode = document.getElementById("loadConfig2").children[0]; for ( var j = 0; j < script.length; j++) { - var textNode = document.createTextNode(script[j]); + var textNode = document.createTextNode($.i18n.prop(script[j])); var tdNode = document.createElement("td"); var tdNode2 = document.createElement("td"); var inputNode = document.createElement("input");