Merge Bench4Q-Monitor-Sigar

This commit is contained in:
coderfengyun 2014-03-20 17:19:37 +08:00
parent fa1262b689
commit 501b761289
33 changed files with 2030 additions and 2369 deletions

View File

@ -1,25 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<assembly <assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>publish</id> <id>publish</id>
<formats> <formats>
<format>tar.gz</format> <format>tar.gz</format>
</formats> </formats>
<includeBaseDirectory>false</includeBaseDirectory> <includeBaseDirectory>false</includeBaseDirectory>
<dependencySets> <dependencySets>
<dependencySet> <dependencySet>
<outputDirectory>lib</outputDirectory> <outputDirectory>lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact> <useProjectArtifact>false</useProjectArtifact>
<unpack>false</unpack> <unpack>false</unpack>
<scope>runtime</scope> <scope>runtime</scope>
</dependencySet> </dependencySet>
</dependencySets> </dependencySets>
<files> <files>
<file> <file>
<source>target/bench4q-monitor.jar</source> <source>target/bench4q-monitor.jar</source>
<outputDirectory>/</outputDirectory> <outputDirectory>/</outputDirectory>
</file> </file>
</files> </files>
</assembly> </assembly>

View File

@ -1,111 +1,111 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.bench4q</groupId> <groupId>org.bench4q</groupId>
<artifactId>bench4q-monitor</artifactId> <artifactId>bench4q-monitor</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<name>Bench4Q Monitor</name> <name>Bench4Q Monitor</name>
<description>Bench4Q Monitor</description> <description>Bench4Q Monitor</description>
<organization> <organization>
<name>TCSE, ISCAS</name> <name>TCSE, ISCAS</name>
</organization> </organization>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.google.code.gson</groupId> <groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId> <artifactId>gson</artifactId>
<version>2.2.4</version> <version>2.2.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.11</version> <version>4.11</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId> <artifactId>jetty-server</artifactId>
<version>8.1.11.v20130520</version> <version>8.1.11.v20130520</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>log4j</groupId> <groupId>log4j</groupId>
<artifactId>log4j</artifactId> <artifactId>log4j</artifactId>
<version>1.2.17</version> <version>1.2.17</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId> <artifactId>jetty-servlet</artifactId>
<version>8.1.11.v20130520</version> <version>8.1.11.v20130520</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId> <artifactId>spring-webmvc</artifactId>
<version>3.2.4.RELEASE</version> <version>3.2.4.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.codehaus.jackson</groupId> <groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId> <artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version> <version>1.9.12</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.directory.studio</groupId> <groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.io</artifactId> <artifactId>org.apache.commons.io</artifactId>
<version>2.4</version> <version>2.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.fusesource</groupId> <groupId>org.fusesource</groupId>
<artifactId>sigar</artifactId> <artifactId>sigar</artifactId>
<version>1.6.4</version> <version>1.6.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>dom4j</groupId> <groupId>dom4j</groupId>
<artifactId>dom4j</artifactId> <artifactId>dom4j</artifactId>
<version>1.6.1</version> <version>1.6.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<configuration> <configuration>
<archive> <archive>
<manifest> <manifest>
<mainClass>org.bench4q.monitor.MonitorServer</mainClass> <mainClass>org.bench4q.monitor.MonitorServer</mainClass>
<addClasspath>true</addClasspath> <addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix> <classpathPrefix>lib/</classpathPrefix>
</manifest> </manifest>
</archive> </archive>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-assembly-plugin</artifactId> <artifactId>maven-assembly-plugin</artifactId>
<executions> <executions>
<execution> <execution>
<id>make-zip</id> <id>make-zip</id>
<phase>package</phase> <phase>package</phase>
<goals> <goals>
<goal>single</goal> <goal>single</goal>
</goals> </goals>
<configuration> <configuration>
<descriptors> <descriptors>
<descriptor>descriptor.xml</descriptor> <descriptor>descriptor.xml</descriptor>
</descriptors> </descriptors>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<configuration> <configuration>
<skip>true</skip> <skip>true</skip>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
<finalName>bench4q-monitor</finalName> <finalName>bench4q-monitor</finalName>
</build> </build>
</project> </project>

View File

@ -1,78 +1,78 @@
package org.bench4q.monitor; package org.bench4q.monitor;
import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.bio.SocketConnector; import org.eclipse.jetty.server.bio.SocketConnector;
import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletHolder;
import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.DispatcherServlet;
public class MonitorServer { public class MonitorServer {
private Server server; private Server server;
private int port; private int port;
private Server getServer() { private Server getServer() {
return server; return server;
} }
private void setServer(Server server) { private void setServer(Server server) {
this.server = server; this.server = server;
} }
private int getPort() { private int getPort() {
return port; return port;
} }
private void setPort(int port) { private void setPort(int port) {
this.port = port; this.port = port;
} }
public MonitorServer(int port) { public MonitorServer(int port) {
this.setPort(port); this.setPort(port);
} }
public boolean start() { public boolean start() {
try { try {
this.setServer(new Server()); this.setServer(new Server());
Connector connector = new SocketConnector(); Connector connector = new SocketConnector();
connector.setPort(this.getPort()); connector.setPort(this.getPort());
this.getServer().addConnector(connector); this.getServer().addConnector(connector);
ServletContextHandler servletContextHandler = new ServletContextHandler(); ServletContextHandler servletContextHandler = new ServletContextHandler();
ServletHolder servletHolder = servletContextHandler.addServlet( ServletHolder servletHolder = servletContextHandler.addServlet(
DispatcherServlet.class, "/"); DispatcherServlet.class, "/");
servletHolder servletHolder
.setInitParameter("contextConfigLocation", .setInitParameter("contextConfigLocation",
"classpath*:org/bench4q/monitor/config/application-context.xml"); "classpath*:org/bench4q/monitor/config/application-context.xml");
this.getServer().setHandler(servletContextHandler); this.getServer().setHandler(servletContextHandler);
this.getServer().start(); this.getServer().start();
return true; return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
} }
public boolean stop() { public boolean stop() {
try { try {
if (this.getServer() != null) { if (this.getServer() != null) {
this.getServer().stop(); this.getServer().stop();
} }
return true; return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} finally { } finally {
this.setServer(null); this.setServer(null);
} }
} }
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(5557);
monitorServer.start(); monitorServer.start();
} }
} }

View File

@ -1,34 +1,34 @@
package org.bench4q.monitor.api; package org.bench4q.monitor.api;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.TimeZone; import java.util.TimeZone;
import org.bench4q.monitor.model.ListMainModel; import org.bench4q.monitor.model.ListMainModel;
import org.bench4q.monitor.service.ReadSystemInfoFromLocalDisk; import org.bench4q.monitor.service.ReadSystemInfoFromLocalDisk;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
@Controller @Controller
@RequestMapping("/monitor") @RequestMapping("/monitor")
public class HistoryDataController { public class HistoryDataController {
@RequestMapping("/history") @RequestMapping("/history")
@ResponseBody ListMainModel getHistory(@RequestParam String starttime, @RequestParam String endtime) throws ParseException @ResponseBody ListMainModel getHistory(@RequestParam String starttime, @RequestParam String endtime) throws ParseException
{ {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")); dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
Date startDate = dateFormat.parse(starttime); Date startDate = dateFormat.parse(starttime);
Date endDate = dateFormat.parse(endtime); Date endDate = dateFormat.parse(endtime);
ReadSystemInfoFromLocalDisk historyservice = new ReadSystemInfoFromLocalDisk(); ReadSystemInfoFromLocalDisk historyservice = new ReadSystemInfoFromLocalDisk();
ListMainModel retModel = new ListMainModel(); ListMainModel retModel = new ListMainModel();
//retModel.setHistorylist(historyservice.ReadSystemInfoByDate(startDate, endDate)); //retModel.setHistorylist(historyservice.ReadSystemInfoByDate(startDate, endDate));
retModel.setHistorylist(historyservice.ReadSystemInfoByDate(startDate, endDate)); retModel.setHistorylist(historyservice.ReadSystemInfoByDate(startDate, endDate));
return retModel; return retModel;
} }
} }

View File

@ -1,23 +1,23 @@
package org.bench4q.monitor.api; package org.bench4q.monitor.api;
import java.util.Date; 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;
import org.hyperic.sigar.SigarException; import org.hyperic.sigar.SigarException;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
@Controller @Controller
@RequestMapping("/monitor") @RequestMapping("/monitor")
public class MainController { 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(); Date date = new Date();
MonitorMain retModel = new MonitorMain(date); MonitorMain retModel = new MonitorMain(date);
return retModel; return retModel;
} }
} }

View File

@ -1,19 +1,19 @@
package org.bench4q.monitor.api; package org.bench4q.monitor.api;
import org.bench4q.monitor.model.MemoryModel; import org.bench4q.monitor.model.MemoryModel;
import org.hyperic.sigar.SigarException; import org.hyperic.sigar.SigarException;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
@Controller @Controller
@RequestMapping("/monitor") @RequestMapping("/monitor")
public class MemoryController { public class MemoryController {
@RequestMapping("/memory") @RequestMapping("/memory")
@ResponseBody @ResponseBody
MemoryModel getMemoryModel() throws SigarException MemoryModel getMemoryModel() throws SigarException
{ {
MemoryModel retModel = new MemoryModel(); MemoryModel retModel = new MemoryModel();
return retModel; return retModel;
} }
} }

View File

@ -1,18 +1,18 @@
package org.bench4q.monitor.api; package org.bench4q.monitor.api;
import org.bench4q.monitor.model.NetworkInterfaceModel; import org.bench4q.monitor.model.NetworkInterfaceModel;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
@Controller @Controller
@RequestMapping("/monitor") @RequestMapping("/monitor")
public class NetworkController { public class NetworkController {
@RequestMapping("/network") @RequestMapping("/network")
@ResponseBody NetworkInterfaceModel getNetworkInterfaceModel(){ @ResponseBody NetworkInterfaceModel getNetworkInterfaceModel(){
NetworkInterfaceModel retModel = new NetworkInterfaceModel(); NetworkInterfaceModel retModel = new NetworkInterfaceModel();
return retModel; return retModel;
} }
} }

View File

@ -1,38 +1,38 @@
package org.bench4q.monitor.api; package org.bench4q.monitor.api;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import org.bench4q.monitor.model.FileSystemModel; import org.bench4q.monitor.model.FileSystemModel;
import org.bench4q.monitor.model.PhysicalDiskModel; import org.bench4q.monitor.model.PhysicalDiskModel;
import org.hyperic.sigar.SigarException; import org.hyperic.sigar.SigarException;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
@Controller @Controller
@RequestMapping("/monitor") @RequestMapping("/monitor")
public class PhysicalDiskController { public class PhysicalDiskController {
@RequestMapping("/physicalDisk") @RequestMapping("/physicalDisk")
@ResponseBody @ResponseBody
PhysicalDiskModel getPhysicalDiskModel() throws SigarException, PhysicalDiskModel getPhysicalDiskModel() throws SigarException,
InterruptedException, ExecutionException { InterruptedException, ExecutionException {
PhysicalDiskModel retModel = new PhysicalDiskModel(); PhysicalDiskModel retModel = new PhysicalDiskModel();
return retModel; return retModel;
} }
@RequestMapping("/pshysicalDisk/{dir}") @RequestMapping("/pshysicalDisk/{dir}")
@ResponseBody @ResponseBody
public FileSystemModel getFileSystemModel(@PathVariable("dir") String dir) public FileSystemModel getFileSystemModel(@PathVariable("dir") String dir)
throws SigarException, InterruptedException, ExecutionException { throws SigarException, InterruptedException, ExecutionException {
PhysicalDiskModel physicalDiskModel = new PhysicalDiskModel(); PhysicalDiskModel physicalDiskModel = new PhysicalDiskModel();
if (physicalDiskModel.getFieFileSystemModels() != null) { if (physicalDiskModel.getFieFileSystemModels() != null) {
for (FileSystemModel fileSystemModel : physicalDiskModel for (FileSystemModel fileSystemModel : physicalDiskModel
.getFieFileSystemModels()) { .getFieFileSystemModels()) {
if (fileSystemModel.getFileDir().equals(dir)) if (fileSystemModel.getFileDir().equals(dir))
return fileSystemModel; return fileSystemModel;
} }
} }
throw new IllegalArgumentException("dir:" + dir + " not exit!"); throw new IllegalArgumentException("dir:" + dir + " not exit!");
} }
} }

