常用的命令为 iostat -xk
x参数表示返回全部参数
k参数表示返回的数据单位为kb
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await svctm %util
vda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
vdb 0.00 0.00 0.00 71.00 0.00 284.00 8.00 0.07 0.96 0.04 0.30
每一列的内容分别为:
如果需要获取实时数值 还需要再加两个参数
iostat -xk 10 2
10表示: 采样间隔为10秒
2表示 : 采集两次(第一次为总的,等同于直接调用 iostat -xk, 因此要获取实时数值这个参数至少传2 )
rrqm/s: 每秒对该设备的读请求被合并次数,文件系统会对读取同块(block)的请求进行合并
wrqm/s: 每秒对该设备的写请求被合并次数
r/s: 每秒完成的读次数
w/s: 每秒完成的写次数
rkB/s: 每秒读数据量(kB为单位)
wkB/s: 每秒写数据量(kB为单位)
avgrq-sz:平均每次IO操作的数据量(扇区数为单位)
avgqu-sz: 平均等待处理的IO请求队列长度
await: 平均每次IO请求等待时间(包括等待时间和处理时间,毫秒为单位)
svctm: 平均每次IO请求的处理时间(毫秒为单位)
%util: 采用周期内用于IO操作的时间比率,即IO队列非空的时间比率
2、提取
这里针对实现了两个C++的函数
首先将返回值按行分割开,可以用这个方法:
void SplitString(const std::string& s, std::vector<std::string>& v, const std::string& c)
{
std::string::size_type pos1, pos2;
pos2 = s.find(c);
pos1 = 0;
while(std::string::npos != pos2) {
v.push_back(s.substr(pos1, pos2-pos1));
pos1 = pos2 + c.size();
pos2 = s.find(c, pos1);
}
if(pos1 != s.length()) {
v.push_back(s.substr(pos1));
}
}分割之后每一行的提取就比较麻烦了,因为这些数值之间都是用不等数目的空格进行分割的,因此实现一个方法:
/* 读取字符串,提取其中的所有数字(包括小数) */
std::vector<double> digDigit(const std::string& src) {
std::vector<double> ret;
std::string num = "";
bool hasPoint = false;
for(std::string::const_iterator s_it = src.begin(); s_it != src.end(); ++s_it) {
char cur = *s_it;
if( (cur >= '0' && cur <= '9') || cur == '.') {
if(cur == '.') { // 小数点
if(hasPoint) {
num = "";
continue;
}else {
hasPoint = true;
num += cur;
}
}else { // 数字
num += cur;
}
}else {
if(num != "") {
// std::cout << num << std::endl;
ret.push_back(atof(num.c_str()));
hasPoint = false;
num = "";
}
}
}
if(num != "") {
// std::cout << num << std::endl;
ret.push_back(atof(num.c_str()));
}
return ret;
}原文地址:http://blog.51cto.com/zhweizhi/2073692