一、各linux发行版本信息统计
linux发行版本中获取系统资源的文件中字段对比如下图所示:
发行版本 |
cpu |
cpu load |
net |
disk |
net_io |
memery |
内核版本 |
/proc/stat |
/proc/loadavg |
/proc/net/dev |
/etc/mtab |
/proc/diskstats |
/proc/meminfo |
||
CentOS-6.4 |
10个字段 user sys nice … |
取前3个字段 1分钟负载 5分钟负载 15分钟负载 |
字段相同,取 Receive和 Transmit 中的bytes列 |
前三列: filesystem mount on filesystem type |
14个字段,取第6和第10个字段sector read sector write |
MemTotal MemFree SwapFree |
2.6.32-358.el6.x86_64 |
CentOS-6.5 |
10个字段 |
同上 |
同上 |
同上 |
同上 |
同上 |
2.6.32-431.el6.x86_64 |
CentOS-7.0 |
10个字段 |
同上 |
同上 |
同上 |
同上 |
同上 |
3.10.0-123.el7.x86_64 |
rhel-server-5.5 |
9个字段 |
同上 |
同上 |
同上 |
同上 |
同上 |
2.6.18-194.el5 |
rhel-server-6.3 |
10个字段 |
同上 |
同上 |
同上 |
同上 |
同上 |
2.6.32-279.el6.x86_64 |
rhel-server-6.4 |
10个字段 |
同上 |
同上 |
同上 |
同上 |
同上 |
2.6.32-358.el6.x86_64 |
Ubuntu-12.04.5-server |
11个字段 |
同上 |
同上 |
同上 |
同上 |
同上 |
3.13.0-32-generic |
Ubuntu-15.05.4-server |
11个字段 |
同上 |
同上 |
同上 |
同上 |
同上 |
3.19.0-15-generic |
Ubuntu-17.05.4-server |
11个字段 |
同上 |
同上 |
同上 |
同上 |
同上 |
4.10.0-19-generic |
SLES-11-SPA |
11个字段 |
同上 |
同上 |
同上 |
同上 |
同上 |
linux-63h3 3.0.101-63-default |
二、目前问题
1、获取cpu数据
问题:/proc/stat文件字段个数不同,但是目前测试至少有9个字段。(现在程序中只读了前7个字段。)
CentOS 6.5:
user (38082) 从系统启动开始累计到当前时刻,处于用户态的运行时间,不包含 nice值为负的进程。
system (27594) 从系统启动开始累计到当前时刻,处于核心态的运行时间。
nice (627) 从系统启动开始累计到当前时刻,nice值为负的进程所占用的CPU时间。
idle (893908) 从系统启动开始累计到当前时刻,除IO等待时间以外的其它等待时间。
iowait (12256) 从系统启动开始累计到当前时刻,IO等待时间(since 2.5.41)。 内核版本
irq (581) 从系统启动开始累计到当前时刻,硬中断时间(since 2.6.0-test4)。
softirq (895) 从系统启动开始累计到当前时刻,软中断时间(since2.6.0-test4)。
stealstolen(0) which is the time spent in otheroperating systems when running in a virtualizedenvironment(since 2.6.11)。
guest(0) whichis the time spent running a virtual CPU for guest operating systems under the control ofthe Linux kernel(since 2.6.24)。
2、获取磁盘容量:
通过读取/etc/mtab文件,获取所有挂载点,然后通过java File类中函数获取挂载点的总空间和使用空间;
File file =new File(dir);
file.getTotalSpace(),file.getUsableSpace();
注:/etc/fstab /etc/mtab /proc/mounts 均可获取磁盘挂载点信息;但每当 mount挂载分区、umount 卸载分区,都会动态更新 mtab,mtab 总是保持着当前系统中已挂载的分区信息,fdisk、df 这类程序,必须要读取 mtab 文件,才能获得当前系统中的分区挂载情况。
http://www.metsky.com/archives/711.html
问题:在/etc/mtab文件中有很多虚拟文件的信息:是否需要过滤(现在将挂载点的总空间为0的挂载点过滤掉,这样获取的数据和df –h 命令得到的数据一致)
ubuntu17.04
3、获取磁盘IO
通过读取 /proc/diskstats 文件,分别获取每个磁盘一秒内的读扇区数和写扇区数(取2个时间点的数据[当前时刻和下一秒],然后做差);最后将所有的磁盘读写扇区数各自相加(一个扇区是512Byte,如果换算成KB,需要除以2,1KB=2*512Byte; 512Byte=1扇区数)
现在过滤了(loop 和ram [loop:虚拟块设备,影射正常文件,ram:将内存的一部分当做磁盘来用])
计算方法参照:
http://www.360doc.com/content/14/0603/14/14935022_383255906.shtml
问题: 现在的程序获取到的磁盘1秒内的读写量(单位:KB)与IOstat 命令1秒内的数据统计(iostat -k 1)基本一致,但是与zabbix的统计是不同的。
目前,cpu使用率,网络IO速率,磁盘IO速率都是通过sleep(1000) 获取的,用采集器每隔20s获取一次的方式会存在数据丢失。
三、java实现
package com.yoyosys.crawler.system_info;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;
import com.alibaba.fastjson.JSON;
import com.yoyosys.crawler.DataObject;
/**
* 取得linux系统下的cpu、内存信息
*/
public final class LinuxSystemTool {
private static Logger log = Logger.getLogger(LinuxSystemTool.class);
// private final static float TotalBandwidth = 1000; //网口带宽,Mbps
private static LinuxSystemTool linuxSystemTool = new LinuxSystemTool();
public static LinuxSystemTool getInstance(){
return linuxSystemTool;
}
public static int[] getMemInfo(List<DataObject> list) throws IOException, InterruptedException {
File file = new File("/proc/meminfo");
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(file)));
int[] result = new int[4];
String str = null;
StringTokenizer token = null;
while ((str = br.readLine()) != null) {
token = new StringTokenizer(str);
if (!token.hasMoreTokens())
continue;
str = token.nextToken();
if (!token.hasMoreTokens())
continue;
if (str.equalsIgnoreCase("MemTotal:")){
String memtotal=token.nextToken();
result[0] = Integer.parseInt(memtotal);
DataObject memTotalData= new DataObject();
memTotalData.setClock(System.currentTimeMillis());
memTotalData.setKey("vm.memory.size[total]");
memTotalData.setValue(memtotal);
list.add(memTotalData);
} else if (str.equalsIgnoreCase("MemFree:")) {
String memFree=token.nextToken();
result[1] = Integer.parseInt(memFree);
DataObject memFreeData= new DataObject();
memFreeData.setClock(System.currentTimeMillis());
memFreeData.setKey("vm.memory.size[free]");
memFreeData.setValue(memFree);
list.add(memFreeData);
} else if (str.equalsIgnoreCase("SwapTotal:")) {
String swapTotal=token.nextToken();
result[2] = Integer.parseInt(swapTotal);
DataObject swapTotalData= new DataObject();
swapTotalData.setClock(System.currentTimeMillis());
swapTotalData.setKey("system.swap.size[,total]");
swapTotalData.setValue(swapTotal);
list.add(swapTotalData);
} else if (str.equalsIgnoreCase("SwapFree:")) {
String swapFree=token.nextToken();
result[3] = Integer.parseInt(swapFree);
DataObject swapFreeData= new DataObject();
swapFreeData.setClock(System.currentTimeMillis());
swapFreeData.setKey("system.swap.size[,free]");
swapFreeData.setValue(swapFree);
list.add(swapFreeData);
}
}
// float memUsage = 1- (float)freeMem/(float)totalMem;
float mem_pused = 1- (float)result[1]/(float)result[0];
DataObject memUsageData= new DataObject();
memUsageData.setClock(System.currentTimeMillis());
memUsageData.setKey("vm.memory.size[pused]");
memUsageData.setValue(mem_pused+"");
list.add(memUsageData);
float swap_pfree=(float)result[3]/(float)result[2];
DataObject swapUsageData= new DataObject();
swapUsageData.setClock(System.currentTimeMillis());
swapUsageData.setKey("system.swap.size[,pfree]");
swapUsageData.setValue(swap_pfree+"");
list.add(swapUsageData);
int swap_used=result[2]-result[3];
DataObject swapUsedData= new DataObject();
swapUsedData.setClock(System.currentTimeMillis());
swapUsedData.setKey("system.swap.size[,used]");
swapUsedData.setValue(swap_used+"");
list.add(swapUsedData);
int mem_used=result[0]-result[1];
DataObject memUsedData= new DataObject();
memUsedData.setClock(System.currentTimeMillis());
memUsedData.setKey("vm.memory.size[used]");
memUsedData.setValue(mem_used+"");
list.add(memUsedData);
return result;
}
/**
* 获取cpu信息
*
* @return float efficiency
* @throws IOException
* @throws InterruptedException
*/
public static float getCpuInfo(List<DataObject> list) throws IOException, InterruptedException {
File file = new File("/proc/stat");
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(file)));
StringTokenizer token = new StringTokenizer(br.readLine());
token.nextToken();
long user1 = Long.parseLong(token.nextToken());
long nice1 = Long.parseLong(token.nextToken());
long sys1 = Long.parseLong(token.nextToken());
long idle1 = Long.parseLong(token.nextToken());
long iowait1 = Long.parseLong(token.nextToken());
long irq1 = Long.parseLong(token.nextToken());
long softirq1 = Long.parseLong(token.nextToken());
Thread.sleep(1000);
br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
token = new StringTokenizer(br.readLine());
token.nextToken();
long user2 = Long.parseLong(token.nextToken());
long nice2 = Long.parseLong(token.nextToken());
long sys2 = Long.parseLong(token.nextToken());
long idle2 = Long.parseLong(token.nextToken());
long iowait2 = Long.parseLong(token.nextToken());
long irq2 = Long.parseLong(token.nextToken());
long softirq2 = Long.parseLong(token.nextToken());
float totalCpu=(user2 + nice2 + sys2 + idle2 + iowait2 +irq2 +softirq2) - (user1 + nice1
+ sys1 + idle1 + iowait1 +irq1 +softirq1);
float usageCpu=(float) ((user2 + sys2 + nice2) - (user1 + sys1 + nice1))
/ totalCpu ;
usageCpu=(totalCpu-(idle2-idle1))/totalCpu;
DataObject userData = new DataObject();
userData.setClock(System.currentTimeMillis());
userData.setKey("system.cpu.util[,user]");
userData.setValue((user2-user1)/totalCpu*100 +"");
list.add(userData);
DataObject niceData = new DataObject();
niceData.setClock(System.currentTimeMillis());
niceData.setKey("system.cpu.util[,nice]");
niceData.setValue((nice2-nice1)/totalCpu*100 +"");
list.add(niceData);
DataObject sysData = new DataObject();
sysData.setClock(System.currentTimeMillis());
sysData.setKey("system.cpu.util[,system]");
sysData.setValue( (sys2-sys1)/totalCpu*100 +"");
list.add(sysData);
DataObject idleData = new DataObject();
idleData.setClock(System.currentTimeMillis());
idleData.setKey("system.cpu.util[,idle]");
idleData.setValue( (idle2-idle1)/totalCpu*100 +"");
list.add(idleData);
DataObject iowaitData = new DataObject();
iowaitData.setClock(System.currentTimeMillis());
iowaitData.setKey("system.cpu.util[,iowait]");
iowaitData.setValue( (iowait2-iowait1)/totalCpu*100 +"");
list.add(iowaitData);
DataObject irqData = new DataObject();
irqData.setClock(System.currentTimeMillis());
irqData.setKey("system.cpu.util[,interrupt]");
irqData.setValue( (irq2-irq1)/totalCpu*100 +"");
list.add(irqData);
DataObject softirqData = new DataObject();
softirqData.setClock(System.currentTimeMillis());
softirqData.setKey("system.cpu.util[,softirq]");
softirqData.setValue( (softirq2-softirq1)/totalCpu*100 +"");
list.add(softirqData);
return 0.0f;
}
public static void getCpuLoadAvg(List<DataObject> list){
File file = new File("/proc/loadavg");
BufferedReader br;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
StringTokenizer token = new StringTokenizer(br.readLine());
DataObject oneMinuteLoad=new DataObject();
oneMinuteLoad.setClock(System.currentTimeMillis());
oneMinuteLoad.setKey("system.cpu.load[,avg1]");
oneMinuteLoad.setValue(token.nextToken());
list.add(oneMinuteLoad);
DataObject fiveMinuteLoad=new DataObject();
fiveMinuteLoad.setClock(System.currentTimeMillis());
fiveMinuteLoad.setKey("system.cpu.load[,avg5]");
fiveMinuteLoad.setValue(token.nextToken());
list.add(fiveMinuteLoad);
DataObject fifteenMinuteLoad=new DataObject();
fifteenMinuteLoad.setClock(System.currentTimeMillis());
fifteenMinuteLoad.setKey("system.cpu.load[,avg15]");
fifteenMinuteLoad.setValue(token.nextToken());
list.add(fifteenMinuteLoad);
} catch (Exception e) {
log.error("get cpu loadavg error:"+e.getMessage());
log.error("get cpu loadavg error:"+e.getLocalizedMessage());
}
}
//单位是 byte
public static float getNetInfo(List<DataObject> list) {
float netUsage = 0.0f;
Map<String,Object> mapNet=new HashMap<String,Object>();
BufferedReader in1 = null;
BufferedReader in2 = null;
try {
File file = new File("/proc/net/dev");
in1 = new BufferedReader(new InputStreamReader(
new FileInputStream(file)));
// //第一次采集流量数据
long startTime = System.currentTimeMillis();
String line = null;
long inSize1 = 0, outSize1 = 0;
in1.readLine();
in1.readLine();
//[face, |bytes, packets, errs, drop, fifo, frame, compressed, multicast|bytes, packets, errs, drop, fifo, colls, carrier, compressed]
while((line=in1.readLine()) != null){
line = line.trim();
String[] temp = line.split("\\s+");
String eth_name=temp[0].substring(0,temp[0].lastIndexOf(":"));
if(eth_name.equals("lo"))
continue;
int _index=temp[0].lastIndexOf(":");
if(temp[0].length() > _index+1){
inSize1 = Long.parseLong(temp[0].substring(temp[0].lastIndexOf(":")+1)); //Receive bytes,单位为Byte
outSize1 = Long.parseLong(temp[8]);//Transmit bytes,单位为Byte
}else{
inSize1 = Long.parseLong(temp[1]);
outSize1 = Long.parseLong(temp[9]);//Transmit bytes,单位为Byte
}
long[] size={inSize1,outSize1};
mapNet.put(eth_name, size);
}
in1.close();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
}
//第二次采集流量数据
long endTime = System.currentTimeMillis();
in2 = new BufferedReader(new InputStreamReader(
new FileInputStream(file)));
long inSize2 = 0 ,outSize2 = 0;
in2.readLine();
in2.readLine();
while((line=in2.readLine()) != null){
line = line.trim();
String[] temp = line.split("\\s+");
String eth_name=temp[0].substring(0,temp[0].lastIndexOf(":"));
if(eth_name.equals("lo"))
continue;
int _index=temp[0].lastIndexOf(":");
if(temp[0].length() > _index+1){
inSize2 = Long.parseLong(temp[0].substring(temp[0].lastIndexOf(":")+1));
outSize2 = Long.parseLong(temp[8]);
}else{
inSize2 = Long.parseLong(temp[1]);
outSize2 = Long.parseLong(temp[9]);//Transmit bytes,单位为Byte
}
long [] d =(long[]) mapNet.get(eth_name);
long inNet=d[0];
long outNet=d[1];
DataObject inNetData = new DataObject();
inNetData.setClock(System.currentTimeMillis());
inNetData.setKey("net.if.in["+eth_name+"]");
inNetData.setValue( (inSize2-inNet) +"");
list.add(inNetData);
DataObject outNetData = new DataObject();
outNetData.setClock(System.currentTimeMillis());
outNetData.setKey("net.if.out["+eth_name+"]");
outNetData.setValue( (outSize2-outNet) + "");
list.add(outNetData);
// System.out.println(inSize2 + " - " + inNet + "=" + (inSize2-inNet)/128.0); //除以128 单位KB (换算成 bps Kbps)
// outNetData.setValue( (outSize2-outNet)*8 +""); //乘以8 单位B
}
in2.close();
} catch (IOException e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
log.error("NetUsage发生InstantiationException. " + e.getMessage());
log.error(sw.toString());
} finally{
try {
if ( in1 != null ) in1.close();
if ( in2 != null ) in2.close();
} catch (IOException e) {
log.info("IOException :" + e.getMessage());
}
}
return netUsage;
}
public static void getHostStatus(List<DataObject> list){
DataObject data = new DataObject();
data.setClock(System.currentTimeMillis());
data.setKey("agent.ping");
data.setValue("1");
list.add(data);
}
public static List<DataObject> get() {
List<DataObject> list= new ArrayList<DataObject>();
//内存 cpu 网络IO 磁盘IO
try{
LinuxSystemTool.getMemInfo(list);
LinuxSystemTool.getCpuInfo(list);
LinuxSystemTool.getCpuLoadAvg(list);
LinuxSystemTool.getNetInfo(list);
LinuxSystemTool.getDiskSpace(list);
LinuxSystemTool.getIOstats(list);
LinuxSystemTool.getHostStatus(list);
}catch(Exception e){
log.error("exception:"+e.getMessage());
}
log.info(JSON.toJSONString(list, true));
return list;
}
//http://www.360doc.com/content/14/0603/14/14935022_383255906.shtml 推导公式
/*
8 0 sda 84369 44065 3313744 31078 72767 195050 2144912 56178 0 54484 87178
8 1 sda1 804 823 6430 90 11 7 72 2 0 90 91
8 2 sda2 82544 41372 3284186 30663 71229 162201 1869888 47523 0 48303 78111
8 3 sda3 863 1870 21864 290 1527 32842 274952 8653 0 6547 8941
*/
//当前单位是KB
public static void getIOstats(List <DataObject> list){
File file = new File("/proc/diskstats");
BufferedReader in1=null;
BufferedReader in2=null;
String line = null;
try {
in1 = new BufferedReader(new InputStreamReader(
new FileInputStream(file)));
try {
long tmp[]={0,0};
while((line=in1.readLine()) != null){
line = line.trim();
String [] ss = line.split("\\s+");
Pattern p = Pattern.compile("sd[a-z][0-9]\\d{0,}$|hd[a-z][0-9]\\d{0,}$");
Matcher matcher = p.matcher(ss[2]);
boolean flag=matcher.matches();
if(ss[2].contains("loop") || ss[2].contains("ram") || flag)
continue;
tmp[0]+=Long.parseLong(ss[5]);
tmp[1]+=Long.parseLong(ss[9]);
}
Thread.sleep(1000);
in2 = new BufferedReader(new InputStreamReader(
new FileInputStream(file)));
long[] tmp2={0,0};
while((line=in2.readLine()) != null){
line = line.trim();
String [] ss = line.split("\\s+");
Pattern p = Pattern.compile("sd[a-z][0-9]\\d{0,}$|hd[a-z][0-9]\\d{0,}$");
Matcher matcher = p.matcher(ss[2]);
boolean flag=matcher.matches();
if( ss[2].contains("loop") || ss[2].contains("ram") || flag)
continue;
long rd_sectors2 = Long.parseLong(ss[5]);
long wr_sectors2 = Long.parseLong(ss[9]);
tmp2[0]+=rd_sectors2;
tmp2[1]+=wr_sectors2;
}
long rd_sector = tmp2[0]-tmp[0];
long wr_sector = tmp2[1]-tmp[1];
DataObject readData = new DataObject();
readData.setClock(System.currentTimeMillis());
readData.setKey("vfs.dev.read[,,avg1]");
readData.setValue(rd_sector/2.0 +"");
list.add(readData);
DataObject writeData = new DataObject();
writeData.setClock(System.currentTimeMillis());
writeData.setKey("vfs.dev.write[,,avg1]");
writeData.setValue(wr_sector/2.0 +"");
list.add(writeData);
log.info(JSON.toJSONString(list,true));
//一个扇区是 512 Byte;re_sector wr_sector是扇区数,换算成KB,要除以2;1KB=2*512Bytess
//System.out.println(JSON.toJSONString(list,true));
} catch (Exception e) {
log.error("diskstats error:"+e.getMessage());
}finally{
try {
if ( in1 != null ) in1.close();
if ( in2 != null ) in2.close();
} catch (IOException e) {
log.info("IOException :" + e.getMessage());
}
}
} catch (FileNotFoundException e) {
log.error("diskstats exception:"+e.getMessage());
}
}
public static void getDiskSpace( List <DataObject> list) {
File file = new File("/etc/mtab");
BufferedReader in1 = null;
String line = null;
/*
* /dev/sda2 / ext4 rw 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
devpts /dev/pts devpts rw,gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs rw 0 0
/dev/sda1 /boot ext4 rw 0 0
/dev/sdb5 /data/logic ext3 rw 0 0
/dev/sdb1 /data/primary ext4 rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0
gvfs-fuse-daemon /root/.gvfs fuse.gvfs-fuse-daemon rw,nosuid,nodev 0 0
/dev/sr0 /media/VMware\040Tools iso9660 r
* 一个目录可以挂载多个分区,(一个分区挂在到多个目录中没有意义)
* */
try {
in1 = new BufferedReader(new InputStreamReader(
new FileInputStream(file)));
while((line=in1.readLine()) != null){
line = line.trim();
String [] ss = line.split("\\s+");
File ff=new File(ss[1]);
if(ss[2].contains("xfs") || ss[2].contains("ext") || ss[2].contains("btrfs")){
//long usdSpace=(long) (ff.getUsableSpace());
long freeSpace=(long)ff.getFreeSpace();
long totalSpace=(long) (ff.getTotalSpace());
DataObject totalSpaceData = new DataObject();
totalSpaceData.setClock(System.currentTimeMillis());
totalSpaceData.setKey("vfs.fs.size["+ss[1]+",total]");
totalSpaceData.setValue(totalSpace +"");
list.add(totalSpaceData);
DataObject usedSpaceData = new DataObject();
usedSpaceData.setClock(System.currentTimeMillis());
usedSpaceData.setKey("vfs.fs.size["+ss[1]+",used]");
usedSpaceData.setValue(totalSpace-freeSpace +"");
list.add(usedSpaceData);
DataObject typeFileSystemData = new DataObject();
typeFileSystemData.setClock(System.currentTimeMillis());
typeFileSystemData.setKey("fs_type_"+ss[1]);
typeFileSystemData.setValue(ss[2]);
list.add(typeFileSystemData);
DataObject pusedData = new DataObject();
pusedData.setClock(System.currentTimeMillis());
pusedData.setKey("vfs.fs.size["+ ss[1] +",pused]");
pusedData.setValue( (totalSpace-freeSpace)/(float)totalSpace +"" );
list.add(pusedData);
}
//map.put(ss[1], obj);
}
log.info(JSON.toJSONString(list,true));
//System.out.print(JSON.toJSONString(list,true));
} catch (Exception e1) {
log.info("Exception:"+e1.getMessage());
}finally{
if(in1 != null){
try {
in1.close();
} catch (IOException e) {
log.error("IOexception :"+e.getMessage());
}
}
}
}
public static void main(String[] args) throws Exception {
String tmp="";
if(args.length != 0){
tmp=args[0];
}
// tmp="diskIO";
// //内存
while(true){
//内存(读文件)-》proc/meminfo
//cpu(读文件)-》/proc/stat
//网络(读文件)-》/proc/net/dev
//磁盘-》执行命令
List<DataObject> list= new ArrayList<DataObject>();
if(tmp.equals("mem") || "".equals(tmp)){
LinuxSystemTool.getMemInfo(list);
}
if(tmp.equals("cpu") || "".equals(tmp)){
LinuxSystemTool.getCpuInfo(list);
LinuxSystemTool.getCpuLoadAvg(list);
}
if(tmp.equals("net") || "".equals(tmp)){
LinuxSystemTool.getNetInfo(list);
}
//磁盘IO 执行命令;
if(tmp.equals("disk") || "".equals(tmp) ){
LinuxSystemTool.getDiskSpace(list);
// System.out.println(JSON.toJSONString(list,true));
// break;
}
if(tmp.equals("diskIO" )|| "".equals(tmp) ){
LinuxSystemTool.getIOstats(list);
}
System.out.println(JSON.toJSONString(list,true));
}
}
}
如果通过采集器的方式每20s采集一次数据,那只能获取20s前一刻的IO速率,不具有代表性。如果这20s内有数据拷贝,IO速率信息也是统计不到的。
Cpunet IO 都会有数据丢失的问题