From 25e553a178858d822bb215432b59b8cb7f9237c6 Mon Sep 17 00:00:00 2001 From: liuchongrui Date: Fri, 10 Oct 2014 10:23:43 +0800 Subject: [PATCH] modify limitFieldModel and test --- .../org/bench4q/monitor/api/MainController.java | 4 +--- .../monitor/model/LimitableFieldsModel.java | 17 +++++++++++------ .../org/bench4q/monitor/model/MonitorMain.java | 1 + .../monitor/Test_LimitableFieldsModel.java | 5 ++++- .../monitor/controler/Test_MainControler.java | 12 ++++++------ 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/MainController.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/MainController.java index a9385130..667da287 100644 --- a/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/MainController.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/MainController.java @@ -1,8 +1,6 @@ package org.bench4q.monitor.api; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.UUID; import java.util.concurrent.ExecutionException; @@ -32,7 +30,7 @@ public class MainController { @RequestMapping(value = "/limitableFields") @ResponseBody - public LimitableFieldsModel limitableFields() { + public LimitableFieldsModel limitableFields() throws SigarException { return new LimitableFieldsModel(); } 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 12f17389..fb4c521e 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,6 +7,9 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; +import org.hyperic.sigar.SigarException; + + @XmlRootElement(name = "limitableFields") public class LimitableFieldsModel { private List fieldsParent; @@ -21,17 +24,19 @@ public class LimitableFieldsModel { this.fields = fields; } - public LimitableFieldsModel() { + public LimitableFieldsModel() throws SigarException { this.fields = new ArrayList(); this.fieldsParent = new ArrayList(); + String stringMemoryModel = new MemoryModel().getClass().getName(); + String stringProcessorModel = new ProcessorModel().getClass().getName(); this.fields.add("MemoryUsedPercent"); - this.fieldsParent.add("org.bench4q.monitor.model.MemoryModel"); + this.fieldsParent.add(stringMemoryModel); this.fields.add("ProcessorTimePercent"); - this.fieldsParent.add("org.bench4q.monitor.model.ProcessorModel"); + this.fieldsParent.add(stringProcessorModel); this.fields.add("UserTimePercent"); - this.fieldsParent.add("org.bench4q.monitor.model.ProcessorModel"); + this.fieldsParent.add(stringProcessorModel); this.fields.add("PrivilegedTimePercent"); - this.fieldsParent.add("org.bench4q.monitor.model.ProcessorModel"); + this.fieldsParent.add(stringProcessorModel); } public String validname(String name){ @@ -49,6 +54,6 @@ public class LimitableFieldsModel { public void setFieldsParent(List fieldsParent) { this.fieldsParent = fieldsParent; } - + } 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 e99c83d5..f1814329 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 @@ -108,6 +108,7 @@ public class MonitorMain extends SampleModel { Method mget=c.getMethod("get"+name); double currentvalue=(Double) mget.invoke(obj); if (currentvalue >= limit) limitResult = true; + //System.out.println(name+": "+currentvalue); } catch (Exception e) { e.printStackTrace(); } diff --git a/Bench4Q-Monitor-Sigar/src/test/java/org/bench4q/monitor/Test_LimitableFieldsModel.java b/Bench4Q-Monitor-Sigar/src/test/java/org/bench4q/monitor/Test_LimitableFieldsModel.java index 67a4669a..13d49556 100644 --- a/Bench4Q-Monitor-Sigar/src/test/java/org/bench4q/monitor/Test_LimitableFieldsModel.java +++ b/Bench4Q-Monitor-Sigar/src/test/java/org/bench4q/monitor/Test_LimitableFieldsModel.java @@ -3,15 +3,18 @@ package org.bench4q.monitor; import java.util.List; import org.bench4q.monitor.model.LimitableFieldsModel; +import org.hyperic.sigar.SigarException; import org.junit.Test; public class Test_LimitableFieldsModel { @Test - public void testLimitableFieldsModelGet(){ + public void testLimitableFieldsModelGet() throws SigarException{ LimitableFieldsModel limitList = new LimitableFieldsModel(); List result = limitList.getFields(); + List resultP = limitList.getFieldsParent(); for (int i = 0; i < result.size(); i++){ System.out.println(result.get(i).toString()); + System.out.println(resultP.get(i).toString()); } } diff --git a/Bench4Q-Monitor-Sigar/src/test/java/org/bench4q/monitor/controler/Test_MainControler.java b/Bench4Q-Monitor-Sigar/src/test/java/org/bench4q/monitor/controler/Test_MainControler.java index aed2bd05..2539a459 100644 --- a/Bench4Q-Monitor-Sigar/src/test/java/org/bench4q/monitor/controler/Test_MainControler.java +++ b/Bench4Q-Monitor-Sigar/src/test/java/org/bench4q/monitor/controler/Test_MainControler.java @@ -16,14 +16,14 @@ public class Test_MainControler { LimitModel.ParameterModel params2 = new LimitModel.ParameterModel(); LimitModel.ParameterModel params3 = new LimitModel.ParameterModel(); LimitModel.ParameterModel params4 = new LimitModel.ParameterModel(); - params1.setName("memoryUsedPercent"); + params1.setName("MemoryUsedPercent"); params1.setLimit(100); - params2.setName("processorTimePercent"); - params2.setLimit(10); - params3.setName("userTimePercent"); + params2.setName("ProcessorTimePercent"); + params2.setLimit(100); + params3.setName("UserTimePercent"); params3.setLimit(100); - params4.setName("privilegedTimePercent"); - params4.setLimit(100); + params4.setName("PrivilegedTimePercent"); + params4.setLimit(20); List list = new ArrayList(); list.add(params1); list.add(params2);