controller->tools->options
可知如下为每3秒采样一次。
等价
iostat –d 3 n 输出的tps
或者iostat –x 3 中的 r/s+w/s
源码分析
http://nchc.dl.sourceforge.net/sourceforge/rstatd/rpc.rstatd-4.0.1.tar.gz下载
getdata.c ->函数getdata_setup,划分不同的版本如get_disk24
unsigned long long rio;
unsigned long long wio;
char line[1024];
char device[128];
int diskno;
/* open the /proc/partitions file */
partitions = fopen("/proc/partitions", "r");
if (NULL == partitions) {
return;
}
/* skip two lines */
fgets(buffer, sizeof(buffer), partitions); /* 1. line */
fgets(buffer, sizeof(buffer), partitions); /* 2. line */
/* accumulate all the io statistics */
diskno = 0;
while ((diskno < 4) && (line == fgets(line, sizeof(line), partitions))) {
sscanf(line, " %*d %*d %*d %s "
"%lld %*d %*d %*d "
"%lld %*d %*d %*d "
"%*d %*d %*d\n",
device, &rio, &wio);
if (isdisk(device)) {
s->dk_xfer[diskno++] = rio + wio;
}
}
输出如:major minor #blocks name rio rmerge rsect ruse wio wmerge wsect wuse running use aveq
8 0 143114240 sda 20157282 76396662 781266460 1674746 51521287 557414054 576721790 18033503 0 16683724 23108039
8 1 104391 sda1 420 989 2818 1640 412 387 1598 22310 0 20060 23950
8 2 4192965 sda2 1693441 294 13549472 5620720 1368359 1659202 24230064 28566661 0 9972060 34221911
8 3 138809632 sda3 18463289 76394995 767713138 39002769 50152516 555754465 552490128 32396225 0 7951734 31784871
故device, &rio, &wio分别取
name rio wio。这些值都是read io/write operations since boot以来的值。To compute the io statistics for a disk, use the rio and wio operations,
as they are closest to what we used to know as unix io operations. Use
the wsect and rsect numbers to report block reads/writes.
rio完成的读 I/O 设备总次数。指真正向 I/O 设备发起并完成的读操作数目,
也就是那些放到 I/O 队列中的读请求。注意很多进程发起的读操作
(read())很可能会和其他的操作进行 merge,不一定每个 read() 调用
都引起一个 I/O 请求。