parent
89b6e39e0c
commit
259fe8caa0
|
@ -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<Thread> threadList = new ArrayList<Thread>();
|
||||
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<LimitModel.ParameterModel> 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) {
|
||||
|
|
Loading…
Reference in New Issue