Have finish the LogicalDiskModel.java and LogicalDiskController.java,

but the test has some problem.
This commit is contained in:
fanfuxiaoran 2013-07-19 16:23:15 +08:00
parent 503857de09
commit 6f437964e3
5 changed files with 160 additions and 208 deletions

View File

@ -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<String, Double> freeSpacePercent = new HashMap<String, Double>();
for (String elem : instances) {
freeSpacePercent.put(elem, this.getLogicalDiskMonitor()
.getFreeSpacePercent(elem));
}
LogicalDiskModel logicalDiskModel = new LogicalDiskModel();
logicalDiskModel.setInstances(instances);
logicalDiskModel.setFreeSpacePercent(freeSpacePercent);
return logicalDiskModel;
}
}

View File

@ -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!";
}
}

View File

@ -6,29 +6,139 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
/**
* @author wxr
*
*/
@XmlRootElement(name = "LogicalDisk") @XmlRootElement(name = "LogicalDisk")
public class LogicalDiskModel { public class LogicalDiskModel {
private String[] instances; private String[] instances;
private Map<String, Double> freeSpacePercent; private Map<String, Double> freeSpacePercent;
private Map<String, Double > freeMegabytes;
@XmlElementWrapper(name = "instanceList")
@XmlElement(name = "instance") //磁盘活动百分比
private Map<String,Double> diskTimePercent;
private Map<String,Double> diskReadTimePercent;
private Map<String,Double> diskWriteTimePercent;
//磁盘平均活动时间
private Map<String,Double> averageDiskTransferTimeInSecond;
private Map<String,Double> averageDiskReadTimeInSecond;
private Map<String,Double> averageDiskWriteTimeInSecond;
//磁盘平均处理的字节
private Map<String,Double> averageDiskBytesPerTransfer;//可计算吞吐率
private Map<String,Double> averageDiskBytesPerRead;
private Map<String,Double> averageDiskBytesPerWrite;
//空闲百分比
private Map<String,Double> idleTimePercent;
//平均队列长度
private Map<String,Double> averageDiskQueueLength;
//当前队列长度
private Map<String,Double> currentDiskQueueLength;
@XmlElementWrapper(name="InstanceList")
@XmlElement(name="Instance")
public String[] getInstances() { public String[] getInstances() {
return instances; return instances;
} }
public void setInstances(String[] instances) { public void setInstances(String[] instances) {
this.instances = instances; this.instances = instances;
} }
@XmlElement(name="FreeSpacePercent")
public Map<String, Double> getFreeSpacePercent() { public Map<String, Double> getFreeSpacePercent() {
return freeSpacePercent; return freeSpacePercent;
} }
public void setFreeSpacePercent(Map<String, Double> freeSpacePercent) { public void setFreeSpacePercent(Map<String, Double> freeSpacePercent) {
this.freeSpacePercent = freeSpacePercent; this.freeSpacePercent = freeSpacePercent;
} }
public Map<String, Double> getFreeMegabytes() {
return freeMegabytes;
}
public void setFreeMegabytes(Map<String, Double> freeMegabytes) {
this.freeMegabytes = freeMegabytes;
}
public Map<String, Double> getDiskTimePercent() {
return diskTimePercent;
}
public void setDiskTimePercent(Map<String, Double> diskTimePercent) {
this.diskTimePercent = diskTimePercent;
}
public Map<String, Double> getDiskReadTimePercent() {
return diskReadTimePercent;
}
public void setDiskReadTimePercent(Map<String, Double> diskReadTimePercent) {
this.diskReadTimePercent = diskReadTimePercent;
}
public Map<String, Double> getDiskWriteTimePercent() {
return diskWriteTimePercent;
}
public void setDiskWriteTimePercent(Map<String, Double> diskWriteTimePercent) {
this.diskWriteTimePercent = diskWriteTimePercent;
}
public Map<String, Double> getAverageDiskTransferTimeInSecond() {
return averageDiskTransferTimeInSecond;
}
public void setAverageDiskTransferTimeInSecond(
Map<String, Double> averageDiskTransferTimeInSecond) {
this.averageDiskTransferTimeInSecond = averageDiskTransferTimeInSecond;
}
public Map<String, Double> getAverageDiskReadTimeInSecond() {
return averageDiskReadTimeInSecond;
}
public void setAverageDiskReadTimeInSecond(
Map<String, Double> averageDiskReadTimeInSecond) {
this.averageDiskReadTimeInSecond = averageDiskReadTimeInSecond;
}
public Map<String, Double> getAverageDiskWriteTimeInSecond() {
return averageDiskWriteTimeInSecond;
}
public void setAverageDiskWriteTimeInSecond(
Map<String, Double> averageDiskWriteTimeInSecond) {
this.averageDiskWriteTimeInSecond = averageDiskWriteTimeInSecond;
}
public Map<String, Double> getAverageDiskBytesPerTransfer() {
return averageDiskBytesPerTransfer;
}
public void setAverageDiskBytesPerTransfer(
Map<String, Double> averageDiskBytesPerTransfer) {
this.averageDiskBytesPerTransfer = averageDiskBytesPerTransfer;
}
public Map<String, Double> getAverageDiskBytesPerRead() {
return averageDiskBytesPerRead;
}
public void setAverageDiskBytesPerRead(
Map<String, Double> averageDiskBytesPerRead) {
this.averageDiskBytesPerRead = averageDiskBytesPerRead;
}
public Map<String, Double> getAverageDiskBytesPerWrite() {
return averageDiskBytesPerWrite;
}
public void setAverageDiskBytesPerWrite(
Map<String, Double> averageDiskBytesPerWrite) {
this.averageDiskBytesPerWrite = averageDiskBytesPerWrite;
}
public Map<String, Double> getIdleTimePercent() {
return idleTimePercent;
}
public void setIdleTimePercent(Map<String, Double> idleTimePercent) {
this.idleTimePercent = idleTimePercent;
}
public Map<String, Double> getAverageDiskQueueLength() {
return averageDiskQueueLength;
}
public void setAverageDiskQueueLength(Map<String, Double> averageDiskQueueLength) {
this.averageDiskQueueLength = averageDiskQueueLength;
}
public Map<String, Double> getCurrentDiskQueueLength() {
return currentDiskQueueLength;
}
public void setCurrentDiskQueueLength(Map<String, Double> currentDiskQueueLength) {
this.currentDiskQueueLength = currentDiskQueueLength;
}
} }

