From 501b761289dc3e5b50566c24420db3d4e710ea9f Mon Sep 17 00:00:00 2001 From: coderfengyun Date: Thu, 20 Mar 2014 17:19:37 +0800 Subject: [PATCH] Merge Bench4Q-Monitor-Sigar --- .../descriptor.xml | 48 +- pom.xml => Bench4Q-Monitor-Sigar/pom.xml | 220 +++---- .../org/bench4q/monitor/MonitorServer.java | 156 ++--- .../monitor/api/HistoryDataController.java | 68 +-- .../bench4q/monitor/api/MainController.java | 46 +- .../bench4q/monitor/api/MemoryController.java | 38 +- .../monitor/api/NetworkController.java | 36 +- .../monitor/api/PhysicalDiskController.java | 76 +-- .../monitor/api/ProcessController.java | 0 .../monitor/api/ProcessorController.java | 74 +-- .../bench4q/monitor/api/StartToRecord.java | 58 +- .../monitor/exception/MonitorException.java | 64 +-- .../monitor/model/FileSystemModel.java | 446 +++++++------- .../bench4q/monitor/model/ListMainModel.java | 44 +- .../bench4q/monitor/model/MemoryModel.java | 344 +++++------ .../bench4q/monitor/model/MonitorMain.java | 0 .../monitor/model/NetworkInterfaceModel.java | 382 ++++++------ .../monitor/model/PhysicalDiskModel.java | 542 +++++++++--------- .../bench4q/monitor/model/ProcessModel.java | 358 ++++++------ .../monitor/model/ProcessModelChild.java | 226 ++++---- .../model/ProcessSigarReleatedModel.java | 0 .../bench4q/monitor/model/ProcessorModel.java | 402 ++++++------- .../monitor/model/ProcessorModelChild.java | 174 +++--- .../bench4q/monitor/model/SystemModel.java | 78 +-- .../bench4q/monitor/service/DataFomat.java | 24 +- .../org/bench4q/monitor/service/GetSigar.java | 30 +- .../monitor/service/GetThreadPool.java | 34 +- .../service/ReadSystemInfoFromLocalDisk.java | 0 .../bench4q/monitor/service/TimerService.java | 72 +-- .../service/WriteSystemInfoToLocalDisk.java | 0 .../src}/main/resources/log4j.properties | 0 .../monitor/config/application-context.xml | 20 +- license.txt | 339 ----------- 33 files changed, 2030 insertions(+), 2369 deletions(-) rename descriptor.xml => Bench4Q-Monitor-Sigar/descriptor.xml (95%) rename pom.xml => Bench4Q-Monitor-Sigar/pom.xml (96%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/MonitorServer.java (95%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/api/HistoryDataController.java (97%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/api/MainController.java (96%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/api/MemoryController.java (96%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/api/NetworkController.java (96%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/api/PhysicalDiskController.java (97%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/api/ProcessController.java (100%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/api/ProcessorController.java (97%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/api/StartToRecord.java (95%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/exception/MonitorException.java (94%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/model/FileSystemModel.java (96%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/model/ListMainModel.java (96%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/model/MemoryModel.java (96%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/model/MonitorMain.java (100%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/model/NetworkInterfaceModel.java (96%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/model/PhysicalDiskModel.java (96%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/model/ProcessModel.java (96%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/model/ProcessModelChild.java (95%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/model/ProcessSigarReleatedModel.java (100%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/model/ProcessorModel.java (96%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/model/ProcessorModelChild.java (96%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/model/SystemModel.java (96%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/service/DataFomat.java (96%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/service/GetSigar.java (93%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/service/GetThreadPool.java (96%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/service/ReadSystemInfoFromLocalDisk.java (100%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/service/TimerService.java (96%) rename {src => Bench4Q-Monitor-Sigar/src}/main/java/org/bench4q/monitor/service/WriteSystemInfoToLocalDisk.java (100%) rename {src => Bench4Q-Monitor-Sigar/src}/main/resources/log4j.properties (100%) rename {src => Bench4Q-Monitor-Sigar/src}/main/resources/org/bench4q/monitor/config/application-context.xml (98%) delete mode 100644 license.txt diff --git a/descriptor.xml b/Bench4Q-Monitor-Sigar/descriptor.xml similarity index 95% rename from descriptor.xml rename to Bench4Q-Monitor-Sigar/descriptor.xml index 3e91b138..e3418acd 100644 --- a/descriptor.xml +++ b/Bench4Q-Monitor-Sigar/descriptor.xml @@ -1,25 +1,25 @@ - - - publish - - tar.gz - - false - - - lib - false - false - runtime - - - - - target/bench4q-monitor.jar - / - - + + + publish + + tar.gz + + false + + + lib + false + false + runtime + + + + + target/bench4q-monitor.jar + / + + \ No newline at end of file diff --git a/pom.xml b/Bench4Q-Monitor-Sigar/pom.xml similarity index 96% rename from pom.xml rename to Bench4Q-Monitor-Sigar/pom.xml index cd33aecf..fb3ff4ab 100644 --- a/pom.xml +++ b/Bench4Q-Monitor-Sigar/pom.xml @@ -1,111 +1,111 @@ - - 4.0.0 - org.bench4q - bench4q-monitor - jar - 0.0.1-SNAPSHOT - Bench4Q Monitor - Bench4Q Monitor - - TCSE, ISCAS - - - - com.google.code.gson - gson - 2.2.4 - - - junit - junit - 4.11 - test - - - org.eclipse.jetty - jetty-server - 8.1.11.v20130520 - - - log4j - log4j - 1.2.17 - - - org.eclipse.jetty - jetty-servlet - 8.1.11.v20130520 - - - org.springframework - spring-webmvc - 3.2.4.RELEASE - - - org.codehaus.jackson - jackson-mapper-asl - 1.9.12 - - - org.apache.directory.studio - org.apache.commons.io - 2.4 - - - org.fusesource - sigar - 1.6.4 - - - - dom4j - dom4j - 1.6.1 - - - - - - - maven-jar-plugin - - - - org.bench4q.monitor.MonitorServer - true - lib/ - - - - - - maven-assembly-plugin - - - make-zip - package - - single - - - - descriptor.xml - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - true - - - - - - bench4q-monitor - + + 4.0.0 + org.bench4q + bench4q-monitor + jar + 0.0.1-SNAPSHOT + Bench4Q Monitor + Bench4Q Monitor + + TCSE, ISCAS + + + + com.google.code.gson + gson + 2.2.4 + + + junit + junit + 4.11 + test + + + org.eclipse.jetty + jetty-server + 8.1.11.v20130520 + + + log4j + log4j + 1.2.17 + + + org.eclipse.jetty + jetty-servlet + 8.1.11.v20130520 + + + org.springframework + spring-webmvc + 3.2.4.RELEASE + + + org.codehaus.jackson + jackson-mapper-asl + 1.9.12 + + + org.apache.directory.studio + org.apache.commons.io + 2.4 + + + org.fusesource + sigar + 1.6.4 + + + + dom4j + dom4j + 1.6.1 + + + + + + + maven-jar-plugin + + + + org.bench4q.monitor.MonitorServer + true + lib/ + + + + + + maven-assembly-plugin + + + make-zip + package + + single + + + + descriptor.xml + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + + + bench4q-monitor + \ No newline at end of file diff --git a/src/main/java/org/bench4q/monitor/MonitorServer.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/MonitorServer.java similarity index 95% rename from src/main/java/org/bench4q/monitor/MonitorServer.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/MonitorServer.java index daf0b6c9..158e0c3f 100644 --- a/src/main/java/org/bench4q/monitor/MonitorServer.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/MonitorServer.java @@ -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(); + } +} diff --git a/src/main/java/org/bench4q/monitor/api/HistoryDataController.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/HistoryDataController.java similarity index 97% rename from src/main/java/org/bench4q/monitor/api/HistoryDataController.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/HistoryDataController.java index 213f3e26..0d51de0c 100644 --- a/src/main/java/org/bench4q/monitor/api/HistoryDataController.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/HistoryDataController.java @@ -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; + } + +} diff --git a/src/main/java/org/bench4q/monitor/api/MainController.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/MainController.java similarity index 96% rename from src/main/java/org/bench4q/monitor/api/MainController.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/MainController.java index 29490e31..33619426 100644 --- a/src/main/java/org/bench4q/monitor/api/MainController.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/MainController.java @@ -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; + } + +} diff --git a/src/main/java/org/bench4q/monitor/api/MemoryController.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/MemoryController.java similarity index 96% rename from src/main/java/org/bench4q/monitor/api/MemoryController.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/MemoryController.java index 0cabdc23..38ae54af 100644 --- a/src/main/java/org/bench4q/monitor/api/MemoryController.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/MemoryController.java @@ -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; + } +} diff --git a/src/main/java/org/bench4q/monitor/api/NetworkController.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/NetworkController.java similarity index 96% rename from src/main/java/org/bench4q/monitor/api/NetworkController.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/NetworkController.java index a5333f2b..6aab45cb 100644 --- a/src/main/java/org/bench4q/monitor/api/NetworkController.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/NetworkController.java @@ -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; + } + +} diff --git a/src/main/java/org/bench4q/monitor/api/PhysicalDiskController.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/PhysicalDiskController.java similarity index 97% rename from src/main/java/org/bench4q/monitor/api/PhysicalDiskController.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/PhysicalDiskController.java index d698d40d..32e23361 100644 --- a/src/main/java/org/bench4q/monitor/api/PhysicalDiskController.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/PhysicalDiskController.java @@ -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!"); + } +} diff --git a/src/main/java/org/bench4q/monitor/api/ProcessController.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/ProcessController.java similarity index 100% rename from src/main/java/org/bench4q/monitor/api/ProcessController.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/ProcessController.java diff --git a/src/main/java/org/bench4q/monitor/api/ProcessorController.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/ProcessorController.java similarity index 97% rename from src/main/java/org/bench4q/monitor/api/ProcessorController.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/ProcessorController.java index 05b6139a..a4e4ec75 100644 --- a/src/main/java/org/bench4q/monitor/api/ProcessorController.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/ProcessorController.java @@ -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"); + } +} diff --git a/src/main/java/org/bench4q/monitor/api/StartToRecord.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/StartToRecord.java similarity index 95% rename from src/main/java/org/bench4q/monitor/api/StartToRecord.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/StartToRecord.java index 20051575..d149f07a 100644 --- a/src/main/java/org/bench4q/monitor/api/StartToRecord.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/api/StartToRecord.java @@ -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"); + + } +} diff --git a/src/main/java/org/bench4q/monitor/exception/MonitorException.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/exception/MonitorException.java similarity index 94% rename from src/main/java/org/bench4q/monitor/exception/MonitorException.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/exception/MonitorException.java index 7c07057b..28061379 100644 --- a/src/main/java/org/bench4q/monitor/exception/MonitorException.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/exception/MonitorException.java @@ -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; + } + +} diff --git a/src/main/java/org/bench4q/monitor/model/FileSystemModel.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/FileSystemModel.java similarity index 96% rename from src/main/java/org/bench4q/monitor/model/FileSystemModel.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/FileSystemModel.java index bb1c93ea..c0d1ea12 100644 --- a/src/main/java/org/bench4q/monitor/model/FileSystemModel.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/FileSystemModel.java @@ -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 caculateReadRateFuture = executorService - .submit(new CalculateDiskReadRate(interval, fileSystemUsage)); - - Future 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 { - 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 caculateReadRateFuture = executorService + .submit(new CalculateDiskReadRate(interval, fileSystemUsage)); + + Future 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 { + 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; + } + +} diff --git a/src/main/java/org/bench4q/monitor/model/ListMainModel.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ListMainModel.java similarity index 96% rename from src/main/java/org/bench4q/monitor/model/ListMainModel.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ListMainModel.java index f3ab2931..d3a87aff 100644 --- a/src/main/java/org/bench4q/monitor/model/ListMainModel.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ListMainModel.java @@ -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 historylist; - - @XmlElementWrapper(name="histories") - @XmlElement(name="history",type=MonitorMain.class) - public List getHistorylist() { - return historylist; - } - public void setHistorylist(List 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 historylist; + + @XmlElementWrapper(name="histories") + @XmlElement(name="history",type=MonitorMain.class) + public List getHistorylist() { + return historylist; + } + public void setHistorylist(List historylist) { + this.historylist = historylist; + } + +} diff --git a/src/main/java/org/bench4q/monitor/model/MemoryModel.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MemoryModel.java similarity index 96% rename from src/main/java/org/bench4q/monitor/model/MemoryModel.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MemoryModel.java index 5aafbc92..cd3854db 100644 --- a/src/main/java/org/bench4q/monitor/model/MemoryModel.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MemoryModel.java @@ -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; + } + +} diff --git a/src/main/java/org/bench4q/monitor/model/MonitorMain.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MonitorMain.java similarity index 100% rename from src/main/java/org/bench4q/monitor/model/MonitorMain.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MonitorMain.java diff --git a/src/main/java/org/bench4q/monitor/model/NetworkInterfaceModel.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/NetworkInterfaceModel.java similarity index 96% rename from src/main/java/org/bench4q/monitor/model/NetworkInterfaceModel.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/NetworkInterfaceModel.java index ee3b07d8..0c5e7c55 100644 --- a/src/main/java/org/bench4q/monitor/model/NetworkInterfaceModel.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/NetworkInterfaceModel.java @@ -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 futureBytesReceivedPerSecond = executorService - .submit(new CalculateBytesReceivedPerSecond(interval)); - - Future 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 futureBytesReceivedPerSecond = executorService + .submit(new CalculateBytesReceivedPerSecond(interval)); + + Future 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; + + } +} diff --git a/src/main/java/org/bench4q/monitor/model/PhysicalDiskModel.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/PhysicalDiskModel.java similarity index 96% rename from src/main/java/org/bench4q/monitor/model/PhysicalDiskModel.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/PhysicalDiskModel.java index b67459ea..a430faba 100644 --- a/src/main/java/org/bench4q/monitor/model/PhysicalDiskModel.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/PhysicalDiskModel.java @@ -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 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 getFieFileSystemModels() { - return fieFileSystemModels; - } - - private void setFieFileSystemModels() throws SigarException, - InterruptedException, ExecutionException { - this.fieFileSystemModels = new ArrayList(); - - Map fileSysUsageMap = this - .getFileSystemUsages(); - if (fileSysUsageMap.keySet() != null) { - List> futures = new ArrayList>(); - - for (String fileDir : fileSysUsageMap.keySet()) { - futures.add(GetThreadPool.getExecutorService().submit( - new NewFileSystemModel(fileSysUsageMap.get(fileDir), - fileDir, interval))); - - } - for (Future 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 getFileSystemUsages() - throws SigarException { - Map fileSystemUsages = new HashMap(); - 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 { - 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 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 getFieFileSystemModels() { + return fieFileSystemModels; + } + + private void setFieFileSystemModels() throws SigarException, + InterruptedException, ExecutionException { + this.fieFileSystemModels = new ArrayList(); + + Map fileSysUsageMap = this + .getFileSystemUsages(); + if (fileSysUsageMap.keySet() != null) { + List> futures = new ArrayList>(); + + for (String fileDir : fileSysUsageMap.keySet()) { + futures.add(GetThreadPool.getExecutorService().submit( + new NewFileSystemModel(fileSysUsageMap.get(fileDir), + fileDir, interval))); + + } + for (Future 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 getFileSystemUsages() + throws SigarException { + Map fileSystemUsages = new HashMap(); + 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 { + 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; + } + +} diff --git a/src/main/java/org/bench4q/monitor/model/ProcessModel.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ProcessModel.java similarity index 96% rename from src/main/java/org/bench4q/monitor/model/ProcessModel.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ProcessModel.java index 58c73317..02d39f10 100644 --- a/src/main/java/org/bench4q/monitor/model/ProcessModel.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ProcessModel.java @@ -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 processModelList; - @Expose - private long[] processPids; - @Expose - private List 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 getProcessModelList() { - return processModelList; - } - - public void setProcesModelList() throws SigarException, - InterruptedException, ExecutionException { - this.processModelList = new ArrayList(); - List> futures = new ArrayList>(); - 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 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 getProcessNameList() { - return processNameList; - } - - private void setProcessNameList() throws SigarException { - this.processNameList = new ArrayList(); - for (long pid : this.getProcessPids()) { - try { - ProcState procState = sigar.getProcState(pid); - processNameList.add(procState.getName()); - } catch (SigarException e) { - } - } - } - -} - -class NewProcessChild implements Callable { - 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 processModelList; + @Expose + private long[] processPids; + @Expose + private List 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 getProcessModelList() { + return processModelList; + } + + public void setProcesModelList() throws SigarException, + InterruptedException, ExecutionException { + this.processModelList = new ArrayList(); + List> futures = new ArrayList>(); + 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 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 getProcessNameList() { + return processNameList; + } + + private void setProcessNameList() throws SigarException { + this.processNameList = new ArrayList(); + for (long pid : this.getProcessPids()) { + try { + ProcState procState = sigar.getProcState(pid); + processNameList.add(procState.getName()); + } catch (SigarException e) { + } + } + } + +} + +class NewProcessChild implements Callable { + 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); + } + } } \ No newline at end of file diff --git a/src/main/java/org/bench4q/monitor/model/ProcessModelChild.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ProcessModelChild.java similarity index 95% rename from src/main/java/org/bench4q/monitor/model/ProcessModelChild.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ProcessModelChild.java index 84018428..d7924d71 100644 --- a/src/main/java/org/bench4q/monitor/model/ProcessModelChild.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ProcessModelChild.java @@ -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(); + } + +} diff --git a/src/main/java/org/bench4q/monitor/model/ProcessSigarReleatedModel.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ProcessSigarReleatedModel.java similarity index 100% rename from src/main/java/org/bench4q/monitor/model/ProcessSigarReleatedModel.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ProcessSigarReleatedModel.java diff --git a/src/main/java/org/bench4q/monitor/model/ProcessorModel.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ProcessorModel.java similarity index 96% rename from src/main/java/org/bench4q/monitor/model/ProcessorModel.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ProcessorModel.java index b0485076..5164418d 100644 --- a/src/main/java/org/bench4q/monitor/model/ProcessorModel.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ProcessorModel.java @@ -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 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 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 getCpuInstanceList() { - return cpuInstanceList; - } - - private void setCpuInstanceList() { - this.cpuInstanceList = new ArrayList(); - - 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 getProcessorModelList() { - return processorModelList; - } - - private void setPorcessorModelList() throws SigarException { - this.processorModelList = new ArrayList(); - CpuPerc[] cpuPercList = sigar.getCpuPercList(); - List> futures = new ArrayList>(); - for (int i = 0; i < cpuPercList.length; ++i) { - futures.add(GetThreadPool.getExecutorService().submit( - new NewProcessorModelChild(i, cpuPercList[i]))); - - } - for (Future 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 { - 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 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 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 getCpuInstanceList() { + return cpuInstanceList; + } + + private void setCpuInstanceList() { + this.cpuInstanceList = new ArrayList(); + + 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 getProcessorModelList() { + return processorModelList; + } + + private void setPorcessorModelList() throws SigarException { + this.processorModelList = new ArrayList(); + CpuPerc[] cpuPercList = sigar.getCpuPercList(); + List> futures = new ArrayList>(); + for (int i = 0; i < cpuPercList.length; ++i) { + futures.add(GetThreadPool.getExecutorService().submit( + new NewProcessorModelChild(i, cpuPercList[i]))); + + } + for (Future 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 { + 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); + } } \ No newline at end of file diff --git a/src/main/java/org/bench4q/monitor/model/ProcessorModelChild.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ProcessorModelChild.java similarity index 96% rename from src/main/java/org/bench4q/monitor/model/ProcessorModelChild.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ProcessorModelChild.java index d56adb08..622a26b9 100644 --- a/src/main/java/org/bench4q/monitor/model/ProcessorModelChild.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/ProcessorModelChild.java @@ -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; + } +} diff --git a/src/main/java/org/bench4q/monitor/model/SystemModel.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/SystemModel.java similarity index 96% rename from src/main/java/org/bench4q/monitor/model/SystemModel.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/SystemModel.java index f816ffc6..f4adb423 100644 --- a/src/main/java/org/bench4q/monitor/model/SystemModel.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/SystemModel.java @@ -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; + } + +} diff --git a/src/main/java/org/bench4q/monitor/service/DataFomat.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/service/DataFomat.java similarity index 96% rename from src/main/java/org/bench4q/monitor/service/DataFomat.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/service/DataFomat.java index 204ef7d1..a605d46e 100644 --- a/src/main/java/org/bench4q/monitor/service/DataFomat.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/service/DataFomat.java @@ -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; + } +} diff --git a/src/main/java/org/bench4q/monitor/service/GetSigar.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/service/GetSigar.java similarity index 93% rename from src/main/java/org/bench4q/monitor/service/GetSigar.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/service/GetSigar.java index 64fb7e04..297eb9ec 100644 --- a/src/main/java/org/bench4q/monitor/service/GetSigar.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/service/GetSigar.java @@ -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; + } + +} diff --git a/src/main/java/org/bench4q/monitor/service/GetThreadPool.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/service/GetThreadPool.java similarity index 96% rename from src/main/java/org/bench4q/monitor/service/GetThreadPool.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/service/GetThreadPool.java index 5b2e30b3..5ab97f1b 100644 --- a/src/main/java/org/bench4q/monitor/service/GetThreadPool.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/service/GetThreadPool.java @@ -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(); + } +} diff --git a/src/main/java/org/bench4q/monitor/service/ReadSystemInfoFromLocalDisk.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/service/ReadSystemInfoFromLocalDisk.java similarity index 100% rename from src/main/java/org/bench4q/monitor/service/ReadSystemInfoFromLocalDisk.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/service/ReadSystemInfoFromLocalDisk.java diff --git a/src/main/java/org/bench4q/monitor/service/TimerService.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/service/TimerService.java similarity index 96% rename from src/main/java/org/bench4q/monitor/service/TimerService.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/service/TimerService.java index a718f142..7f216e0c 100644 --- a/src/main/java/org/bench4q/monitor/service/TimerService.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/service/TimerService.java @@ -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(); + } + } + +} diff --git a/src/main/java/org/bench4q/monitor/service/WriteSystemInfoToLocalDisk.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/service/WriteSystemInfoToLocalDisk.java similarity index 100% rename from src/main/java/org/bench4q/monitor/service/WriteSystemInfoToLocalDisk.java rename to Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/service/WriteSystemInfoToLocalDisk.java diff --git a/src/main/resources/log4j.properties b/Bench4Q-Monitor-Sigar/src/main/resources/log4j.properties similarity index 100% rename from src/main/resources/log4j.properties rename to Bench4Q-Monitor-Sigar/src/main/resources/log4j.properties diff --git a/src/main/resources/org/bench4q/monitor/config/application-context.xml b/Bench4Q-Monitor-Sigar/src/main/resources/org/bench4q/monitor/config/application-context.xml similarity index 98% rename from src/main/resources/org/bench4q/monitor/config/application-context.xml rename to Bench4Q-Monitor-Sigar/src/main/resources/org/bench4q/monitor/config/application-context.xml index 909a7298..6c72d7ff 100644 --- a/src/main/resources/org/bench4q/monitor/config/application-context.xml +++ b/Bench4Q-Monitor-Sigar/src/main/resources/org/bench4q/monitor/config/application-context.xml @@ -1,10 +1,10 @@ - - - - - + + + + + diff --git a/license.txt b/license.txt deleted file mode 100644 index 33e77493..00000000 --- a/license.txt +++ /dev/null @@ -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. \ No newline at end of file