From 6f437964e3b75e552611e755ed792bd6113e420a Mon Sep 17 00:00:00 2001 From: fanfuxiaoran <495538672@qq.com> Date: Fri, 19 Jul 2013 16:23:15 +0800 Subject: [PATCH] Have finish the LogicalDiskModel.java and LogicalDiskController.java, but the test has some problem. --- .../bench4q/monitor/api/MonitorControl.java | 45 ------ .../monitor/api/MonitorController.java | 17 --- .../monitor/model/LogicalDiskModel.java | 124 +++++++++++++++- src/main/java/wxr/LogicalDisk.java | 136 ------------------ .../monitor/test/MonitorServiceTest.java | 46 +++++- 5 files changed, 160 insertions(+), 208 deletions(-) delete mode 100644 src/main/java/org/bench4q/monitor/api/MonitorControl.java delete mode 100644 src/main/java/org/bench4q/monitor/api/MonitorController.java delete mode 100644 src/main/java/wxr/LogicalDisk.java diff --git a/src/main/java/org/bench4q/monitor/api/MonitorControl.java b/src/main/java/org/bench4q/monitor/api/MonitorControl.java deleted file mode 100644 index 022b7913..00000000 --- a/src/main/java/org/bench4q/monitor/api/MonitorControl.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.bench4q.monitor.api; - -import java.util.HashMap; -import java.util.Map; - -import org.bench4q.monitor.model.LogicalDiskModel; -import org.bench4q.monitor.performance.windows.LogicalDiskMonitor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -@RequestMapping("/Monitor") -public class MonitorControl { - private LogicalDiskMonitor logicalDiskMonitor; - - private LogicalDiskMonitor getLogicalDiskMonitor() { - return logicalDiskMonitor; - } - - @Autowired - private void setLogicalDiskMonitor(LogicalDiskMonitor logicalDiskMonitor) { - this.logicalDiskMonitor = logicalDiskMonitor; - } - - @RequestMapping(value = "/LogicalDisk", method = RequestMethod.GET) - @ResponseBody - public LogicalDiskModel getLogicalDiskInstances() { - String[] instances = this.getLogicalDiskMonitor().getInstances(); - Map freeSpacePercent = new HashMap(); - - for (String elem : instances) { - - freeSpacePercent.put(elem, this.getLogicalDiskMonitor() - .getFreeSpacePercent(elem)); - } - LogicalDiskModel logicalDiskModel = new LogicalDiskModel(); - logicalDiskModel.setInstances(instances); - logicalDiskModel.setFreeSpacePercent(freeSpacePercent); - return logicalDiskModel; - } - -} diff --git a/src/main/java/org/bench4q/monitor/api/MonitorController.java b/src/main/java/org/bench4q/monitor/api/MonitorController.java deleted file mode 100644 index a7851c91..00000000 --- a/src/main/java/org/bench4q/monitor/api/MonitorController.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.bench4q.monitor.api; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -@RequestMapping("/monitor") -public class MonitorController { - - @RequestMapping(method = RequestMethod.GET) - @ResponseBody - public String index() { - return "It works!"; - } -} diff --git a/src/main/java/org/bench4q/monitor/model/LogicalDiskModel.java b/src/main/java/org/bench4q/monitor/model/LogicalDiskModel.java index 07a7b99c..ac7ac1fe 100644 --- a/src/main/java/org/bench4q/monitor/model/LogicalDiskModel.java +++ b/src/main/java/org/bench4q/monitor/model/LogicalDiskModel.java @@ -6,29 +6,139 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; +/** + * @author wxr + * + */ @XmlRootElement(name = "LogicalDisk") public class LogicalDiskModel { + + private String[] instances; - private Map freeSpacePercent; - - @XmlElementWrapper(name = "instanceList") - @XmlElement(name = "instance") + private Map freeMegabytes; + + //磁盘活动百分比 + private Map diskTimePercent; + private Map diskReadTimePercent; + private Map diskWriteTimePercent; + + //磁盘平均活动时间 + private Map averageDiskTransferTimeInSecond; + private Map averageDiskReadTimeInSecond; + private Map averageDiskWriteTimeInSecond; + //磁盘平均处理的字节 + private Map averageDiskBytesPerTransfer;//可计算吞吐率 + private Map averageDiskBytesPerRead; + private Map averageDiskBytesPerWrite; + + //空闲百分比 + private Map idleTimePercent; + //平均队列长度 + private Map averageDiskQueueLength; + //当前队列长度 + private Map currentDiskQueueLength; + + @XmlElementWrapper(name="InstanceList") + @XmlElement(name="Instance") public String[] getInstances() { return instances; } - public void setInstances(String[] instances) { this.instances = instances; } + @XmlElement(name="FreeSpacePercent") public Map getFreeSpacePercent() { return freeSpacePercent; } - public void setFreeSpacePercent(Map freeSpacePercent) { this.freeSpacePercent = freeSpacePercent; } - + public Map getFreeMegabytes() { + return freeMegabytes; + } + public void setFreeMegabytes(Map freeMegabytes) { + this.freeMegabytes = freeMegabytes; + } + public Map getDiskTimePercent() { + return diskTimePercent; + } + public void setDiskTimePercent(Map diskTimePercent) { + this.diskTimePercent = diskTimePercent; + } + public Map getDiskReadTimePercent() { + return diskReadTimePercent; + } + public void setDiskReadTimePercent(Map diskReadTimePercent) { + this.diskReadTimePercent = diskReadTimePercent; + } + public Map getDiskWriteTimePercent() { + return diskWriteTimePercent; + } + public void setDiskWriteTimePercent(Map diskWriteTimePercent) { + this.diskWriteTimePercent = diskWriteTimePercent; + } + public Map getAverageDiskTransferTimeInSecond() { + return averageDiskTransferTimeInSecond; + } + public void setAverageDiskTransferTimeInSecond( + Map averageDiskTransferTimeInSecond) { + this.averageDiskTransferTimeInSecond = averageDiskTransferTimeInSecond; + } + public Map getAverageDiskReadTimeInSecond() { + return averageDiskReadTimeInSecond; + } + public void setAverageDiskReadTimeInSecond( + Map averageDiskReadTimeInSecond) { + this.averageDiskReadTimeInSecond = averageDiskReadTimeInSecond; + } + public Map getAverageDiskWriteTimeInSecond() { + return averageDiskWriteTimeInSecond; + } + public void setAverageDiskWriteTimeInSecond( + Map averageDiskWriteTimeInSecond) { + this.averageDiskWriteTimeInSecond = averageDiskWriteTimeInSecond; + } + public Map getAverageDiskBytesPerTransfer() { + return averageDiskBytesPerTransfer; + } + public void setAverageDiskBytesPerTransfer( + Map averageDiskBytesPerTransfer) { + this.averageDiskBytesPerTransfer = averageDiskBytesPerTransfer; + } + public Map getAverageDiskBytesPerRead() { + return averageDiskBytesPerRead; + } + public void setAverageDiskBytesPerRead( + Map averageDiskBytesPerRead) { + this.averageDiskBytesPerRead = averageDiskBytesPerRead; + } + public Map getAverageDiskBytesPerWrite() { + return averageDiskBytesPerWrite; + } + public void setAverageDiskBytesPerWrite( + Map averageDiskBytesPerWrite) { + this.averageDiskBytesPerWrite = averageDiskBytesPerWrite; + } + public Map getIdleTimePercent() { + return idleTimePercent; + } + public void setIdleTimePercent(Map idleTimePercent) { + this.idleTimePercent = idleTimePercent; + } + public Map getAverageDiskQueueLength() { + return averageDiskQueueLength; + } + public void setAverageDiskQueueLength(Map averageDiskQueueLength) { + this.averageDiskQueueLength = averageDiskQueueLength; + } + public Map getCurrentDiskQueueLength() { + return currentDiskQueueLength; + } + public void setCurrentDiskQueueLength(Map currentDiskQueueLength) { + this.currentDiskQueueLength = currentDiskQueueLength; + } + } diff --git a/src/main/java/wxr/LogicalDisk.java b/src/main/java/wxr/LogicalDisk.java deleted file mode 100644 index c2f5b37c..00000000 --- a/src/main/java/wxr/LogicalDisk.java +++ /dev/null @@ -1,136 +0,0 @@ -package wxr; -import java.io.File; - -import org.bench4q.monitor.Main; -import org.bench4q.monitor.performance.windows.*; - -public class LogicalDisk { - - static { - loadLibraries(); - } - - private static void loadLibraries() { - String osName = System.getProperty("os.name").toLowerCase(); - if (osName.contains("windows")) { - String directory = Main.class.getProtectionDomain().getCodeSource() - .getLocation().getFile().replace("\\", "/"); - File file = new File(directory); - if (!file.isDirectory()) { - directory = directory.substring(0, directory.lastIndexOf("/")); - if (!directory.endsWith("/")) { - directory += "/"; - } - int arch = Integer.parseInt(System - .getProperty("sun.arch.data.model")); - if (arch == 64) { - System.load(directory + "lib/x64/Monitor.dll"); - System.load(directory + "lib/x64/Native.dll"); - } else { - System.load(directory + "lib/x86/Monitor.dll"); - System.load(directory + "lib/x86/Native.dll"); - } - } else { - // In IDE - String userDir = System.getProperty("user.dir").replace("\\", - "/"); - userDir += "/WindowsMonitor"; - int arch = Integer.parseInt(System - .getProperty("sun.arch.data.model")); - if (arch == 64) { - System.load(userDir + "/x64/Release/Monitor.dll"); - System.load(userDir + "/x64/Release/Native.dll"); - } else { - System.load(userDir + "/Release/Monitor.dll"); - System.load(userDir + "/Release/Native.dll"); - } - } - } - } - - public static void main(String args[]){ - - - LogicalDiskMonitor ld=new LogicalDiskMonitor(); - - String[] instances=ld.getInstances(); - System.out.println("getInstances():"); - for(String elem:instances){ - System.out.println(elem); - } - - String[] countlist=ld.getCounterList(); - System.out.println("getCounterList():"); - for(String elem:countlist){ - System.out.println(elem); - } - - System.out.println("getFreeSpacePercent(c )"); - System.out.println(ld.getFreeSpacePercent("c:")); - - - System.out.println("getFreeMegabytes "); - System.out.println(ld.getFreeMegabytes("c:")); - - - /*public native double getFreeMegabytes(String instanceName); - - public native double getCurrentDiskQueueLength(String instanceName); - - public native double getDiskTimePercent(String instanceName, int idleTime); - - public native double getAverageDiskQueueLength(String instanceName, - idleTime); - - public native double getDiskReadTimePercent(String instanceName, - int idleTime); - - public native double getAverageDiskReadQueueLength(String instanceName, - int idleTime); - - public native double getDiskWriteTimePercent(String instanceName, - int idleTime); - - public native double getAverageDiskWriteQueueLength(String instanceName, - int idleTime); - - public native double getAverageDiskTransferTimeInSecond( - String instanceName, int idleTime); - - public native double getAverageDiskReadTimeInSecond(String instanceName, - int idleTime); - - public native double getAverageDiskWriteTimeInSecond(String instanceName, - int idleTime); - - public native double getDiskTransfersPerSecond(String instanceName, - int idleTime); - - public native double getDiskReadsPerSecond(String instanceName, int idleTime); - - public native double getDiskWritesPerSecond(String instanceName, - int idleTime); - - public native double getDiskBytesPerSecond(String instanceName, int idleTime); - - public native double getDiskReadBytesPerSecond(String instanceName, - int idleTime); - - public native double getDiskWriteBytesPerSecond(String instanceName, - int idleTime); - - public native double getAverageDiskBytesPerTransfer(String instanceName, - int idleTime); - - public native double getAverageDiskBytesPerRead(String instanceName, - int idleTime); - - public native double getAverageDiskBytesPerWrite(String instanceName, - int idleTime); - - public native double getIdleTimePercent(String instanceName, int idleTime); - - public native double getSplitIOPerSecond(String instanceName, int idleTime);*/ -} - -} diff --git a/src/test/java/org/bench4q/monitor/test/MonitorServiceTest.java b/src/test/java/org/bench4q/monitor/test/MonitorServiceTest.java index 72845d1c..981b44d0 100644 --- a/src/test/java/org/bench4q/monitor/test/MonitorServiceTest.java +++ b/src/test/java/org/bench4q/monitor/test/MonitorServiceTest.java @@ -3,14 +3,20 @@ package org.bench4q.monitor.test; import java.io.ByteArrayInputStream; import java.io.IOException; +import javax.naming.spi.DirStateFactory.Result; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; +import org.bench4q.monitor.MonitorServer; import org.bench4q.monitor.model.LogicalDiskModel; import org.bench4q.monitor.test.communication.HttpRequester; import org.bench4q.monitor.test.communication.HttpRequester.HttpResponse; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.DispatcherServlet; public class MonitorServiceTest { private HttpRequester httpRequester; @@ -25,21 +31,55 @@ public class MonitorServiceTest { } public static void main(String[] args) { + String urlString = "http://localhost:5555/Monitor/LogicalDisk"; MonitorServiceTest monitorServiceTest = new MonitorServiceTest(); try { - HttpResponse httpResponse = monitorServiceTest.getHttpRequester() - .sendGet(urlString, null, null); + + + HttpResponse httpResponse = monitorServiceTest.getHttpRequester(). + sendGet(urlString, null, null); LogicalDiskModel logicalDiskModel = monitorServiceTest .extractLogicalDiskModel(httpResponse.getContent()); - + monitorServiceTest.result(logicalDiskModel); } catch (IOException e) { e.printStackTrace(); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } + + } + + public void result(LogicalDiskModel logicalDiskModel) { + + for (String elem : logicalDiskModel.getInstances()) { + System.out.println(elem + ":"); + System.out.println("freeSpacePercent" + + logicalDiskModel.getFreeSpacePercent().get(elem)); + System.out.println("FreeMegabytes" + + logicalDiskModel.getFreeMegabytes().get(elem)); + System.out.println("diskTimePercent" + + logicalDiskModel.getDiskTimePercent().get(elem)); + System.out.println("diskReadTimePercent" + + logicalDiskModel.getDiskReadTimePercent().get(elem)); + System.out.println("diskWriteTimePercent" + + logicalDiskModel.getDiskWriteTimePercent().get(elem)); + System.out.println("averageDiskTransferTimeInSecond" + + logicalDiskModel.getAverageDiskTransferTimeInSecond().get(elem)); + System.out.println("averageDiskReadTimeInSecond" + + logicalDiskModel.getAverageDiskReadTimeInSecond().get(elem)); + System.out.println("averageDiskWriteTimeInSecond" + + logicalDiskModel.getAverageDiskWriteTimeInSecond().get(elem)); + System.out.println("averageDiskBytesPerTransfer" + + logicalDiskModel.getAverageDiskBytesPerTransfer().get(elem)); + System.out.println("averageDiskBytesPerRead" + + logicalDiskModel.getAverageDiskBytesPerRead().get(elem)); + System.out.println("averageDiskBytesPerWrite" + + logicalDiskModel.getAverageDiskBytesPerWrite().get(elem)); + } + } public LogicalDiskModel extractLogicalDiskModel(String content)