View File

@ -1,37 +1,37 @@
package org.bench4q.monitor.api; package org.bench4q.monitor.api;
import org.bench4q.monitor.model.ProcessorModel; import org.bench4q.monitor.model.ProcessorModel;
import org.bench4q.monitor.model.ProcessorModelChild; import org.bench4q.monitor.model.ProcessorModelChild;
import org.hyperic.sigar.SigarException; import org.hyperic.sigar.SigarException;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
@Controller @Controller
@RequestMapping("/monitor") @RequestMapping("/monitor")
public class ProcessorController { public class ProcessorController {
@RequestMapping("/processor") @RequestMapping("/processor")
@ResponseBody @ResponseBody
ProcessorModel getResposeModel() throws SigarException { ProcessorModel getResposeModel() throws SigarException {
ProcessorModel retModel = new ProcessorModel(); ProcessorModel retModel = new ProcessorModel();
return retModel; return retModel;
} }
@RequestMapping("/processor/{instanceName}") @RequestMapping("/processor/{instanceName}")
@ResponseBody @ResponseBody
ProcessorModelChild getProcessorModelChild( ProcessorModelChild getProcessorModelChild(
@PathVariable("instanceName") String instanceName) throws SigarException { @PathVariable("instanceName") String instanceName) throws SigarException {
ProcessorModel processorModel = new ProcessorModel(); ProcessorModel processorModel = new ProcessorModel();
if (processorModel.getProcessorModelList() == null) if (processorModel.getProcessorModelList() == null)
throw new IllegalArgumentException(instanceName throw new IllegalArgumentException(instanceName
+ " not exsist,cpu instance is empty"); + " not exsist,cpu instance is empty");
for (ProcessorModelChild processorModelChild : processorModel for (ProcessorModelChild processorModelChild : processorModel
.getProcessorModelList()) { .getProcessorModelList()) {
if (processorModelChild.getInstance().equals(instanceName)) if (processorModelChild.getInstance().equals(instanceName))
return processorModelChild; return processorModelChild;
} }
throw new IllegalArgumentException(instanceName + " not exsist"); throw new IllegalArgumentException(instanceName + " not exsist");
} }
} }

View File

@ -1,29 +1,29 @@
package org.bench4q.monitor.api; package org.bench4q.monitor.api;
import java.util.Timer; import java.util.Timer;
import org.bench4q.monitor.service.TimerService; import org.bench4q.monitor.service.TimerService;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
@Controller @Controller
@RequestMapping("/monitor") @RequestMapping("/monitor")
public class StartToRecord { public class StartToRecord {
private Timer timer = new Timer(); private Timer timer = new Timer();
@RequestMapping("/start") @RequestMapping("/start")
@ResponseBody @ResponseBody
public String start() { public String start() {
timer.schedule(new TimerService(), 1000, 2000); timer.schedule(new TimerService(), 1000, 2000);
return new String("startted"); return new String("startted");
} }
@RequestMapping("/stop") @RequestMapping("/stop")
@ResponseBody @ResponseBody
public String stop() { public String stop() {
timer.cancel(); timer.cancel();
return new String("stopped"); return new String("stopped");
} }
} }

View File

@ -1,32 +1,32 @@
package org.bench4q.monitor.exception; package org.bench4q.monitor.exception;
public class MonitorException { public class MonitorException {
private String errorCode; private String errorCode;
private String message; private String message;
private String cause; private String cause;
public String getErrorCode() { public String getErrorCode() {
return errorCode; return errorCode;
} }
public void setErrorCode(String errorCode) { public void setErrorCode(String errorCode) {
this.errorCode = errorCode; this.errorCode = errorCode;
} }
public String getMessage() { public String getMessage() {
return message; return message;
} }
public void setMessage(String message) { public void setMessage(String message) {
this.message = message; this.message = message;
} }
public String getCause() { public String getCause() {
return cause; return cause;
} }
public void setCause(String cause) { public void setCause(String cause) {
this.cause = cause; this.cause = cause;
} }
} }

View File

@ -1,223 +1,223 @@
package org.bench4q.monitor.model; package org.bench4q.monitor.model;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
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 org.bench4q.monitor.service.DataFomat; import org.bench4q.monitor.service.DataFomat;
import org.bench4q.monitor.service.GetSigar; import org.bench4q.monitor.service.GetSigar;
import org.hyperic.sigar.FileSystemUsage; import org.hyperic.sigar.FileSystemUsage;
import org.hyperic.sigar.SigarException; import org.hyperic.sigar.SigarException;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
@XmlRootElement(name = "fileSystem") @XmlRootElement(name = "fileSystem")
public class FileSystemModel { public class FileSystemModel {
@Expose @Expose
private String fileDir; private String fileDir;
@Expose @Expose
private Double diskReadKBytesRate; private Double diskReadKBytesRate;
@Expose @Expose
private Double diskWriteKBytesRate; private Double diskWriteKBytesRate;
@Expose @Expose
private double curDiskQueLength; private double curDiskQueLength;
@Expose @Expose
private double totalGB; private double totalGB;
@Expose @Expose
private double usedGB; private double usedGB;
@Expose @Expose
private double freeGB; private double freeGB;
@Expose @Expose
private double usedPercent; private double usedPercent;
@Expose @Expose
private double diskTotalKBytesRate; private double diskTotalKBytesRate;
private FileSystemUsage fileSystemUsage; private FileSystemUsage fileSystemUsage;
public static void main(String args[]) throws SigarException, public static void main(String args[]) throws SigarException,
InterruptedException, ExecutionException { InterruptedException, ExecutionException {
FileSystemUsage fileSystemUsage = GetSigar FileSystemUsage fileSystemUsage = GetSigar
.getSigar() .getSigar()
.getFileSystemUsage( .getFileSystemUsage(
GetSigar.getSigar().getFileSystemList()[0].getDirName()); GetSigar.getSigar().getFileSystemList()[0].getDirName());
FileSystemModel fileSystemModel = new FileSystemModel(fileSystemUsage, FileSystemModel fileSystemModel = new FileSystemModel(fileSystemUsage,
GetSigar.getSigar().getFileSystemList()[0].getDirName(), 500); GetSigar.getSigar().getFileSystemList()[0].getDirName(), 500);
System.out.println(fileSystemModel.getFreeGB()); System.out.println(fileSystemModel.getFreeGB());
System.out.println(fileSystemModel.getTotalGB()); System.out.println(fileSystemModel.getTotalGB());
System.out.println(fileSystemModel.getDiskReadKBytesRate()); System.out.println(fileSystemModel.getDiskReadKBytesRate());
} }
public FileSystemModel() { public FileSystemModel() {
} }
public FileSystemModel(FileSystemUsage fileSystemUsage, String fileDir, public FileSystemModel(FileSystemUsage fileSystemUsage, String fileDir,
int interval) throws InterruptedException, ExecutionException { int interval) throws InterruptedException, ExecutionException {
this.fileDir = fileDir; this.fileDir = fileDir;
this.fileSystemUsage = fileSystemUsage; this.fileSystemUsage = fileSystemUsage;
ExecutorService executorService = Executors.newFixedThreadPool(2); ExecutorService executorService = Executors.newFixedThreadPool(2);
Future<Double> caculateReadRateFuture = executorService Future<Double> caculateReadRateFuture = executorService
.submit(new CalculateDiskReadRate(interval, fileSystemUsage)); .submit(new CalculateDiskReadRate(interval, fileSystemUsage));
Future<Double> caculateWriteRateFuture = executorService Future<Double> caculateWriteRateFuture = executorService
.submit(new CalculateDiskWriteRate(interval, fileSystemUsage)); .submit(new CalculateDiskWriteRate(interval, fileSystemUsage));
this.setCurDiskQueLength(); this.setCurDiskQueLength();
this.setFreeGB(); this.setFreeGB();
this.setTotalGB(); this.setTotalGB();
this.setUsedGB(); this.setUsedGB();
this.setUsedPercent(); this.setUsedPercent();
this.setDiskReadKBytesRate(caculateReadRateFuture.get()); this.setDiskReadKBytesRate(caculateReadRateFuture.get());
this.setDiskWriteKBytesRate(caculateWriteRateFuture.get()); this.setDiskWriteKBytesRate(caculateWriteRateFuture.get());
this.setDiskTotalKBytesRate(); this.setDiskTotalKBytesRate();
this.setCurDiskQueLength(); this.setCurDiskQueLength();
executorService.shutdown(); executorService.shutdown();
} }
@XmlElement @XmlElement
public String getFileDir() { public String getFileDir() {
return fileDir; return fileDir;
} }
@XmlElement @XmlElement
public Double getDiskReadKBytesRate() { public Double getDiskReadKBytesRate() {
return diskReadKBytesRate; return diskReadKBytesRate;
} }
private void setDiskReadKBytesRate(Double diskReadKBytesRate) { private void setDiskReadKBytesRate(Double diskReadKBytesRate) {
this.diskReadKBytesRate = diskReadKBytesRate; this.diskReadKBytesRate = diskReadKBytesRate;
} }
@XmlElement @XmlElement
public Double getDiskWriteKBytesRate() { public Double getDiskWriteKBytesRate() {
return diskWriteKBytesRate; return diskWriteKBytesRate;
} }
private void setDiskWriteKBytesRate(Double diskWriteKBytesRate) { private void setDiskWriteKBytesRate(Double diskWriteKBytesRate) {
this.diskWriteKBytesRate = diskWriteKBytesRate; this.diskWriteKBytesRate = diskWriteKBytesRate;
} }
@XmlElement @XmlElement
public double getCurDiskQueLength() { public double getCurDiskQueLength() {
return curDiskQueLength; return curDiskQueLength;
} }
private void setCurDiskQueLength() { private void setCurDiskQueLength() {
this.curDiskQueLength = this.fileSystemUsage.getDiskQueue(); this.curDiskQueLength = this.fileSystemUsage.getDiskQueue();
} }
@XmlElement @XmlElement
public double getTotalGB() { public double getTotalGB() {
return totalGB; return totalGB;
} }
private void setTotalGB() { private void setTotalGB() {
this.totalGB = changeBytesToGB(this.fileSystemUsage.getTotal()); this.totalGB = changeBytesToGB(this.fileSystemUsage.getTotal());
} }
@XmlElement @XmlElement
public double getUsedGB() { public double getUsedGB() {
return usedGB; return usedGB;
} }
private void setUsedGB() { private void setUsedGB() {
this.usedGB = changeBytesToGB(this.fileSystemUsage.getUsed()); this.usedGB = changeBytesToGB(this.fileSystemUsage.getUsed());
} }
@XmlElement @XmlElement
public double getFreeGB() { public double getFreeGB() {
return freeGB; return freeGB;
} }
private void setFreeGB() { private void setFreeGB() {
this.freeGB = changeBytesToGB(this.fileSystemUsage.getFree()); this.freeGB = changeBytesToGB(this.fileSystemUsage.getFree());
} }
@XmlElement @XmlElement
public double getUsedPercent() { public double getUsedPercent() {
return usedPercent; return usedPercent;
} }
private void setUsedPercent() { private void setUsedPercent() {
this.usedPercent = DataFomat.fomatToPercent(fileSystemUsage this.usedPercent = DataFomat.fomatToPercent(fileSystemUsage
.getUsePercent()); .getUsePercent());
} }
@XmlElement @XmlElement
public double getDiskTotalKBytesRate() { public double getDiskTotalKBytesRate() {
return diskTotalKBytesRate; return diskTotalKBytesRate;
} }
private void setDiskTotalKBytesRate() { private void setDiskTotalKBytesRate() {
this.diskTotalKBytesRate = this.getDiskReadKBytesRate() this.diskTotalKBytesRate = this.getDiskReadKBytesRate()
+ this.getDiskWriteKBytesRate(); + this.getDiskWriteKBytesRate();
} }
private double changeBytesToGB(long bytes) { private double changeBytesToGB(long bytes) {
return (double) Math.round(((double) bytes / 1024 / 1024) * 100) / 100; return (double) Math.round(((double) bytes / 1024 / 1024) * 100) / 100;
} }
} }
abstract class CalculateDiskRate implements Callable<Double> { abstract class CalculateDiskRate implements Callable<Double> {
private long interval; private long interval;
private Double KBytesRate; private Double KBytesRate;
protected FileSystemUsage fileSystemUsage; protected FileSystemUsage fileSystemUsage;
public CalculateDiskRate(long interval, FileSystemUsage fileSystemUsage) { public CalculateDiskRate(long interval, FileSystemUsage fileSystemUsage) {
this.interval = interval; this.interval = interval;
this.fileSystemUsage = fileSystemUsage; this.fileSystemUsage = fileSystemUsage;
} }
public Double call() throws InterruptedException, SigarException { public Double call() throws InterruptedException, SigarException {
long preDiskKBytes = getFileKBytes(); long preDiskKBytes = getFileKBytes();
long postDiskKBytes = 0; long postDiskKBytes = 0;
long startTime = System.nanoTime(); long startTime = System.nanoTime();
long endTime = 0; long endTime = 0;
Thread.sleep(this.interval); Thread.sleep(this.interval);
postDiskKBytes = getFileKBytes(); postDiskKBytes = getFileKBytes();
endTime = System.nanoTime(); endTime = System.nanoTime();
this.KBytesRate = new Double( this.KBytesRate = new Double(
Math.round((postDiskKBytes - preDiskKBytes) Math.round((postDiskKBytes - preDiskKBytes)
/ DataFomat.caculateTimeInterval(startTime, endTime) / DataFomat.caculateTimeInterval(startTime, endTime)
* 10000) / 10000); * 10000) / 10000);
return this.KBytesRate; return this.KBytesRate;
} }
abstract long getFileKBytes() throws SigarException; abstract long getFileKBytes() throws SigarException;
} }
class CalculateDiskWriteRate extends CalculateDiskRate { class CalculateDiskWriteRate extends CalculateDiskRate {
public CalculateDiskWriteRate(long interval, FileSystemUsage fileSystemUsage) { public CalculateDiskWriteRate(long interval, FileSystemUsage fileSystemUsage) {
super(interval, fileSystemUsage); super(interval, fileSystemUsage);
} }
long getFileKBytes() throws SigarException { long getFileKBytes() throws SigarException {
return fileSystemUsage.getDiskWriteBytes() / 1024L; return fileSystemUsage.getDiskWriteBytes() / 1024L;
} }
} }
class CalculateDiskReadRate extends CalculateDiskRate { class CalculateDiskReadRate extends CalculateDiskRate {
public CalculateDiskReadRate(long interval, public CalculateDiskReadRate(long interval,
FileSystemUsage feFileSystemUsage) { FileSystemUsage feFileSystemUsage) {
super(interval, feFileSystemUsage); super(interval, feFileSystemUsage);
} }
long getFileKBytes() throws SigarException { long getFileKBytes() throws SigarException {
return fileSystemUsage.getDiskReadBytes() / 1024L; return fileSystemUsage.getDiskReadBytes() / 1024L;
} }
} }

