fix the monitor main
This commit is contained in:
parent
f304ff5a63
commit
698d70ebb8
|
@ -72,7 +72,7 @@ public class MonitorServer {
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
|
||||||
MonitorServer monitorServer = new MonitorServer(5557);
|
MonitorServer monitorServer = new MonitorServer(5556);
|
||||||
monitorServer.start();
|
monitorServer.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.bench4q.monitor.api;
|
package org.bench4q.monitor.api;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import org.bench4q.monitor.model.MonitorMain;
|
import org.bench4q.monitor.model.MonitorMain;
|
||||||
|
@ -15,8 +14,7 @@ public class MainController {
|
||||||
@RequestMapping("/all")
|
@RequestMapping("/all")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
MonitorMain getMainModel() throws SigarException, InterruptedException, ExecutionException {
|
MonitorMain getMainModel() throws SigarException, InterruptedException, ExecutionException {
|
||||||
Date date = new Date();
|
MonitorMain retModel = new MonitorMain();
|
||||||
MonitorMain retModel = new MonitorMain(date);
|
|
||||||
return retModel;
|
return retModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,40 +9,33 @@ import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import javax.xml.bind.annotation.XmlType;
|
|
||||||
|
|
||||||
import org.hyperic.sigar.SigarException;
|
import org.hyperic.sigar.SigarException;
|
||||||
|
|
||||||
import com.google.gson.annotations.Expose;
|
import com.google.gson.annotations.Expose;
|
||||||
|
|
||||||
@XmlRootElement(name = "history")
|
@XmlRootElement(name = "history")
|
||||||
@XmlType
|
|
||||||
public class MonitorMain {
|
public class MonitorMain {
|
||||||
@Expose
|
|
||||||
@XmlElement
|
@XmlElement
|
||||||
private String date;
|
private String date;
|
||||||
@Expose
|
|
||||||
@XmlElement(name = "processor_info")
|
@XmlElement(name = "processor_info")
|
||||||
private ProcessorModel processorModel;
|
private ProcessorModel processorModel;
|
||||||
@Expose
|
|
||||||
@XmlElement(name = "memory_info")
|
@XmlElement(name = "memory_info")
|
||||||
private MemoryModel memoryModel;
|
private MemoryModel memoryModel;
|
||||||
@Expose
|
|
||||||
@XmlElement(name = "disk_info")
|
@XmlElement(name = "disk_info")
|
||||||
private PhysicalDiskModel physicalDiskModel;
|
private PhysicalDiskModel physicalDiskModel;
|
||||||
@Expose
|
@Expose
|
||||||
@XmlElement(name = "network_info")
|
@XmlElement(name = "network_info")
|
||||||
private NetworkInterfaceModel networkInterfaceModel;
|
private NetworkInterfaceModel networkInterfaceModel;
|
||||||
@Expose
|
|
||||||
@XmlElement(name = "process_info")
|
@XmlElement(name = "process_info")
|
||||||
private ProcessModel processModel;
|
private ProcessModel processModel;
|
||||||
private SimpleDateFormat dateFormat = new SimpleDateFormat(
|
private SimpleDateFormat dateFormat = new SimpleDateFormat(
|
||||||
"yyyy-MM-dd-HH-mm-ss");
|
"yyyy-MM-dd-HH-mm-ss");
|
||||||
|
|
||||||
public MonitorMain(Date date) throws SigarException, InterruptedException,
|
public MonitorMain() throws SigarException, InterruptedException,
|
||||||
ExecutionException {
|
ExecutionException {
|
||||||
dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
||||||
this.date = dateFormat.format(date);
|
this.date = dateFormat.format(new Date());
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
List<Thread> threadList = new ArrayList<Thread>();
|
List<Thread> threadList = new ArrayList<Thread>();
|
||||||
threadList.add(new Thread(new ProcessModel(this)));
|
threadList.add(new Thread(new ProcessModel(this)));
|
||||||
|
|
|
@ -30,11 +30,10 @@ public class WriteSystemInfoToLocalDisk {
|
||||||
public void writeCurrentSystemInfoToLocalDisk() throws SigarException,
|
public void writeCurrentSystemInfoToLocalDisk() throws SigarException,
|
||||||
InterruptedException, ExecutionException, IOException {
|
InterruptedException, ExecutionException, IOException {
|
||||||
dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
||||||
Date date = new Date();
|
MonitorMain mainModel = new MonitorMain();
|
||||||
MonitorMain mainModel = new MonitorMain(date);
|
|
||||||
FileWriter writer = null;
|
FileWriter writer = null;
|
||||||
try {
|
try {
|
||||||
writer = new FileWriter(savePath + dateFormat.format(date)
|
writer = new FileWriter(savePath + dateFormat.format(new Date())
|
||||||
+ ".json");
|
+ ".json");
|
||||||
Gson gson = new GsonBuilder()
|
Gson gson = new GsonBuilder()
|
||||||
.excludeFieldsWithoutExposeAnnotation().create();
|
.excludeFieldsWithoutExposeAnnotation().create();
|
||||||
|
|
Loading…
Reference in New Issue