From e19a82b626a24d9698d30aacbfabad0c06709f27 Mon Sep 17 00:00:00 2001 From: fanfuxiaoran <495538672@qq.com> Date: Mon, 19 Aug 2013 17:41:29 +0800 Subject: [PATCH] add the LogicalDisk to Linux --- .../model/NetworkInterfaceModelChild.java | 18 ++++ .../performance/linux/LogicalDiskMonitor.java | 85 +++++++++---------- .../linux/NetworkInterfaceServiceLinux.java | 5 ++ .../NetworkInterfaceServiceWindows.java | 2 + 4 files changed, 66 insertions(+), 44 deletions(-) create mode 100644 src/main/java/org/bench4q/monitor/service/linux/NetworkInterfaceServiceLinux.java diff --git a/src/main/java/org/bench4q/monitor/model/NetworkInterfaceModelChild.java b/src/main/java/org/bench4q/monitor/model/NetworkInterfaceModelChild.java index 1b3241cf..a2d91ed7 100644 --- a/src/main/java/org/bench4q/monitor/model/NetworkInterfaceModelChild.java +++ b/src/main/java/org/bench4q/monitor/model/NetworkInterfaceModelChild.java @@ -5,6 +5,24 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class NetworkInterfaceModelChild { private double bytesTotalPerSecond; +private double bytesReceivedPerSecond; +private double bytesSentPerSecond; +public double getBytesReceivedPerSecond() { + return bytesReceivedPerSecond; +} + +public void setBytesReceivedPerSecond(double bytesReceivedPerSecond) { + this.bytesReceivedPerSecond = bytesReceivedPerSecond; +} + +public double getBytesSentPerSecond() { + return bytesSentPerSecond; +} + +public void setBytesSentPerSecond(double bytesSentPerSecond) { + this.bytesSentPerSecond = bytesSentPerSecond; +} + private String instance; public String getInstance() { return instance; diff --git a/src/main/java/org/bench4q/monitor/performance/linux/LogicalDiskMonitor.java b/src/main/java/org/bench4q/monitor/performance/linux/LogicalDiskMonitor.java index 9757fecb..194db99b 100644 --- a/src/main/java/org/bench4q/monitor/performance/linux/LogicalDiskMonitor.java +++ b/src/main/java/org/bench4q/monitor/performance/linux/LogicalDiskMonitor.java @@ -25,24 +25,26 @@ public class LogicalDiskMonitor extends LinuxFileRead { freeSpacePercent = new HashMap(); freeMegabytes = new HashMap(); - // ���̻�ٷֱ� + // 锟斤拷锟教活动锟劫分憋拷 diskTimePercent = new HashMap(); diskReadTimePercent = new HashMap(); diskWriteTimePercent = new HashMap(); - // ����ƽ��ʱ�� + // 锟斤拷锟斤拷平锟斤拷疃憋拷锟� averageDiskTransferTimeInSecond = new HashMap(); averageDiskReadTimeInSecond = new HashMap(); averageDiskWriteTimeInSecond = new HashMap(); - // ����ƽ������ֽ� + // 锟斤拷锟斤拷平锟斤拷锟斤拷锟斤拷纸锟� diskBytesPerSecond = new HashMap(); diskReadBytesPerSecond = new HashMap(); diskWriteBytesPerSecond = new HashMap(); idleTimePercent = new HashMap(); - // ƽ����г��� + // 平锟斤拷锟斤拷谐锟斤拷锟� averageDiskQueueLength = new HashMap(); - // ��ǰ���г��� + // 锟斤拷前锟斤拷锟叫筹拷锟斤拷 currentDiskQueueLength = new HashMap(); + + } @@ -142,25 +144,28 @@ public class LogicalDiskMonitor extends LinuxFileRead { private Map freeSpacePercent; private Map freeMegabytes; - // ���̻�ٷֱ� + // 锟斤拷锟教活动锟劫分憋拷 private Map diskTimePercent; private Map diskReadTimePercent; private Map diskWriteTimePercent; - // ����ƽ��ʱ�� + // 锟斤拷锟斤拷平锟斤拷疃憋拷锟� private Map averageDiskTransferTimeInSecond; private Map averageDiskReadTimeInSecond; private Map averageDiskWriteTimeInSecond; - // ����ƽ������ֽ� + + // 锟斤拷锟斤拷平锟斤拷锟斤拷锟斤拷纸锟� private Map diskBytesPerSecond; private Map diskReadBytesPerSecond;; private Map diskWriteBytesPerSecond; - // ���аٷֱ� + + // 锟斤拷锟叫百分憋拷 private Map idleTimePercent; - // ƽ����г��� + // 平锟斤拷锟斤拷谐锟斤拷锟� private Map averageDiskQueueLength; - // ��ǰ���г��� + // 锟斤拷前锟斤拷锟叫筹拷锟斤拷 + private Map currentDiskQueueLength; public LogicalDiskModel getLogicalDiskInfo(int idleTime) @@ -186,32 +191,27 @@ public class LogicalDiskMonitor extends LinuxFileRead { str = token.nextToken(); String elem = str; - instances_temp.add(elem);// 分区名字 - str = token.nextToken();// 第1个域:读磁盘的次数,成功完成读的总次数。 + instances_temp.add(elem);// 鍒嗗尯鍚嶅瓧 + str = token.nextToken();// 绗�涓煙锛氳纾佺洏鐨勬鏁帮紝鎴愬姛瀹屾垚璇荤殑鎬绘鏁般� readTimes.put(elem, (double)Integer.parseInt(str)); - str = token.nextToken();// 第2个域:合并读次数, field 6 – - // 合并写次数。为了效率可能会合并相邻的读和写。从而两次4K的读在它最终被处理到磁盘上之前可能会变成一次8K的读,才被计数(和排队),因此只有一次I/O操作。这个域使你知道这样的操作有多频繁。 + str = token.nextToken();// 绗�涓煙锛氬悎骞惰娆℃暟锛�field 6 鈥� // 鍚堝苟鍐欐鏁般�涓轰簡鏁堢巼鍙兘浼氬悎骞剁浉閭荤殑璇诲拰鍐欍�浠庤�涓ゆ4K鐨勮鍦ㄥ畠鏈�粓琚鐞嗗埌纾佺洏涓婁箣鍓嶅彲鑳戒細鍙樻垚涓�8K鐨勮锛屾墠琚鏁帮紙鍜屾帓闃燂級锛屽洜姝ゅ彧鏈変竴娆/O鎿嶄綔銆傝繖涓煙浣夸綘鐭ラ亾杩欐牱鐨勬搷浣滄湁澶氶绻併� - str = token.nextToken();// 第3个域:读扇区的次数,成功读过的扇区总次数。 - secRead.put(elem, (double)Integer.parseInt(str)); - str = token.nextToken();// 第4个域:读花费的毫秒数,这是所有读操作所花费的毫秒数(用__make_request()到end_that_request_last()测量)。 + str = token.nextToken();// 绗�涓煙锛氳鎵囧尯鐨勬鏁帮紝鎴愬姛璇昏繃鐨勬墖鍖烘�娆℃暟銆� secRead.put(elem, (double)Integer.parseInt(str)); + str = token.nextToken();// 绗�涓煙锛氳鑺辫垂鐨勬绉掓暟锛岃繖鏄墍鏈夎鎿嶄綔鎵�姳璐圭殑姣鏁帮紙鐢╛_make_request()鍒癳nd_that_request_last()娴嬮噺锛夈� readTmie.put(elem,(double) Integer.parseInt(str));// ms - str = token.nextToken();// 第5个域:写完成的次数,成功写完成的总次数。 + str = token.nextToken();// 绗�涓煙锛氬啓瀹屾垚鐨勬鏁帮紝鎴愬姛鍐欏畬鎴愮殑鎬绘鏁般� str=token.nextToken(); writeTimes.put(elem, (double)Integer.parseInt(str)); - str = token.nextToken();// 第7个域:写扇区的次数,成功写扇区总次数。 - secWrite.put(elem, (double)Integer.parseInt(str)); - str = token.nextToken();// 第8个域:写花费的毫秒数,这是所有写操作所花费的毫秒数(用__make_request()到end_that_request_last()测量)。 + str = token.nextToken();// 绗�涓煙锛氬啓鎵囧尯鐨勬鏁帮紝鎴愬姛鍐欐墖鍖烘�娆℃暟銆� secWrite.put(elem, (double)Integer.parseInt(str)); + str = token.nextToken();// 绗�涓煙锛氬啓鑺辫垂鐨勬绉掓暟锛岃繖鏄墍鏈夊啓鎿嶄綔鎵�姳璐圭殑姣鏁帮紙鐢╛_make_request()鍒癳nd_that_request_last()娴嬮噺锛夈� writeTime.put(elem, (double)Integer.parseInt(str)); - str = token.nextToken();// 第9个域:I/O的当前进度,只有这个域应该是0。当请求被交给适当的request_queue_t时增加和请求完成时减小。 + str = token.nextToken();// 绗�涓煙锛欼/O鐨勫綋鍓嶈繘搴︼紝鍙湁杩欎釜鍩熷簲璇ユ槸0銆傚綋璇锋眰琚氦缁欓�褰撶殑request_queue_t鏃跺鍔犲拰璇锋眰瀹屾垚鏃跺噺灏忋� currentDiskQueueLength_p.put(elem, (double) Integer.parseInt(str)); - str = token.nextToken();// 第10个域:花在I/O操作上的毫秒数,这个域会增长只要field - // 9不为0。 - - str = token.nextToken();// 第11个域:加权,花在I/O操作上的毫秒数,在每次I/O开始,I/O结束,I/O合并时这个域都会增加。这可以给I/O完成时间和存储那些可以累积的提供一个便利的测量标准 - + str = token.nextToken();// 绗�0涓煙锛氳姳鍦↖/O鎿嶄綔涓婄殑姣鏁帮紝杩欎釜鍩熶細澧為暱鍙field + // 9涓嶄负0銆� + str = token.nextToken();// 绗�1涓煙锛氬姞鏉冿紝鑺卞湪I/O鎿嶄綔涓婄殑姣鏁帮紝鍦ㄦ瘡娆/O寮�锛孖/O缁撴潫锛孖/O鍚堝苟鏃惰繖涓煙閮戒細澧炲姞銆傝繖鍙互缁橧/O瀹屾垚鏃堕棿鍜屽瓨鍌ㄩ偅浜涘彲浠ョ疮绉殑鎻愪緵涓�釜渚垮埄鐨勬祴閲忔爣鍑� } } @@ -228,39 +228,36 @@ public class LogicalDiskMonitor extends LinuxFileRead { if (!(str.equals("0"))) { str = token.nextToken(); String elem = str; - str = token.nextToken();// 第1个域:读磁盘的次数,成功完成读的总次数。 + str = token.nextToken();// 绗�涓煙锛氳纾佺洏鐨勬鏁帮紝鎴愬姛瀹屾垚璇荤殑鎬绘鏁般� readTimes.put(elem, (double)(Integer.parseInt(str) - readTimes.get(elem))); - str = token.nextToken();// 第2个域:合并读次数, field 6 – - // 合并写次数。为了效率可能会合并相邻的读和写。从而两次4K的读在它最终被处理到磁盘上之前可能会变成一次8K的读,才被计数(和排队),因此只有一次I/O操作。这个域使你知道这样的操作有多频繁。 + str = token.nextToken();// 绗�涓煙锛氬悎骞惰娆℃暟锛�field 6 鈥� // 鍚堝苟鍐欐鏁般�涓轰簡鏁堢巼鍙兘浼氬悎骞剁浉閭荤殑璇诲拰鍐欍�浠庤�涓ゆ4K鐨勮鍦ㄥ畠鏈�粓琚鐞嗗埌纾佺洏涓婁箣鍓嶅彲鑳戒細鍙樻垚涓�8K鐨勮锛屾墠琚鏁帮紙鍜屾帓闃燂級锛屽洜姝ゅ彧鏈変竴娆/O鎿嶄綔銆傝繖涓煙浣夸綘鐭ラ亾杩欐牱鐨勬搷浣滄湁澶氶绻併� - str = token.nextToken();// 第3个域:读扇区的次数,成功读过的扇区总次数。 + str = token.nextToken();// 绗�涓煙锛氳鎵囧尯鐨勬鏁帮紝鎴愬姛璇昏繃鐨勬墖鍖烘�娆℃暟銆� secRead.put(elem, Integer.parseInt(str) - secRead.get(elem)); - str = token.nextToken();// 第4个域:读花费的毫秒数,这是所有读操作所花费的毫秒数(用__make_request()到end_that_request_last()测量)。 + str = token.nextToken();// 绗�涓煙锛氳鑺辫垂鐨勬绉掓暟锛岃繖鏄墍鏈夎鎿嶄綔鎵�姳璐圭殑姣鏁帮紙鐢╛_make_request()鍒癳nd_that_request_last()娴嬮噺锛夈� readTmie.put(elem, Integer.parseInt(str) - readTmie.get(elem));// ms - str = token.nextToken();// 第5个域:写完成的次数,成功写完成的总次数。 + str = token.nextToken();// 绗�涓煙锛氬啓瀹屾垚鐨勬鏁帮紝鎴愬姛鍐欏畬鎴愮殑鎬绘鏁般� writeTimes.put(elem, Integer.parseInt(str) - writeTimes.get(elem)); - str=token.nextToken();//第6个域:合并写完成次数 -----合并写次数。 - str = token.nextToken();// 第7个域:写扇区的次数,成功写扇区总次数。 + str=token.nextToken();//绗�涓煙锛氬悎骞跺啓瀹屾垚娆℃暟 -----鍚堝苟鍐欐鏁般� + str = token.nextToken();// 绗�涓煙锛氬啓鎵囧尯鐨勬鏁帮紝鎴愬姛鍐欐墖鍖烘�娆℃暟銆� secWrite.put(elem, Integer.parseInt(str) - secWrite.get(elem)); - str = token.nextToken();// 第8个域:写花费的毫秒数,这是所有写操作所花费的毫秒数(用__make_request()到end_that_request_last()测量)。 + str = token.nextToken();// 绗�涓煙锛氬啓鑺辫垂鐨勬绉掓暟锛岃繖鏄墍鏈夊啓鎿嶄綔鎵�姳璐圭殑姣鏁帮紙鐢╛_make_request()鍒癳nd_that_request_last()娴嬮噺锛夈� writeTime.put(elem, Integer.parseInt(str) - writeTime.get(elem)); - str = token.nextToken();// 第9个域:I/O的当前进度,只有这个域应该是0。当请求被交给适当的request_queue_t时增加和请求完成时减小。 + str = token.nextToken();// 绗�涓煙锛欼/O鐨勫綋鍓嶈繘搴︼紝鍙湁杩欎釜鍩熷簲璇ユ槸0銆傚綋璇锋眰琚氦缁欓�褰撶殑request_queue_t鏃跺鍔犲拰璇锋眰瀹屾垚鏃跺噺灏忋� currentDiskQueueLength_temp.put(elem, (double) Integer.parseInt(str)); - str = token.nextToken();// 第10个域:花在I/O操作上的毫秒数,这个域会增长只要field - // 9不为0。 - - str = token.nextToken();// 第11个域:加权,花在I/O操作上的毫秒数,在每次I/O开始,I/O结束,I/O合并时这个域都会增加。这可以给I/O完成时间和存储那些可以累积的提供一个便利的测量标准 - + str = token.nextToken();// 绗�0涓煙锛氳姳鍦↖/O鎿嶄綔涓婄殑姣鏁帮紝杩欎釜鍩熶細澧為暱鍙field + // 9涓嶄负0銆� + str = token.nextToken();// 绗�1涓煙锛氬姞鏉冿紝鑺卞湪I/O鎿嶄綔涓婄殑姣鏁帮紝鍦ㄦ瘡娆/O寮�锛孖/O缁撴潫锛孖/O鍚堝苟鏃惰繖涓煙閮戒細澧炲姞銆傝繖鍙互缁橧/O瀹屾垚鏃堕棿鍜屽瓨鍌ㄩ偅浜涘彲浠ョ疮绉殑鎻愪緵涓�釜渚垮埄鐨勬祴閲忔爣鍑� } } @@ -268,7 +265,7 @@ public class LogicalDiskMonitor extends LinuxFileRead { Runtime rt = Runtime.getRuntime(); Integer time = new Integer(idleTime); - Process p = rt.exec("df -hl ");// df -hl 查看硬盘空间 + Process p = rt.exec("df -hl ");// df -hl 鏌ョ湅纭洏绌洪棿 BufferedReader in = new BufferedReader(new InputStreamReader( p.getInputStream())); diff --git a/src/main/java/org/bench4q/monitor/service/linux/NetworkInterfaceServiceLinux.java b/src/main/java/org/bench4q/monitor/service/linux/NetworkInterfaceServiceLinux.java new file mode 100644 index 00000000..6fd1f546 --- /dev/null +++ b/src/main/java/org/bench4q/monitor/service/linux/NetworkInterfaceServiceLinux.java @@ -0,0 +1,5 @@ +package org.bench4q.monitor.service.linux; + +public class NetworkInterfaceServiceLinux { + +} diff --git a/src/main/java/org/bench4q/monitor/service/windows/NetworkInterfaceServiceWindows.java b/src/main/java/org/bench4q/monitor/service/windows/NetworkInterfaceServiceWindows.java index 4540c708..f2e73e9a 100644 --- a/src/main/java/org/bench4q/monitor/service/windows/NetworkInterfaceServiceWindows.java +++ b/src/main/java/org/bench4q/monitor/service/windows/NetworkInterfaceServiceWindows.java @@ -29,6 +29,8 @@ public class NetworkInterfaceServiceWindows { networkInterfaceModelChild.setBytesTotalPerSecond(this .getNetworkInterfaceMonitor().getBytesTotalPerSecond(elem, idleTime)); + networkInterfaceModelChild.setBytesReceivedPerSecond(this.getNetworkInterfaceMonitor().getBytesReceivedPerSecond(elem, idleTime)); + networkInterfaceModelChild.setBytesSentPerSecond(this.getNetworkInterfaceMonitor().getBytesSentPerSecond(elem, idleTime)); networkInterfaceModel.getNetworkList().add(networkInterfaceModelChild); } return networkInterfaceModel;