View File

@ -1,22 +1,22 @@
package org.bench4q.monitor.model; package org.bench4q.monitor.model;
import java.util.List; import java.util.List;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name="historylist") @XmlRootElement(name="historylist")
public class ListMainModel { public class ListMainModel {
private List<MonitorMain> historylist; private List<MonitorMain> historylist;
@XmlElementWrapper(name="histories") @XmlElementWrapper(name="histories")
@XmlElement(name="history",type=MonitorMain.class) @XmlElement(name="history",type=MonitorMain.class)
public List<MonitorMain> getHistorylist() { public List<MonitorMain> getHistorylist() {
return historylist; return historylist;
} }
public void setHistorylist(List<MonitorMain> historylist) { public void setHistorylist(List<MonitorMain> historylist) {
this.historylist = historylist; this.historylist = historylist;
} }
} }

View File

@ -1,172 +1,172 @@
package org.bench4q.monitor.model; package org.bench4q.monitor.model;
import java.beans.Transient; import java.beans.Transient;
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 org.bench4q.monitor.service.GetSigar; import org.bench4q.monitor.service.GetSigar;
import org.hyperic.sigar.SigarException; import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.Swap; import org.hyperic.sigar.Swap;
import org.hyperic.sigar.Sigar; import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.Mem; import org.hyperic.sigar.Mem;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
@XmlRootElement(name = "Memory") @XmlRootElement(name = "Memory")
public class MemoryModel { public class MemoryModel {
@Expose @Expose
private long pagesPerSecond; private long pagesPerSecond;
@Expose @Expose
private long pagesInputPerSecond; private long pagesInputPerSecond;
@Expose @Expose
private long pagesOutputPerSecond; private long pagesOutputPerSecond;
@Expose @Expose
private long availableKiloBytes; private long availableKiloBytes;
@Expose @Expose
private long totalKiloBytes; private long totalKiloBytes;
@Expose @Expose
private double memoryUsedPercent; private double memoryUsedPercent;
@Expose @Expose
private double swapKiloBytes; private double swapKiloBytes;
@Expose @Expose
private double swapFreeKiloBytes; private double swapFreeKiloBytes;
private Sigar sigar = GetSigar.getSigar(); private Sigar sigar = GetSigar.getSigar();
private Swap swap; private Swap swap;
private Mem mem; private Mem mem;
public static void main(String[] args) throws SigarException { public static void main(String[] args) throws SigarException {
MemoryModel model = new MemoryModel(); MemoryModel model = new MemoryModel();
System.out.println("PagesRate: " + model.getPagesPerSecond()); System.out.println("PagesRate: " + model.getPagesPerSecond());
System.out.println("PagesIn: " + model.getPagesInputPerSecond()); System.out.println("PagesIn: " + model.getPagesInputPerSecond());
System.out.println("PagesIn: " + model.getPagesOutputPerSecond()); System.out.println("PagesIn: " + model.getPagesOutputPerSecond());
System.out.println("UsedPerc: " + model.getMemoryUsedPercent() + "%"); System.out.println("UsedPerc: " + model.getMemoryUsedPercent() + "%");
System.out.println("Total: " + model.getTotalKiloBytes() + "kb"); System.out.println("Total: " + model.getTotalKiloBytes() + "kb");
System.out.println("Aval: " + model.getAvailableKiloBytes() + "kb"); System.out.println("Aval: " + model.getAvailableKiloBytes() + "kb");
System.out.println("swap total:" + model.getSwapKiloBytes() + "kb"); System.out.println("swap total:" + model.getSwapKiloBytes() + "kb");
System.out.println("swap free :" + model.getSwapFreeKiloBytes() + "kb"); System.out.println("swap free :" + model.getSwapFreeKiloBytes() + "kb");
} }
public MemoryModel() throws SigarException { public MemoryModel() throws SigarException {
this.getPagesInputPerSecond(); this.getPagesInputPerSecond();
this.getPagesOutputPerSecond(); this.getPagesOutputPerSecond();
this.getPagesPerSecond(); this.getPagesPerSecond();
this.getMemoryUsedPercent(); this.getMemoryUsedPercent();
this.getAvailableKiloBytes(); this.getAvailableKiloBytes();
this.getTotalKiloBytes(); this.getTotalKiloBytes();
this.setSwapKiloBytes(); this.setSwapKiloBytes();
this.setSwapFreeKiloBytes(); this.setSwapFreeKiloBytes();
} }
@XmlElement @XmlElement
public long getPagesPerSecond() throws SigarException { public long getPagesPerSecond() throws SigarException {
setPagesPerSecond(getPagesInputPerSecond() + getPagesOutputPerSecond()); setPagesPerSecond(getPagesInputPerSecond() + getPagesOutputPerSecond());
return pagesPerSecond; return pagesPerSecond;
} }
private void setPagesPerSecond(long pagesPerSecond) { private void setPagesPerSecond(long pagesPerSecond) {
this.pagesPerSecond = pagesPerSecond; this.pagesPerSecond = pagesPerSecond;
} }
@XmlElement @XmlElement
public long getPagesInputPerSecond() throws SigarException { public long getPagesInputPerSecond() throws SigarException {
swap = sigar.getSwap(); swap = sigar.getSwap();
setPagesInputPerSecond(swap.getPageIn()); setPagesInputPerSecond(swap.getPageIn());
return pagesInputPerSecond; return pagesInputPerSecond;
} }
private void setPagesInputPerSecond(long pagesInputPerSecond) { private void setPagesInputPerSecond(long pagesInputPerSecond) {
this.pagesInputPerSecond = pagesInputPerSecond; this.pagesInputPerSecond = pagesInputPerSecond;
} }
@XmlElement @XmlElement
public long getPagesOutputPerSecond() throws SigarException { public long getPagesOutputPerSecond() throws SigarException {
swap = sigar.getSwap(); swap = sigar.getSwap();
setPagesOutputPerSecond(swap.getPageOut()); setPagesOutputPerSecond(swap.getPageOut());
return pagesOutputPerSecond; return pagesOutputPerSecond;
} }
private void setPagesOutputPerSecond(long pagesOutputPerSecond) { private void setPagesOutputPerSecond(long pagesOutputPerSecond) {
this.pagesOutputPerSecond = pagesOutputPerSecond; this.pagesOutputPerSecond = pagesOutputPerSecond;
} }
@XmlElement @XmlElement
public long getAvailableKiloBytes() throws SigarException { public long getAvailableKiloBytes() throws SigarException {
mem = sigar.getMem(); mem = sigar.getMem();
setAvailableKiloBytes(mem.getActualFree() / 1024L); setAvailableKiloBytes(mem.getActualFree() / 1024L);
return availableKiloBytes; return availableKiloBytes;
} }
private void setAvailableKiloBytes(long availableKiloBytes) { private void setAvailableKiloBytes(long availableKiloBytes) {
this.availableKiloBytes = availableKiloBytes; this.availableKiloBytes = availableKiloBytes;
} }
@XmlElement @XmlElement
public long getTotalKiloBytes() throws SigarException { public long getTotalKiloBytes() throws SigarException {
mem = sigar.getMem(); mem = sigar.getMem();
setTotalKiloBytes(mem.getTotal() / 1024L); setTotalKiloBytes(mem.getTotal() / 1024L);
return totalKiloBytes; return totalKiloBytes;
} }
private void setTotalKiloBytes(long totalKiloBytes) { private void setTotalKiloBytes(long totalKiloBytes) {
this.totalKiloBytes = totalKiloBytes; this.totalKiloBytes = totalKiloBytes;
} }
@XmlElement @XmlElement
public double getMemoryUsedPercent() throws SigarException { public double getMemoryUsedPercent() throws SigarException {
mem = sigar.getMem(); mem = sigar.getMem();
long temp = Math.round(mem.getUsedPercent() * 100); long temp = Math.round(mem.getUsedPercent() * 100);
setMemoryUsedPercent(temp / 100.0); setMemoryUsedPercent(temp / 100.0);
return this.memoryUsedPercent; return this.memoryUsedPercent;
} }
private void setMemoryUsedPercent(double memoryUsedPercent) { private void setMemoryUsedPercent(double memoryUsedPercent) {
this.memoryUsedPercent = memoryUsedPercent; this.memoryUsedPercent = memoryUsedPercent;
} }
@XmlElement @XmlElement
public double getSwapKiloBytes() { public double getSwapKiloBytes() {
return swapKiloBytes; return swapKiloBytes;
} }
private void setSwapKiloBytes() { private void setSwapKiloBytes() {
this.swapKiloBytes = this.swap.getTotal() / 1024L; this.swapKiloBytes = this.swap.getTotal() / 1024L;
} }
@XmlElement @XmlElement
public double getSwapFreeKiloBytes() { public double getSwapFreeKiloBytes() {
return swapFreeKiloBytes; return swapFreeKiloBytes;
} }
private void setSwapFreeKiloBytes() { private void setSwapFreeKiloBytes() {
this.swapFreeKiloBytes = this.swap.getFree() / 1024L; this.swapFreeKiloBytes = this.swap.getFree() / 1024L;
} }
@Transient @Transient
public Sigar getSigar() { public Sigar getSigar() {
return sigar; return sigar;
} }
public void setSigar(Sigar sigar) { public void setSigar(Sigar sigar) {
this.sigar = sigar; this.sigar = sigar;
} }
@Transient @Transient
public Swap getSwap() { public Swap getSwap() {
return swap; return swap;
} }
public void setSwap(Swap swap) { public void setSwap(Swap swap) {
this.swap = swap; this.swap = swap;
} }
@Transient @Transient
public Mem getMem() { public Mem getMem() {
return mem; return mem;
} }
public void setMem(Mem mem) { public void setMem(Mem mem) {
this.mem = mem; this.mem = mem;
} }
} }

