From 259fe8caa0e8be0e66f02354de913c7df6113d41 Mon Sep 17 00:00:00 2001 From: liuchongrui Date: Thu, 25 Sep 2014 14:50:22 +0800 Subject: [PATCH] add getLimitResult function judge whether reach limit --- .../bench4q/monitor/model/MonitorMain.java | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) 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 7677a843..10e0fdd7 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 @@ -6,6 +6,7 @@ import java.util.Date; import java.util.List; import java.util.TimeZone; import java.util.concurrent.ExecutionException; +import java.util.jar.Attributes.Name; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @@ -31,7 +32,8 @@ public class MonitorMain extends SampleModel { private ProcessModel processModel; @XmlElement(name = "touch_limit") private boolean isTouchLimit; - + @XmlElement(name = "reach_limit") + private boolean isReachLimit; private SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd-HH-mm-ss"); @@ -59,8 +61,42 @@ public class MonitorMain extends SampleModel { System.out.println(System.currentTimeMillis() - startTime); } - public MonitorMain(LimitModel limitModel) { - + public MonitorMain(LimitModel limitModel) throws SigarException { + dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")); + this.date = dateFormat.format(new Date()); + long startTime = System.currentTimeMillis(); + List threadList = new ArrayList(); + threadList.add(new Thread(new ProcessModel(this))); + threadList.add(new Thread(new PhysicalDiskModel(this))); + threadList.add(new Thread(new ProcessorModel(this))); + threadList.add(new Thread(new NetworkInterfaceModel(this))); + for (Thread thread : threadList) + thread.start(); + memoryModel = new MemoryModel(); + boolean threadIsAlive = true; + while (threadIsAlive) { + threadIsAlive = false; + for (Thread thread : threadList) { + if (thread.isAlive()) + threadIsAlive = true; + } + } + this.isReachLimit = getLimitresult(limitModel); + System.out.println(System.currentTimeMillis() - startTime); + } + + private boolean getLimitresult(LimitModel limitModel) throws SigarException { + //LimitableFieldsModel limitableFieldsModel = new LimitableFieldsModel(); + boolean limitResult = false; + List list = limitModel.getParams(); + 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; + } + return limitResult; } public void setProcesssModel(ProcessModel processModel) {