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"?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
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">
<id>publish</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<files>
<file>
<source>target/bench4q-monitor.jar</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
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">
<id>publish</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<files>
<file>
<source>target/bench4q-monitor.jar</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
</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"
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>
<groupId>org.bench4q</groupId>
<artifactId>bench4q-monitor</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Bench4Q Monitor</name>
<description>Bench4Q Monitor</description>
<organization>
<name>TCSE, ISCAS</name>
</organization>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>8.1.11.v20130520</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>8.1.11.v20130520</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version>
</dependency>
<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.fusesource</groupId>
<artifactId>sigar</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.bench4q.monitor.MonitorServer</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>descriptor.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
<finalName>bench4q-monitor</finalName>
</build>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.bench4q</groupId>
<artifactId>bench4q-monitor</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Bench4Q Monitor</name>
<description>Bench4Q Monitor</description>
<organization>
<name>TCSE, ISCAS</name>
</organization>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>8.1.11.v20130520</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>8.1.11.v20130520</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version>
</dependency>
<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.fusesource</groupId>
<artifactId>sigar</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.bench4q.monitor.MonitorServer</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>descriptor.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
<finalName>bench4q-monitor</finalName>
</build>
</project>

View File

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

View File

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

View File

@ -1,23 +1,23 @@
package org.bench4q.monitor.api;
import java.util.Date;
import java.util.concurrent.ExecutionException;
import org.bench4q.monitor.model.MonitorMain;
import org.hyperic.sigar.SigarException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/monitor")
public class MainController {
@RequestMapping("/all")
@ResponseBody
MonitorMain getMainModel() throws SigarException, InterruptedException, ExecutionException {
Date date = new Date();
MonitorMain retModel = new MonitorMain(date);
return retModel;
}
}
package org.bench4q.monitor.api;
import java.util.Date;
import java.util.concurrent.ExecutionException;
import org.bench4q.monitor.model.MonitorMain;
import org.hyperic.sigar.SigarException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/monitor")
public class MainController {
@RequestMapping("/all")
@ResponseBody
MonitorMain getMainModel() throws SigarException, InterruptedException, ExecutionException {
Date date = new Date();
MonitorMain retModel = new MonitorMain(date);
return retModel;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<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: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
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">
<context:component-scan base-package="org.bench4q" />
<mvc:annotation-driven />
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<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: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
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">
<context:component-scan base-package="org.bench4q" />
<mvc:annotation-driven />
</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.