View File

@ -1,191 +1,191 @@
package org.bench4q.monitor.model; package org.bench4q.monitor.model;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
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 org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.bench4q.monitor.service.DataFomat; import org.bench4q.monitor.service.DataFomat;
import org.bench4q.monitor.service.GetSigar; import org.bench4q.monitor.service.GetSigar;
import org.hyperic.sigar.SigarException; import org.hyperic.sigar.SigarException;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
@XmlRootElement(name = "NetworkInterface") @XmlRootElement(name = "NetworkInterface")
public class NetworkInterfaceModel implements Runnable { public class NetworkInterfaceModel implements Runnable {
@Expose @Expose
private Double kiloBytesTotalPerSecond; private Double kiloBytesTotalPerSecond;
@Expose @Expose
private Double kiloBytesReceivedPerSecond; private Double kiloBytesReceivedPerSecond;
@Expose @Expose
private Double kiloBytesSentPerSecond; private Double kiloBytesSentPerSecond;
private long interval = 500; private long interval = 500;
/* private Logger logger = Logger.getLogger(NetworkInterfaceModel.class); */ /* private Logger logger = Logger.getLogger(NetworkInterfaceModel.class); */
public static void main(String[] args) { public static void main(String[] args) {
while (true) { while (true) {
long Time = System.currentTimeMillis(); long Time = System.currentTimeMillis();
NetworkInterfaceModel test = new NetworkInterfaceModel(); NetworkInterfaceModel test = new NetworkInterfaceModel();
System.out.println("KiloBytesReceivedPerSecond:" System.out.println("KiloBytesReceivedPerSecond:"
+ test.getKiloBytesReceivedPerSecond() + "kb/s"); + test.getKiloBytesReceivedPerSecond() + "kb/s");
System.out.println("KiloBytesSentPerSecond:" System.out.println("KiloBytesSentPerSecond:"
+ test.getKiloBytesSentPerSecond() + "kb/s"); + test.getKiloBytesSentPerSecond() + "kb/s");
System.out.println("KiloBytesTotalPerSecond:" System.out.println("KiloBytesTotalPerSecond:"
+ test.getKiloBytesTotalPerSecond() + "kb/s"); + test.getKiloBytesTotalPerSecond() + "kb/s");
System.out.println(System.currentTimeMillis() - Time); System.out.println(System.currentTimeMillis() - Time);
} }
} }
private MonitorMain monitorMain; private MonitorMain monitorMain;
public NetworkInterfaceModel(MonitorMain monitorMain) { public NetworkInterfaceModel(MonitorMain monitorMain) {
this.monitorMain = monitorMain; this.monitorMain = monitorMain;
} }
public void run() { public void run() {
monitorMain.setNetworkInterfaceModel(new NetworkInterfaceModel()); monitorMain.setNetworkInterfaceModel(new NetworkInterfaceModel());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public NetworkInterfaceModel() { public NetworkInterfaceModel() {
// this can be used for all // this can be used for all
ExecutorService executorService = Executors.newFixedThreadPool(2); ExecutorService executorService = Executors.newFixedThreadPool(2);
Future<Double> futureBytesReceivedPerSecond = executorService Future<Double> futureBytesReceivedPerSecond = executorService
.submit(new CalculateBytesReceivedPerSecond(interval)); .submit(new CalculateBytesReceivedPerSecond(interval));
Future<Double> futureBytesSentPerSecond = executorService Future<Double> futureBytesSentPerSecond = executorService
.submit(new CalculateBytesSentPerSecond(interval)); .submit(new CalculateBytesSentPerSecond(interval));
try { try {
this.setKiloBytesReceivedPerSecond(futureBytesReceivedPerSecond this.setKiloBytesReceivedPerSecond(futureBytesReceivedPerSecond
.get()); .get());
this.setKiloBytesSentPerSecond(futureBytesSentPerSecond.get()); this.setKiloBytesSentPerSecond(futureBytesSentPerSecond.get());
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} catch (ExecutionException e) { } catch (ExecutionException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
executorService.shutdown(); executorService.shutdown();
} }
} }
@XmlElement @XmlElement
public Double getKiloBytesReceivedPerSecond() { public Double getKiloBytesReceivedPerSecond() {
return this.kiloBytesReceivedPerSecond; return this.kiloBytesReceivedPerSecond;
} }
public void setKiloBytesReceivedPerSecond(Double kiloBytesReceivedPerSecond) { public void setKiloBytesReceivedPerSecond(Double kiloBytesReceivedPerSecond) {
this.kiloBytesReceivedPerSecond = kiloBytesReceivedPerSecond; this.kiloBytesReceivedPerSecond = kiloBytesReceivedPerSecond;
} }
@XmlElement @XmlElement
public Double getKiloBytesSentPerSecond() { public Double getKiloBytesSentPerSecond() {
return this.kiloBytesSentPerSecond; return this.kiloBytesSentPerSecond;
} }
public void setKiloBytesSentPerSecond(Double kiloBytesSentPerSecond) { public void setKiloBytesSentPerSecond(Double kiloBytesSentPerSecond) {
this.kiloBytesSentPerSecond = kiloBytesSentPerSecond; this.kiloBytesSentPerSecond = kiloBytesSentPerSecond;
} }
@XmlElement @XmlElement
public Double getKiloBytesTotalPerSecond() { public Double getKiloBytesTotalPerSecond() {
setKiloBytesTotalPerSecond(this.kiloBytesReceivedPerSecond setKiloBytesTotalPerSecond(this.kiloBytesReceivedPerSecond
+ this.kiloBytesSentPerSecond); + this.kiloBytesSentPerSecond);
return kiloBytesTotalPerSecond; return kiloBytesTotalPerSecond;
} }
public void setKiloBytesTotalPerSecond(Double kiloBytesTotalPerSecond) { public void setKiloBytesTotalPerSecond(Double kiloBytesTotalPerSecond) {
this.kiloBytesTotalPerSecond = kiloBytesTotalPerSecond; this.kiloBytesTotalPerSecond = kiloBytesTotalPerSecond;
} }
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
abstract class CalculateBytesPerSecond implements Callable { abstract class CalculateBytesPerSecond implements Callable {
private long interval; private long interval;
private Logger logger = Logger private Logger logger = Logger
.getLogger(CalculateBytesReceivedPerSecond.class); .getLogger(CalculateBytesReceivedPerSecond.class);
private Double kiloBytesPerSecond; private Double kiloBytesPerSecond;
public CalculateBytesPerSecond(long interval) { public CalculateBytesPerSecond(long interval) {
this.interval = interval; this.interval = interval;
} }
public double getKiloBytesPerSecond() { public double getKiloBytesPerSecond() {
return kiloBytesPerSecond; return kiloBytesPerSecond;
} }
public Double call() { public Double call() {
try { try {
long startTime = System.nanoTime(); long startTime = System.nanoTime();
long endTime; long endTime;
long preBytesSentSoFar = this.getBytesSoFar(); long preBytesSentSoFar = this.getBytesSoFar();
long postBytesSentSoFar = 0; long postBytesSentSoFar = 0;
Thread.sleep(interval); Thread.sleep(interval);
endTime = System.nanoTime(); endTime = System.nanoTime();
postBytesSentSoFar = this.getBytesSoFar(); postBytesSentSoFar = this.getBytesSoFar();
this.kiloBytesPerSecond = (double) ((postBytesSentSoFar - preBytesSentSoFar) this.kiloBytesPerSecond = (double) ((postBytesSentSoFar - preBytesSentSoFar)
/ DataFomat.caculateTimeInterval(startTime, endTime) / 1024L); / DataFomat.caculateTimeInterval(startTime, endTime) / 1024L);
return new Double(Math.round(this.kiloBytesPerSecond * 100) / 100); return new Double(Math.round(this.kiloBytesPerSecond * 100) / 100);
} catch (SigarException e) { } catch (SigarException e) {
logger.error(e, e.fillInStackTrace()); logger.error(e, e.fillInStackTrace());
return new Double(0); return new Double(0);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// TODO: handle exception // TODO: handle exception
logger.error(e, e.fillInStackTrace()); logger.error(e, e.fillInStackTrace());
return new Double(0); return new Double(0);
} }
} }
abstract long getBytesSoFar() throws SigarException; abstract long getBytesSoFar() throws SigarException;
} }
class CalculateBytesSentPerSecond extends CalculateBytesPerSecond { class CalculateBytesSentPerSecond extends CalculateBytesPerSecond {
public CalculateBytesSentPerSecond(long interval) { public CalculateBytesSentPerSecond(long interval) {
super(interval); super(interval);
} }
public double getKiloBytesSentPerSecond() { public double getKiloBytesSentPerSecond() {
return this.getKiloBytesPerSecond(); return this.getKiloBytesPerSecond();
} }
long getBytesSoFar() throws SigarException { long getBytesSoFar() throws SigarException {
long bytesPostSoFar = 0; long bytesPostSoFar = 0;
String[] netInterfaceList = GetSigar.getSigar().getNetInterfaceList(); String[] netInterfaceList = GetSigar.getSigar().getNetInterfaceList();
for (int i = 0; i < netInterfaceList.length; ++i) for (int i = 0; i < netInterfaceList.length; ++i)
bytesPostSoFar += GetSigar.getSigar() bytesPostSoFar += GetSigar.getSigar()
.getNetInterfaceStat(netInterfaceList[i]).getTxBytes(); .getNetInterfaceStat(netInterfaceList[i]).getTxBytes();
return bytesPostSoFar; return bytesPostSoFar;
} }
} }
class CalculateBytesReceivedPerSecond extends CalculateBytesPerSecond { class CalculateBytesReceivedPerSecond extends CalculateBytesPerSecond {
public CalculateBytesReceivedPerSecond(long interval) { public CalculateBytesReceivedPerSecond(long interval) {
super(interval); super(interval);
} }
public double getKiloBytesReceivedPerSecond() { public double getKiloBytesReceivedPerSecond() {
return this.getKiloBytesPerSecond(); return this.getKiloBytesPerSecond();
} }
long getBytesSoFar() throws SigarException { long getBytesSoFar() throws SigarException {
long bytesReceivedSoFar = 0; long bytesReceivedSoFar = 0;
String[] netInterfaceList = GetSigar.getSigar().getNetInterfaceList(); String[] netInterfaceList = GetSigar.getSigar().getNetInterfaceList();
for (int i = 0; i < netInterfaceList.length; ++i) for (int i = 0; i < netInterfaceList.length; ++i)
bytesReceivedSoFar += GetSigar.getSigar() bytesReceivedSoFar += GetSigar.getSigar()
.getNetInterfaceStat(netInterfaceList[i]).getRxBytes(); .getNetInterfaceStat(netInterfaceList[i]).getRxBytes();
return bytesReceivedSoFar; return bytesReceivedSoFar;
} }
} }

View File

@ -1,271 +1,271 @@
package org.bench4q.monitor.model; package org.bench4q.monitor.model;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.bench4q.monitor.service.GetSigar; import org.bench4q.monitor.service.GetSigar;
import org.bench4q.monitor.service.GetThreadPool; import org.bench4q.monitor.service.GetThreadPool;
import org.hyperic.sigar.Sigar; import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.FileSystem; import org.hyperic.sigar.FileSystem;
import org.hyperic.sigar.FileSystemUsage; import org.hyperic.sigar.FileSystemUsage;
import org.hyperic.sigar.SigarException; import org.hyperic.sigar.SigarException;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
@XmlRootElement @XmlRootElement
public class PhysicalDiskModel implements Runnable{ public class PhysicalDiskModel implements Runnable{
@Expose @Expose
private Double diskReadKBytesRate; private Double diskReadKBytesRate;
@Expose @Expose
private Double diskWriteKBytesRate; private Double diskWriteKBytesRate;
@Expose @Expose
private double curDiskQueLength; private double curDiskQueLength;
@Expose @Expose
private double totalGB; private double totalGB;
@Expose @Expose
private double usedGB; private double usedGB;
@Expose @Expose
private double freeGB; private double freeGB;
@Expose @Expose
private double usedPercent; private double usedPercent;
@Expose @Expose
private List<FileSystemModel> fieFileSystemModels; private List<FileSystemModel> fieFileSystemModels;
private Sigar sigar = GetSigar.getSigar(); private Sigar sigar = GetSigar.getSigar();
private FileSystem[] fileSystemList; private FileSystem[] fileSystemList;
private final int interval = 500; private final int interval = 500;
private MonitorMain monitorMain; private MonitorMain monitorMain;
private Logger logger = Logger.getLogger(PhysicalDiskModel.class); private Logger logger = Logger.getLogger(PhysicalDiskModel.class);
public static void main(String[] args) throws SigarException, public static void main(String[] args) throws SigarException,
InterruptedException, ExecutionException { InterruptedException, ExecutionException {
PhysicalDiskModel physicalDiskModel = new PhysicalDiskModel(); PhysicalDiskModel physicalDiskModel = new PhysicalDiskModel();
System.out.println("queue length:" System.out.println("queue length:"
+ physicalDiskModel.getCurDiskQueLength()); + physicalDiskModel.getCurDiskQueLength());
System.out.println("read rate: " System.out.println("read rate: "
+ physicalDiskModel.getDiskReadKBytesRate()); + physicalDiskModel.getDiskReadKBytesRate());
System.out.println("write rate: " System.out.println("write rate: "
+ physicalDiskModel.getDiskWriteKBytesRate()); + physicalDiskModel.getDiskWriteKBytesRate());
System.out System.out
.println("used percent:" + physicalDiskModel.getUsedPercent()); .println("used percent:" + physicalDiskModel.getUsedPercent());
System.out.println("total:" + physicalDiskModel.getTotalGB()); System.out.println("total:" + physicalDiskModel.getTotalGB());
} }
public PhysicalDiskModel(MonitorMain monitorMain) { public PhysicalDiskModel(MonitorMain monitorMain) {
this.monitorMain = monitorMain; this.monitorMain = monitorMain;
} }
public void run() { public void run() {
try { try {
monitorMain.setPhysicalDiskModel(new PhysicalDiskModel()); monitorMain.setPhysicalDiskModel(new PhysicalDiskModel());
} catch (SigarException e) { } catch (SigarException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
logger.info(e, e.fillInStackTrace()); logger.info(e, e.fillInStackTrace());
} catch (InterruptedException e) { } catch (InterruptedException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
logger.info(e, e.fillInStackTrace()); logger.info(e, e.fillInStackTrace());
} catch (ExecutionException e) { } catch (ExecutionException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
logger.info(e, e.fillInStackTrace()); logger.info(e, e.fillInStackTrace());
} }
} }
public PhysicalDiskModel() throws SigarException, InterruptedException, public PhysicalDiskModel() throws SigarException, InterruptedException,
ExecutionException { ExecutionException {
this.setFileSystemList(); this.setFileSystemList();
this.setFieFileSystemModels(); this.setFieFileSystemModels();
this.setCurDiskQueLength(); this.setCurDiskQueLength();
this.setDiskReadKBytesRate(); this.setDiskReadKBytesRate();
this.setDiskWriteKBytesRate(); this.setDiskWriteKBytesRate();
this.setFreeGB(); this.setFreeGB();
this.setTotalGB(); this.setTotalGB();
this.setUsedGB(); this.setUsedGB();
this.setUsedPercent(); this.setUsedPercent();
} }
@XmlElementWrapper @XmlElementWrapper
@XmlElement(name = "FileSystem", type = FileSystemModel.class) @XmlElement(name = "FileSystem", type = FileSystemModel.class)
public List<FileSystemModel> getFieFileSystemModels() { public List<FileSystemModel> getFieFileSystemModels() {
return fieFileSystemModels; return fieFileSystemModels;
} }
private void setFieFileSystemModels() throws SigarException, private void setFieFileSystemModels() throws SigarException,
InterruptedException, ExecutionException { InterruptedException, ExecutionException {
this.fieFileSystemModels = new ArrayList<FileSystemModel>(); this.fieFileSystemModels = new ArrayList<FileSystemModel>();
Map<String, FileSystemUsage> fileSysUsageMap = this Map<String, FileSystemUsage> fileSysUsageMap = this
.getFileSystemUsages(); .getFileSystemUsages();
if (fileSysUsageMap.keySet() != null) { if (fileSysUsageMap.keySet() != null) {
List<Future<FileSystemModel>> futures = new ArrayList<Future<FileSystemModel>>(); List<Future<FileSystemModel>> futures = new ArrayList<Future<FileSystemModel>>();
for (String fileDir : fileSysUsageMap.keySet()) { for (String fileDir : fileSysUsageMap.keySet()) {
futures.add(GetThreadPool.getExecutorService().submit( futures.add(GetThreadPool.getExecutorService().submit(
new NewFileSystemModel(fileSysUsageMap.get(fileDir), new NewFileSystemModel(fileSysUsageMap.get(fileDir),
fileDir, interval))); fileDir, interval)));
} }
for (Future<FileSystemModel> future : futures) { for (Future<FileSystemModel> future : futures) {
fieFileSystemModels.add(future.get()); fieFileSystemModels.add(future.get());
} }
} }
} }
@XmlElement @XmlElement
public double getDiskReadKBytesRate() { public double getDiskReadKBytesRate() {
return diskReadKBytesRate; return diskReadKBytesRate;
} }
private void setDiskReadKBytesRate() { private void setDiskReadKBytesRate() {
diskReadKBytesRate = new Double(0); diskReadKBytesRate = new Double(0);
for (FileSystemModel fileSystemModel : this.fieFileSystemModels) { for (FileSystemModel fileSystemModel : this.fieFileSystemModels) {
diskReadKBytesRate += fileSystemModel.getDiskReadKBytesRate(); diskReadKBytesRate += fileSystemModel.getDiskReadKBytesRate();
} }
} }
@XmlElement @XmlElement
public double getDiskWriteKBytesRate() { public double getDiskWriteKBytesRate() {
return this.diskWriteKBytesRate; return this.diskWriteKBytesRate;
} }
private void setDiskWriteKBytesRate() { private void setDiskWriteKBytesRate() {
this.diskWriteKBytesRate = new Double(0); this.diskWriteKBytesRate = new Double(0);
for (FileSystemModel fileSystemModel : this.fieFileSystemModels) { for (FileSystemModel fileSystemModel : this.fieFileSystemModels) {
this.diskWriteKBytesRate += fileSystemModel this.diskWriteKBytesRate += fileSystemModel
.getDiskWriteKBytesRate(); .getDiskWriteKBytesRate();
} }
} }
@XmlElement @XmlElement
public double getCurDiskQueLength() { public double getCurDiskQueLength() {
return this.curDiskQueLength; return this.curDiskQueLength;
} }
private void setCurDiskQueLength() throws SigarException { private void setCurDiskQueLength() throws SigarException {
this.curDiskQueLength = new Double(0); this.curDiskQueLength = new Double(0);
for (FileSystemModel fileSystemModel : this.getFieFileSystemModels()) { for (FileSystemModel fileSystemModel : this.getFieFileSystemModels()) {
this.curDiskQueLength += fileSystemModel.getCurDiskQueLength(); this.curDiskQueLength += fileSystemModel.getCurDiskQueLength();
} }
} }
@XmlElement @XmlElement
public FileSystem[] getFileSystemList() { public FileSystem[] getFileSystemList() {
return fileSystemList; return fileSystemList;
} }
private void setFileSystemList() throws SigarException { private void setFileSystemList() throws SigarException {
this.fileSystemList = this.sigar.getFileSystemList(); this.fileSystemList = this.sigar.getFileSystemList();
} }
@XmlElement @XmlElement
public double getTotalGB() { public double getTotalGB() {
return this.totalGB; return this.totalGB;
} }
private void setTotalGB() { private void setTotalGB() {
this.totalGB = 0; this.totalGB = 0;
for (FileSystemModel fileSystemModel : this.fieFileSystemModels) { for (FileSystemModel fileSystemModel : this.fieFileSystemModels) {
this.totalGB += fileSystemModel.getTotalGB(); this.totalGB += fileSystemModel.getTotalGB();
} }
} }
@XmlElement @XmlElement
public double getUsedGB() { public double getUsedGB() {
return usedGB; return usedGB;
} }
private void setUsedGB() { private void setUsedGB() {
this.usedGB = 0; this.usedGB = 0;
for (FileSystemModel fileSystemModel : this.fieFileSystemModels) { for (FileSystemModel fileSystemModel : this.fieFileSystemModels) {
this.usedGB += fileSystemModel.getUsedGB(); this.usedGB += fileSystemModel.getUsedGB();
} }
this.usedGB=Math.round(this.usedGB*100)/100; this.usedGB=Math.round(this.usedGB*100)/100;
} }
@XmlElement @XmlElement
public double getFreeGB() { public double getFreeGB() {
return freeGB; return freeGB;
} }
private void setFreeGB() { private void setFreeGB() {
this.freeGB = 0; this.freeGB = 0;
for (FileSystemModel fileSystemModel : this.fieFileSystemModels) { for (FileSystemModel fileSystemModel : this.fieFileSystemModels) {
this.freeGB += fileSystemModel.getFreeGB(); this.freeGB += fileSystemModel.getFreeGB();
} }
} }
@XmlElement @XmlElement
public double getUsedPercent() { public double getUsedPercent() {
return usedPercent; return usedPercent;
} }
private void setUsedPercent() { private void setUsedPercent() {
this.usedPercent = 0; this.usedPercent = 0;
for (FileSystemModel fileSystemModel : this.fieFileSystemModels) { for (FileSystemModel fileSystemModel : this.fieFileSystemModels) {
this.usedPercent += fileSystemModel.getUsedPercent(); this.usedPercent += fileSystemModel.getUsedPercent();
} }
this.usedPercent=this.usedPercent/this.fieFileSystemModels.size(); this.usedPercent=this.usedPercent/this.fieFileSystemModels.size();
} }
public Map<String, FileSystemUsage> getFileSystemUsages() public Map<String, FileSystemUsage> getFileSystemUsages()
throws SigarException { throws SigarException {
Map<String, FileSystemUsage> fileSystemUsages = new HashMap<String, FileSystemUsage>(); Map<String, FileSystemUsage> fileSystemUsages = new HashMap<String, FileSystemUsage>();
if (this.getFileSystemList() == null) if (this.getFileSystemList() == null)
this.setFileSystemList(); this.setFileSystemList();
for (FileSystem fileSystem : this.getFileSystemList()) { for (FileSystem fileSystem : this.getFileSystemList()) {
if (fileSystem.getType() == 2) if (fileSystem.getType() == 2)
fileSystemUsages.put(fileSystem.getDirName(), fileSystemUsages.put(fileSystem.getDirName(),
sigar.getFileSystemUsage(fileSystem.getDirName())); sigar.getFileSystemUsage(fileSystem.getDirName()));
} }
return fileSystemUsages; return fileSystemUsages;
} }
} }
class NewFileSystemModel implements Callable<FileSystemModel> { class NewFileSystemModel implements Callable<FileSystemModel> {
private FileSystemUsage fileSystemUsage; private FileSystemUsage fileSystemUsage;
private String fileDir; private String fileDir;
private int interval; private int interval;
public NewFileSystemModel(FileSystemUsage fileSystemUsage, String fileDir, public NewFileSystemModel(FileSystemUsage fileSystemUsage, String fileDir,
int interval) { int interval) {
this.fileDir = fileDir; this.fileDir = fileDir;
this.fileSystemUsage = fileSystemUsage; this.fileSystemUsage = fileSystemUsage;
this.interval = interval; this.interval = interval;
} }
public FileSystemModel call() throws InterruptedException, public FileSystemModel call() throws InterruptedException,
ExecutionException { ExecutionException {
return new FileSystemModel(this.fileSystemUsage, fileDir, interval); return new FileSystemModel(this.fileSystemUsage, fileDir, interval);
} }
public FileSystemUsage getFileSystemUsage() { public FileSystemUsage getFileSystemUsage() {
return fileSystemUsage; return fileSystemUsage;
} }
public String getFileDir() { public String getFileDir() {
return fileDir; return fileDir;
} }
public long getInterval() { public long getInterval() {
return interval; return interval;
} }
} }

View File

@ -1,180 +1,180 @@
package org.bench4q.monitor.model; package org.bench4q.monitor.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.bench4q.monitor.service.GetSigar; import org.bench4q.monitor.service.GetSigar;
import org.bench4q.monitor.service.GetThreadPool; import org.bench4q.monitor.service.GetThreadPool;
import org.hyperic.sigar.ProcState; import org.hyperic.sigar.ProcState;
import org.hyperic.sigar.Sigar; import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException; import org.hyperic.sigar.SigarException;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
@XmlRootElement @XmlRootElement
public class ProcessModel implements Runnable { public class ProcessModel implements Runnable {
private Sigar sigar = GetSigar.getSigar(); private Sigar sigar = GetSigar.getSigar();
@Expose @Expose
private List<ProcessModelChild> processModelList; private List<ProcessModelChild> processModelList;
@Expose @Expose
private long[] processPids; private long[] processPids;
@Expose @Expose
private List<String> processNameList; private List<String> processNameList;
@Expose @Expose
private int size; private int size;
public static void main(String args[]) throws SigarException, public static void main(String args[]) throws SigarException,
InterruptedException, ExecutionException { InterruptedException, ExecutionException {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
ProcessModel processModel = new ProcessModel(); ProcessModel processModel = new ProcessModel();
System.out.println("total process:" System.out.println("total process:"
+ processModel.getProcessPids().length); + processModel.getProcessPids().length);
for (int i = 0; i < processModel.getProcessPids().length; i++) { for (int i = 0; i < processModel.getProcessPids().length; i++) {
if (processModel.getProcessModelList().get(i) != null) { if (processModel.getProcessModelList().get(i) != null) {
System.out.println("pid:" System.out.println("pid:"
+ processModel.getProcessModelList().get(i) + processModel.getProcessModelList().get(i)
.getInstanceString()); .getInstanceString());
System.out.println("name:" System.out.println("name:"
+ processModel.getProcessModelList().get(i) + processModel.getProcessModelList().get(i)
.getProcessId()); .getProcessId());
System.out.println("cpu percent:" System.out.println("cpu percent:"
+ processModel.getProcessModelList().get(i) + processModel.getProcessModelList().get(i)
.getProcessorTimePercent()); .getProcessorTimePercent());
System.out.println("getResidentKBytes:" System.out.println("getResidentKBytes:"
+ processModel.getProcessModelList().get(i) + processModel.getProcessModelList().get(i)
.getResidentKBytes()); .getResidentKBytes());
System.out.println("virtural Kbytes:" System.out.println("virtural Kbytes:"
+ processModel.getProcessModelList().get(i).getVSize()); + processModel.getProcessModelList().get(i).getVSize());
System.out.println(" Kbytes:" System.out.println(" Kbytes:"
+ processModel.getProcessModelList().get(i) + processModel.getProcessModelList().get(i)
.getMemSize()); .getMemSize());
break; break;
} }
} }
System.out.println(System.currentTimeMillis() - time); System.out.println(System.currentTimeMillis() - time);
} }
private MonitorMain monitorMain; private MonitorMain monitorMain;
private Logger logger = Logger.getLogger(ProcessModel.class); private Logger logger = Logger.getLogger(ProcessModel.class);
public ProcessModel(MonitorMain monitorMain) { public ProcessModel(MonitorMain monitorMain) {
this.monitorMain = monitorMain; this.monitorMain = monitorMain;
} }
public void run() { public void run() {
try { try {
monitorMain.setProcesssModel(new ProcessModel()); monitorMain.setProcesssModel(new ProcessModel());
} catch (SigarException e) { } catch (SigarException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
logger.info(e, e.fillInStackTrace()); logger.info(e, e.fillInStackTrace());
} catch (InterruptedException e) { } catch (InterruptedException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
logger.info(e, e.fillInStackTrace()); logger.info(e, e.fillInStackTrace());
} catch (ExecutionException e) { } catch (ExecutionException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
logger.info(e, e.fillInStackTrace()); logger.info(e, e.fillInStackTrace());
} }
} }
public ProcessModel() throws SigarException, InterruptedException, public ProcessModel() throws SigarException, InterruptedException,
ExecutionException { ExecutionException {
this.setProcessPids(); this.setProcessPids();
this.setProcesModelList(); this.setProcesModelList();
this.setProcessNameList(); this.setProcessNameList();
this.setSize(); this.setSize();
} }
@XmlElement @XmlElement
public int getSize() { public int getSize() {
return this.size; return this.size;
} }
private void setSize() throws SigarException { private void setSize() throws SigarException {
this.size = sigar.getProcList().length; this.size = sigar.getProcList().length;
} }
@XmlElementWrapper() @XmlElementWrapper()
@XmlElement(type = ProcessModelChild.class) @XmlElement(type = ProcessModelChild.class)
public List<ProcessModelChild> getProcessModelList() { public List<ProcessModelChild> getProcessModelList() {
return processModelList; return processModelList;
} }
public void setProcesModelList() throws SigarException, public void setProcesModelList() throws SigarException,
InterruptedException, ExecutionException { InterruptedException, ExecutionException {
this.processModelList = new ArrayList<ProcessModelChild>(); this.processModelList = new ArrayList<ProcessModelChild>();
List<Future<ProcessModelChild>> futures = new ArrayList<Future<ProcessModelChild>>(); List<Future<ProcessModelChild>> futures = new ArrayList<Future<ProcessModelChild>>();
for (int i = 0; i < this.processPids.length; ++i) { for (int i = 0; i < this.processPids.length; ++i) {
try { try {
futures.add(GetThreadPool.getExecutorService().submit( futures.add(GetThreadPool.getExecutorService().submit(
new NewProcessChild(processPids[i], new NewProcessChild(processPids[i],
new ProcessSigarReleatedModel(processPids[i])))); new ProcessSigarReleatedModel(processPids[i]))));
} catch (SigarException e) { } catch (SigarException e) {
processModelList.add(new ProcessModelChild(processPids[i])); processModelList.add(new ProcessModelChild(processPids[i]));
} }
} }
for (Future<ProcessModelChild> future : futures) { for (Future<ProcessModelChild> future : futures) {
processModelList.add(future.get()); processModelList.add(future.get());
} }
} }
@XmlElement @XmlElement
public long[] getProcessPids() { public long[] getProcessPids() {
return processPids; return processPids;
} }
private void setProcessPids() throws SigarException { private void setProcessPids() throws SigarException {
this.processPids = sigar.getProcList(); this.processPids = sigar.getProcList();
} }
@XmlElementWrapper(name = "processNameList") @XmlElementWrapper(name = "processNameList")
@XmlElement(name = "processName", type = String.class) @XmlElement(name = "processName", type = String.class)
public List<String> getProcessNameList() { public List<String> getProcessNameList() {
return processNameList; return processNameList;
} }
private void setProcessNameList() throws SigarException { private void setProcessNameList() throws SigarException {
this.processNameList = new ArrayList<String>(); this.processNameList = new ArrayList<String>();
for (long pid : this.getProcessPids()) { for (long pid : this.getProcessPids()) {
try { try {
ProcState procState = sigar.getProcState(pid); ProcState procState = sigar.getProcState(pid);
processNameList.add(procState.getName()); processNameList.add(procState.getName());
} catch (SigarException e) { } catch (SigarException e) {
} }
} }
} }
} }
class NewProcessChild implements Callable<ProcessModelChild> { class NewProcessChild implements Callable<ProcessModelChild> {
private long pid; private long pid;
private ProcessSigarReleatedModel processSigarReleatedModel; private ProcessSigarReleatedModel processSigarReleatedModel;
public NewProcessChild(long pid, public NewProcessChild(long pid,
ProcessSigarReleatedModel processSigarReleatedModel) { ProcessSigarReleatedModel processSigarReleatedModel) {
this.pid = pid; this.pid = pid;
this.processSigarReleatedModel = processSigarReleatedModel; this.processSigarReleatedModel = processSigarReleatedModel;
} }
public ProcessModelChild call() { public ProcessModelChild call() {
try { try {
return new ProcessModelChild(pid, processSigarReleatedModel); return new ProcessModelChild(pid, processSigarReleatedModel);
} catch (SigarException e) { } catch (SigarException e) {
return new ProcessModelChild(pid); return new ProcessModelChild(pid);
} }
} }
} }

View File

@ -1,113 +1,113 @@
package org.bench4q.monitor.model; package org.bench4q.monitor.model;
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 org.bench4q.monitor.service.DataFomat; import org.bench4q.monitor.service.DataFomat;
import org.hyperic.sigar.ProcCpu; import org.hyperic.sigar.ProcCpu;
import org.hyperic.sigar.ProcMem; import org.hyperic.sigar.ProcMem;
import org.hyperic.sigar.ProcState; import org.hyperic.sigar.ProcState;
import org.hyperic.sigar.SigarException; import org.hyperic.sigar.SigarException;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
@XmlRootElement @XmlRootElement
public class ProcessModelChild { public class ProcessModelChild {
@Expose @Expose
private String instanceString; private String instanceString;
@Expose @Expose
private long residentKBytes; private long residentKBytes;
@Expose @Expose
private double processorTimePercent; private double processorTimePercent;
@Expose @Expose
private long memSize; private long memSize;
@Expose @Expose
private long processId; private long processId;
@Expose @Expose
private long vSize; private long vSize;
private ProcessSigarReleatedModel processSigarReleatedModel; private ProcessSigarReleatedModel processSigarReleatedModel;
public ProcessModelChild(){ public ProcessModelChild(){
} }
public ProcessModelChild(long pid){ public ProcessModelChild(long pid){
this.processId=pid; this.processId=pid;
this.instanceString="no power to get info"; this.instanceString="no power to get info";
} }
public ProcessModelChild(long processId, public ProcessModelChild(long processId,
ProcessSigarReleatedModel processSigarReleatedModel) ProcessSigarReleatedModel processSigarReleatedModel)
throws SigarException { throws SigarException {
this.processSigarReleatedModel = processSigarReleatedModel; this.processSigarReleatedModel = processSigarReleatedModel;
this.setProcessId(processId); this.setProcessId(processId);
this.setInstanceString(); this.setInstanceString();
this.setProcessorTimePercent(); this.setProcessorTimePercent();
this.setMemSize(); this.setMemSize();
this.setResidentKBytes(); this.setResidentKBytes();
this.setVSize(); this.setVSize();
} }
@XmlElement @XmlElement
public double getProcessorTimePercent() throws SigarException { public double getProcessorTimePercent() throws SigarException {
return processorTimePercent; return processorTimePercent;
} }
private void setProcessorTimePercent() { private void setProcessorTimePercent() {
ProcCpu procCpu = this.processSigarReleatedModel.getProcCpu(); ProcCpu procCpu = this.processSigarReleatedModel.getProcCpu();
this.processorTimePercent = DataFomat.fomatToPercent(procCpu this.processorTimePercent = DataFomat.fomatToPercent(procCpu
.getPercent()); .getPercent());
} }
@XmlElement @XmlElement
public String getInstanceString() throws SigarException { public String getInstanceString() throws SigarException {
return instanceString; return instanceString;
} }
private void setInstanceString() { private void setInstanceString() {
ProcState procState = this.processSigarReleatedModel.getProcState(); ProcState procState = this.processSigarReleatedModel.getProcState();
this.instanceString = procState.getName(); this.instanceString = procState.getName();
} }
@XmlElement @XmlElement
public long getProcessId() { public long getProcessId() {
return processId; return processId;
} }
private void setProcessId(long processId) { private void setProcessId(long processId) {
this.processId = processId; this.processId = processId;
} }
@XmlElement @XmlElement
public long getVSize() throws SigarException { public long getVSize() throws SigarException {
return vSize; return vSize;
} }
private void setVSize() { private void setVSize() {
ProcMem procMem = this.processSigarReleatedModel.getProcMem(); ProcMem procMem = this.processSigarReleatedModel.getProcMem();
this.vSize = procMem.getSize() / 1024L; this.vSize = procMem.getSize() / 1024L;
} }
@XmlElement @XmlElement
public long getResidentKBytes() throws SigarException { public long getResidentKBytes() throws SigarException {
return residentKBytes; return residentKBytes;
} }
private void setResidentKBytes() { private void setResidentKBytes() {
ProcMem procMem = this.processSigarReleatedModel.getProcMem(); ProcMem procMem = this.processSigarReleatedModel.getProcMem();
this.residentKBytes = procMem.getResident() / 1024L; this.residentKBytes = procMem.getResident() / 1024L;
} }
@XmlElement @XmlElement
public long getMemSize() { public long getMemSize() {
return memSize; return memSize;
} }
private void setMemSize() { private void setMemSize() {
ProcMem procMem = this.processSigarReleatedModel.getProcMem(); ProcMem procMem = this.processSigarReleatedModel.getProcMem();
this.memSize = procMem.getSize(); this.memSize = procMem.getSize();
} }
} }

View File

@ -1,202 +1,202 @@
package org.bench4q.monitor.model; package org.bench4q.monitor.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.bench4q.monitor.service.DataFomat; import org.bench4q.monitor.service.DataFomat;
import org.bench4q.monitor.service.GetSigar; import org.bench4q.monitor.service.GetSigar;
import org.bench4q.monitor.service.GetThreadPool; import org.bench4q.monitor.service.GetThreadPool;
import org.hyperic.sigar.CpuInfo; import org.hyperic.sigar.CpuInfo;
import org.hyperic.sigar.Sigar; import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.CpuPerc; import org.hyperic.sigar.CpuPerc;
import org.hyperic.sigar.SigarException; import org.hyperic.sigar.SigarException;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
@XmlRootElement @XmlRootElement
public class ProcessorModel implements Runnable { public class ProcessorModel implements Runnable {
private List<ProcessorModelChild> processorModelList; private List<ProcessorModelChild> processorModelList;
private Sigar sigar = GetSigar.getSigar(); private Sigar sigar = GetSigar.getSigar();
private CpuPerc cpuPerc; private CpuPerc cpuPerc;
@Expose @Expose
private double processorTimePercent; private double processorTimePercent;
@Expose @Expose
private double privilegedTimePercent; private double privilegedTimePercent;
@Expose @Expose
private double userTimePercent; private double userTimePercent;
@Expose @Expose
private double speed; private double speed;
@Expose @Expose
private List<String> cpuInstanceList; private List<String> cpuInstanceList;
@Expose @Expose
private int size; private int size;
private MonitorMain monitorMain; private MonitorMain monitorMain;
private Logger logger = Logger.getLogger(ProcessorModel.class); private Logger logger = Logger.getLogger(ProcessorModel.class);
public static void main(String args[]) { public static void main(String args[]) {
try { try {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
ProcessorModel processorModel = new ProcessorModel(); ProcessorModel processorModel = new ProcessorModel();
System.out.println(processorModel.getProcessorModelList().size() System.out.println(processorModel.getProcessorModelList().size()
+ " instances"); + " instances");
System.out.println("privileged time percent" System.out.println("privileged time percent"
+ processorModel.getPrivilegedTimePercent()); + processorModel.getPrivilegedTimePercent());
System.out.println("user time percent" System.out.println("user time percent"
+ processorModel.getUserTimePercent()); + processorModel.getUserTimePercent());
System.out.println("total time percent:" System.out.println("total time percent:"
+ processorModel.getProcessorTimePercent()); + processorModel.getProcessorTimePercent());
System.out.println("speed:" + processorModel.getSpeed()); System.out.println("speed:" + processorModel.getSpeed());
System.out.println(System.currentTimeMillis() - time); System.out.println(System.currentTimeMillis() - time);
} catch (SigarException e) { } catch (SigarException e) {
// TODO: handle exception // TODO: handle exception
e.printStackTrace(); e.printStackTrace();
} }
} }
public ProcessorModel(MonitorMain monitorMain) { public ProcessorModel(MonitorMain monitorMain) {
this.monitorMain = monitorMain; this.monitorMain = monitorMain;
} }
public void run() { public void run() {
try { try {
monitorMain.setProcessorModel(new ProcessorModel()); monitorMain.setProcessorModel(new ProcessorModel());
} catch (SigarException e) { } catch (SigarException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
logger.info(e, e.fillInStackTrace()); logger.info(e, e.fillInStackTrace());
} }
} }
public ProcessorModel() throws SigarException { public ProcessorModel() throws SigarException {
cpuPerc = sigar.getCpuPerc(); cpuPerc = sigar.getCpuPerc();
this.setPorcessorModelList(); this.setPorcessorModelList();
this.setPrivilegedTimePercent(); this.setPrivilegedTimePercent();
this.setProcessorTimePercent(); this.setProcessorTimePercent();
this.setUserTimePercent(); this.setUserTimePercent();
this.setSpeed(); this.setSpeed();
this.setCpuInstanceList(); this.setCpuInstanceList();
this.setSize(); this.setSize();
} }
@XmlElement @XmlElement
public int getSize() { public int getSize() {
return size; return size;
} }
private void setSize() { private void setSize() {
this.size = this.getProcessorModelList().size(); this.size = this.getProcessorModelList().size();
} }
@XmlElement @XmlElement
public double getProcessorTimePercent() throws SigarException { public double getProcessorTimePercent() throws SigarException {
return this.processorTimePercent; return this.processorTimePercent;
} }
private void setProcessorTimePercent() throws SigarException { private void setProcessorTimePercent() throws SigarException {
this.processorTimePercent = DataFomat.fomatToPercent(1 - cpuPerc this.processorTimePercent = DataFomat.fomatToPercent(1 - cpuPerc
.getIdle()); .getIdle());
} }
@XmlElement @XmlElement
public double getPrivilegedTimePercent() { public double getPrivilegedTimePercent() {
return this.privilegedTimePercent; return this.privilegedTimePercent;
} }
private void setPrivilegedTimePercent() { private void setPrivilegedTimePercent() {
this.privilegedTimePercent = DataFomat.fomatToPercent(cpuPerc.getSys()); this.privilegedTimePercent = DataFomat.fomatToPercent(cpuPerc.getSys());
} }
@XmlElement @XmlElement
public double getUserTimePercent() throws SigarException { public double getUserTimePercent() throws SigarException {
return this.userTimePercent; return this.userTimePercent;
} }
private void setUserTimePercent() throws SigarException { private void setUserTimePercent() throws SigarException {
this.userTimePercent = DataFomat.fomatToPercent(cpuPerc.getUser()); this.userTimePercent = DataFomat.fomatToPercent(cpuPerc.getUser());
} }
public double getSpeed() { public double getSpeed() {
return this.speed; return this.speed;
} }
private void setSpeed() throws SigarException { private void setSpeed() throws SigarException {
this.speed = 0; this.speed = 0;
CpuInfo[] cpuInfos = GetSigar.getSigar().getCpuInfoList(); CpuInfo[] cpuInfos = GetSigar.getSigar().getCpuInfoList();
if (cpuInfos != null) { if (cpuInfos != null) {
this.speed += cpuInfos[0].getMhz(); this.speed += cpuInfos[0].getMhz();
} }
long temp = Math.round(this.speed * 100); long temp = Math.round(this.speed * 100);
this.speed = temp / 1024L / 100; this.speed = temp / 1024L / 100;
} }
@XmlElementWrapper(name = "instanceNameList") @XmlElementWrapper(name = "instanceNameList")
@XmlElement(name = "instanceName", type = String.class) @XmlElement(name = "instanceName", type = String.class)
public List<String> getCpuInstanceList() { public List<String> getCpuInstanceList() {
return cpuInstanceList; return cpuInstanceList;
} }
private void setCpuInstanceList() { private void setCpuInstanceList() {
this.cpuInstanceList = new ArrayList<String>(); this.cpuInstanceList = new ArrayList<String>();
if (this.getProcessorModelList() != null) { if (this.getProcessorModelList() != null) {
for (ProcessorModelChild processModelChild : this for (ProcessorModelChild processModelChild : this
.getProcessorModelList()) { .getProcessorModelList()) {
this.cpuInstanceList.add(processModelChild.getInstance()); this.cpuInstanceList.add(processModelChild.getInstance());
} }
} }
} }
@XmlElementWrapper(name = "processorlist") @XmlElementWrapper(name = "processorlist")
@XmlElement(name = "processor", type = ProcessorModelChild.class) @XmlElement(name = "processor", type = ProcessorModelChild.class)
public List<ProcessorModelChild> getProcessorModelList() { public List<ProcessorModelChild> getProcessorModelList() {
return processorModelList; return processorModelList;
} }
private void setPorcessorModelList() throws SigarException { private void setPorcessorModelList() throws SigarException {
this.processorModelList = new ArrayList<ProcessorModelChild>(); this.processorModelList = new ArrayList<ProcessorModelChild>();
CpuPerc[] cpuPercList = sigar.getCpuPercList(); CpuPerc[] cpuPercList = sigar.getCpuPercList();
List<Future<ProcessorModelChild>> futures = new ArrayList<Future<ProcessorModelChild>>(); List<Future<ProcessorModelChild>> futures = new ArrayList<Future<ProcessorModelChild>>();
for (int i = 0; i < cpuPercList.length; ++i) { for (int i = 0; i < cpuPercList.length; ++i) {
futures.add(GetThreadPool.getExecutorService().submit( futures.add(GetThreadPool.getExecutorService().submit(
new NewProcessorModelChild(i, cpuPercList[i]))); new NewProcessorModelChild(i, cpuPercList[i])));
} }
for (Future<ProcessorModelChild> future : futures) { for (Future<ProcessorModelChild> future : futures) {
try { try {
processorModelList.add(future.get()); processorModelList.add(future.get());
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} catch (ExecutionException e) { } catch (ExecutionException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
} }
class NewProcessorModelChild implements Callable<ProcessorModelChild> { class NewProcessorModelChild implements Callable<ProcessorModelChild> {
private int id; private int id;
private CpuPerc cpuPerc; private CpuPerc cpuPerc;
public NewProcessorModelChild(int id, CpuPerc cpuPerc) { public NewProcessorModelChild(int id, CpuPerc cpuPerc) {
this.id = id; this.id = id;
this.cpuPerc = cpuPerc; this.cpuPerc = cpuPerc;
} }
public ProcessorModelChild call() throws SigarException { public ProcessorModelChild call() throws SigarException {
return new ProcessorModelChild(id, cpuPerc); return new ProcessorModelChild(id, cpuPerc);
} }
} }

View File

@ -1,87 +1,87 @@
package org.bench4q.monitor.model; package org.bench4q.monitor.model;
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 org.bench4q.monitor.service.GetSigar; import org.bench4q.monitor.service.GetSigar;
import org.hyperic.sigar.CpuPerc; import org.hyperic.sigar.CpuPerc;
import org.hyperic.sigar.SigarException; import org.hyperic.sigar.SigarException;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
@XmlRootElement @XmlRootElement
public class ProcessorModelChild { public class ProcessorModelChild {
@Expose @Expose
private String instance; private String instance;
@Expose @Expose
private double processorTimePercent; private double processorTimePercent;
@Expose @Expose
private double userTimePercent; private double userTimePercent;
@Expose @Expose
private double privilegedTimePercent; private double privilegedTimePercent;
private CpuPerc cpuPerc; private CpuPerc cpuPerc;
public static void main(String[] agrs) throws SigarException { public static void main(String[] agrs) throws SigarException {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
ProcessorModelChild testModel = new ProcessorModelChild(0, GetSigar ProcessorModelChild testModel = new ProcessorModelChild(0, GetSigar
.getSigar().getCpuPercList()[0]); .getSigar().getCpuPercList()[0]);
System.out.println(testModel.getPrivilegedTimePercent()); System.out.println(testModel.getPrivilegedTimePercent());
System.out.println(testModel.getUserTimePercent()); System.out.println(testModel.getUserTimePercent());
System.out.println(testModel.getProcessorTimePercent()); System.out.println(testModel.getProcessorTimePercent());
System.out.println(System.currentTimeMillis() - time); System.out.println(System.currentTimeMillis() - time);
} }
public ProcessorModelChild(){ public ProcessorModelChild(){
} }
public ProcessorModelChild(int id) throws SigarException { public ProcessorModelChild(int id) throws SigarException {
this.setInstance("cpu" + id); this.setInstance("cpu" + id);
this.cpuPerc=GetSigar.getSigar().getCpuPerc(); this.cpuPerc=GetSigar.getSigar().getCpuPerc();
} }
public ProcessorModelChild(int id, CpuPerc cpuPerc) throws SigarException { public ProcessorModelChild(int id, CpuPerc cpuPerc) throws SigarException {
this.setInstance("cpu" + id); this.setInstance("cpu" + id);
this.cpuPerc = cpuPerc; this.cpuPerc = cpuPerc;
} }
@XmlElement @XmlElement
public String getInstance() { public String getInstance() {
return this.instance; return this.instance;
} }
private void setInstance(String instance) { private void setInstance(String instance) {
this.instance = instance; this.instance = instance;
} }
@XmlElement @XmlElement
public double getProcessorTimePercent() { public double getProcessorTimePercent() {
long temp = Math.round(cpuPerc.getCombined() * 10000); long temp = Math.round(cpuPerc.getCombined() * 10000);
this.setProcessorTimePercent(temp / 100.0); this.setProcessorTimePercent(temp / 100.0);
return processorTimePercent; return processorTimePercent;
} }
private void setProcessorTimePercent(double processorTimePercent) { private void setProcessorTimePercent(double processorTimePercent) {
this.processorTimePercent = processorTimePercent; this.processorTimePercent = processorTimePercent;
} }
@XmlElement @XmlElement
public double getUserTimePercent() throws SigarException { public double getUserTimePercent() throws SigarException {
long temp = Math.round(cpuPerc.getUser() * 10000); long temp = Math.round(cpuPerc.getUser() * 10000);
this.setUserTimePercent(temp / 100.0); this.setUserTimePercent(temp / 100.0);
return this.userTimePercent; return this.userTimePercent;
} }
private void setUserTimePercent(double userTimePercent) { private void setUserTimePercent(double userTimePercent) {
this.userTimePercent = userTimePercent; this.userTimePercent = userTimePercent;
} }
@XmlElement @XmlElement
public double getPrivilegedTimePercent() throws SigarException { public double getPrivilegedTimePercent() throws SigarException {
long temp = Math.round(cpuPerc.getSys() * 10000); long temp = Math.round(cpuPerc.getSys() * 10000);
this.setPrivilegedTimePercent(temp / 100.0); this.setPrivilegedTimePercent(temp / 100.0);
return this.privilegedTimePercent; return this.privilegedTimePercent;
} }
private void setPrivilegedTimePercent(double privilegedTimePercent) { private void setPrivilegedTimePercent(double privilegedTimePercent) {
this.privilegedTimePercent = privilegedTimePercent; this.privilegedTimePercent = privilegedTimePercent;
} }
} }

View File

@ -1,39 +1,39 @@
package org.bench4q.monitor.model; package org.bench4q.monitor.model;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement @XmlRootElement
public class SystemModel { public class SystemModel {
private double fileDataOperationsPerSecond; private double fileDataOperationsPerSecond;
public double getFileDataOperationsPerSecond() { public double getFileDataOperationsPerSecond() {
return fileDataOperationsPerSecond; return fileDataOperationsPerSecond;
} }
public void setFileDataOperationsPerSecond( public void setFileDataOperationsPerSecond(
double fileDataOperationsPerSecond) { double fileDataOperationsPerSecond) {
this.fileDataOperationsPerSecond = fileDataOperationsPerSecond; this.fileDataOperationsPerSecond = fileDataOperationsPerSecond;
} }
public double getProcessorQueueLength() { public double getProcessorQueueLength() {
return processorQueueLength; return processorQueueLength;
} }
public void setProcessorQueueLength(double processorQueueLength) { public void setProcessorQueueLength(double processorQueueLength) {
this.processorQueueLength = processorQueueLength; this.processorQueueLength = processorQueueLength;
} }
private double processorQueueLength; private double processorQueueLength;
double totalProceesorTimePercent; double totalProceesorTimePercent;
public double getTotalProceesorTimePercent() { public double getTotalProceesorTimePercent() {
return totalProceesorTimePercent; return totalProceesorTimePercent;
} }
public void setTotalProceesorTimePercent(double totalProceesorTimePercent2) { public void setTotalProceesorTimePercent(double totalProceesorTimePercent2) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
this.totalProceesorTimePercent = totalProceesorTimePercent2; this.totalProceesorTimePercent = totalProceesorTimePercent2;
} }
} }

View File

@ -1,12 +1,12 @@
package org.bench4q.monitor.service; package org.bench4q.monitor.service;
public class DataFomat { public class DataFomat {
public static double fomatToPercent(double data) { public static double fomatToPercent(double data) {
long temp = Math.round(data * 10000); long temp = Math.round(data * 10000);
return temp / 100.0; return temp / 100.0;
} }
public static double caculateTimeInterval(long startTime, long endTime) { public static double caculateTimeInterval(long startTime, long endTime) {
double temp=(endTime - startTime); double temp=(endTime - startTime);
return temp/1000000000L; return temp/1000000000L;
} }
} }

View File

@ -1,15 +1,15 @@
package org.bench4q.monitor.service; package org.bench4q.monitor.service;
import org.hyperic.sigar.Sigar; import org.hyperic.sigar.Sigar;
public class GetSigar { public class GetSigar {
public static Sigar sigar; public static Sigar sigar;
public static Sigar getSigar() { public static Sigar getSigar() {
sigar = new Sigar(); sigar = new Sigar();
return sigar; return sigar;
} }
} }

View File

@ -1,17 +1,17 @@
package org.bench4q.monitor.service; package org.bench4q.monitor.service;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
public class GetThreadPool { public class GetThreadPool {
private static ExecutorService executorService = Executors private static ExecutorService executorService = Executors
.newFixedThreadPool(100); .newFixedThreadPool(100);
public static ExecutorService getExecutorService() { public static ExecutorService getExecutorService() {
return executorService; return executorService;
} }
public static void shutDownExecutrorService() { public static void shutDownExecutrorService() {
executorService.shutdown(); executorService.shutdown();
} }
} }

View File

@ -1,36 +1,36 @@
package org.bench4q.monitor.service; package org.bench4q.monitor.service;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import org.hyperic.sigar.SigarException; import org.hyperic.sigar.SigarException;
public class TimerService extends TimerTask { public class TimerService extends TimerTask {
@Override @Override
public void run(){ public void run(){
WriteSystemInfoToLocalDisk testWrite = new WriteSystemInfoToLocalDisk(); WriteSystemInfoToLocalDisk testWrite = new WriteSystemInfoToLocalDisk();
String filePath = System.getProperty("user.dir")+"/sigartmp"; String filePath = System.getProperty("user.dir")+"/sigartmp";
new File(filePath).mkdirs(); new File(filePath).mkdirs();
testWrite.setSavaPath("sigartmp/"); testWrite.setSavaPath("sigartmp/");
try { try {
try { try {
testWrite.writeCurrentSystemInfoToLocalDisk(); testWrite.writeCurrentSystemInfoToLocalDisk();
} catch (InterruptedException e) { } catch (InterruptedException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} catch (ExecutionException e) { } catch (ExecutionException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} catch (SigarException e) { } catch (SigarException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
} }

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="org.bench4q" /> <context:component-scan base-package="org.bench4q" />
<mvc:annotation-driven /> <mvc:annotation-driven />
</beans> </beans>

View File

@ -1,339 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc., [http://fsf.org/]
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{description}
Copyright (C) {year} {fullname}
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
{signature of Ty Coon}, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.