View File

@ -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);*/
}
}

View File

@ -3,14 +3,20 @@ package org.bench4q.monitor.test;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import javax.naming.spi.DirStateFactory.Result;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller; import javax.xml.bind.Unmarshaller;
import org.bench4q.monitor.MonitorServer;
import org.bench4q.monitor.model.LogicalDiskModel; import org.bench4q.monitor.model.LogicalDiskModel;
import org.bench4q.monitor.test.communication.HttpRequester; import org.bench4q.monitor.test.communication.HttpRequester;
import org.bench4q.monitor.test.communication.HttpRequester.HttpResponse; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.DispatcherServlet;
public class MonitorServiceTest { public class MonitorServiceTest {
private HttpRequester httpRequester; private HttpRequester httpRequester;
@ -25,21 +31,55 @@ public class MonitorServiceTest {
} }
public static void main(String[] args) { public static void main(String[] args) {
String urlString = "http://localhost:5555/Monitor/LogicalDisk"; String urlString = "http://localhost:5555/Monitor/LogicalDisk";
MonitorServiceTest monitorServiceTest = new MonitorServiceTest(); MonitorServiceTest monitorServiceTest = new MonitorServiceTest();
try { try {
HttpResponse httpResponse = monitorServiceTest.getHttpRequester()
.sendGet(urlString, null, null);
HttpResponse httpResponse = monitorServiceTest.getHttpRequester().
sendGet(urlString, null, null);
LogicalDiskModel logicalDiskModel = monitorServiceTest LogicalDiskModel logicalDiskModel = monitorServiceTest
.extractLogicalDiskModel(httpResponse.getContent()); .extractLogicalDiskModel(httpResponse.getContent());
monitorServiceTest.result(logicalDiskModel);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (JAXBException e) { } catch (JAXBException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); 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) public LogicalDiskModel extractLogicalDiskModel(String content)