This commit is contained in:
hmm 2014-09-26 11:35:19 +08:00
commit 4f98da003c
2 changed files with 40 additions and 20 deletions

View File

@ -9,8 +9,8 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "limitableFields")
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;
@ -97,21 +99,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;
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();
}
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;
}
}
return limitResult;