关于写一个munin插件iostat的记录

November 1st, 2007 by chifeng Leave a reply »

仅记录一下过程

0,用上了munin之后,发觉在FreeBSD下不能统计到iostat状态,便发了mail到munin-users@lists.sourceforge.net,Nicolai老大给了一个用在NetBSD下的脚本,我改了一下,可以用了,但是发现一个问题,就是iostat在FreeBSD下默认第一行输出的是一个从开机到现在的平均io值,而不是一个当前值,这不符合munin统计的要求。折腾了半天,仍然没有能够找到一个合适的命令来得到当前的iostat值。最后写了个脚本把这个拿到,放到一个临时文件,然后再通过另外一个脚本来得到这个值,看似可以了。便作罢。

1,过了2天,看到Pierre说他写了一个脚本来统计FreeBSD下的iostat,便好奇的看了一眼,发觉也是统计的系统uptime时间的平均值,便回了封邮件进行反驳。最终看起来仍然得到的不是当前值。

2,前天正好skype:delphij老大,顺便聊了这个问题,他建议我发个PR试试,发了个PR:http://www.freebsd.org/cgi/query-pr.cgi?pr=117664

3,又等了一天,Peter和John分别给我回信解释这个情况,并建议我类似bsdsar那样来做,就跟我一开始的做法差不多。呵呵,基本明白了iostat为什么要这么做,又学到了一招。

附一下邮件内容如下:
Peter
————————————————————————
This is generic, rather than amd64-specific.

I believe you misunderstand iostat.  There is no “current value” as
you desire.  There are a variety of system counters that get updated
when various events occur and iostat reports the change in those
counters over the specified interval.  The only way to determine the
system activity, averaged over two seconds, is to sample the counters,
wait two seconds, sample the counters again and reports the differences.

I suggest you start a thread on (eg) freebsd-questions explaining what
you are trying to achieve and someone there may be able to assist.

In the meantime, you might like to investigate the sysutils/bsdsar port.

John
————————————————————————
There isn’t a ‘current value’ for iostat to dump.  The kernel just keeps
running counts and iostat simulates a current value by saving the values each
time and computing a delta for each line after the first.  However, for the
first line there is no saved value so it cannot compute a delta.  Probably
you need to write your own plugin that saves the previous values and computes
deltas when queried similar to how iostat behaves.

Advertisement

Leave a Reply