modify getLimitResult function

This commit is contained in:
liuchongrui 2014-09-26 10:21:32 +08:00
parent 401c3b16d6
commit fe2a6e391a
2 changed files with 40 additions and 20 deletions

View File

@ -9,8 +9,8 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class LimitableFieldsModel {
private List<String> fieldsParent;
private List<String> fields;
@XmlElementWrapper(name = "fieldList")
@XmlElement(name = "field")
public List<String> getFields() {
@ -23,10 +23,31 @@ public class LimitableFieldsModel {
public LimitableFieldsModel() {
this.fields = new ArrayList<String>();
this.fields.add("memoryUsedPercent");
this.fields.add("processorTimePercent");
this.fields.add("userTimePercent");
this.fields.add("privilegedTimePercent");
this.fieldsParent = new ArrayList<String>();
this.fields.add("MemoryUsedPercent");
this.fieldsParent.add("org.bench4q.monitor.model.MemoryModel");
this.fields.add("ProcessorTimePercent");
this.fieldsParent.add("org.bench4q.monitor.model.ProcessorModel");
this.fields.add("UserTimePercent");
this.fieldsParent.add("org.bench4q.monitor.model.ProcessorModel");
this.fields.add("PrivilegedTimePercent");
this.fieldsParent.add("org.bench4q.monitor.model.ProcessorModel");
}
public String validname(String name){
for (int i = 0; i < this.fields.size(); i++){
if (name.toUpperCase().equals(fields.get(i).toUpperCase()))
return fieldsParent.get(i);
}
return "";
}
public List<String> getFieldsParent() {
return fieldsParent;
}
public void setFieldsParent(List<String> fieldsParent) {
this.fieldsParent = fieldsParent;
}

View File

@ -1,11 +1,13 @@
package org.bench4q.monitor.model;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import java.util.concurrent.ExecutionException;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@ -96,21 +98,18 @@ public class MonitorMain extends SampleModel {
for (int i = 0; i < list.size(); i++){
String name = list.get(i).getName();
double limit = list.get(i).getLimit();
if (name.equals("memoryUsedPercent")){
if (limit <= this.memoryModel.getMemoryUsedPercent())
limitResult = true;
}
if (name.equals("processorTimePercent")){
if (limit <= this.processorModel.getProcessorTimePercent())
limitResult = true;
}
if (name.equals("userTimePercent")){
if (limit <= this.processorModel.getUserTimePercent())
limitResult = true;
}
if (name.equals("privilegedTimePercent")){
if (limit <= this.processorModel.getPrivilegedTimePercent())
limitResult = true;
LimitableFieldsModel limitableFieldsModel = new LimitableFieldsModel();
String parent = limitableFieldsModel.validname(name);
if (parent !=""){
try {
Class<?> c = Class.forName(parent);
Object obj=c.newInstance();
Method mget=c.getMethod("get"+name);
double currentvalue=(Double) mget.invoke(obj);
if (currentvalue >= limit) limitResult = true;
} catch (Exception e) {
e.printStackTrace();
}
}
}
return limitResult;