0

my target is to check iowait value that not higher than 50 from top command

and if value is higher than 50 for more then one hour , then need to give alarm about this ( by script or other option )

what I do until now is that:

  top-n|grepiowait
  CPUstates:94.3%idle,0.5%user,5.2%kernel,0.0%iowait,0.0%swap

I can easily to capture the iowait as the following:

 top-n|grepiowait|awk'{print$9}'|seds'/%//'
 0.0

But how to verify iowait value that higher than 50 for at least one hour?

maihabunash
  • 443
  • 1
  • 11
  • 25

2 Answers2

2

I'm sure you understand the general method of collecting the data along with the time of the collection and tracking the values over time. The specifics would be quite a complicated script and we're not a script writing service.

If you wanted to go down that route you might find sar or iostat are more useful YMMV.

However there are better tools than top for doing things like this, most people would use some sort of monitoring tool e.g. zabbix, nagios, munin etc. They will gather the statistics send alerts etc. In the case of zabbix they're even easy to install and configure.

user9517
  • 115,471
  • 20
  • 215
  • 297
1

You can use iostat for this very purpose. Simply run iostat -y 3600 | grep -A 1 avg-cpu

The above command will report each hour the various CPU states (idle, iowait, ecc) and the following grep will extrapolate only the two lines about you care. Obviously, do some tests with lower wait time (eg: 5 seconds) before putting the script into production.

EDIT: for solaris, you can use iostat -c 3600 The grep command will be different, though, so you had to test yourself.

shodanshok
  • 47,711
  • 7
  • 111
  • 180
  • what the syntax for solaris if I use iostat ? – maihabunash Jul 29 '15 at 07:31
  • See my edit above – shodanshok Jul 29 '15 at 07:51
  • What happens if the iowait goes above 50 part way through the time and remains above 50 for more than an hour then returns below 50 ? You'll miss that using this method as it's granularity is 1 hour. – user9517 Jul 29 '15 at 08:00
  • You can set the granularity as you want, by simply changing the interval time from 3600 to whatever you want. This is much cleaner than the `top` method suggested by the OP – shodanshok Jul 29 '15 at 08:08
  • Depending on the interval it's really not that much different from using top and still leaves the op having to write a script. You answer implies that using an interval of 3600 will provide the OP with exactly what they want which it won't. – user9517 Jul 29 '15 at 08:19
  • You will be **always** tied to an interval and a moving average. Heck, even the kernel do its accounting using a moving average. If you want to descent to sub-second average, you had to use some profiling tool as `perf` and the like, but this is way overkill. Using iostat vs top has the non negligible advantage to provide (if required) detailed disk I/O stats, which are invaluable to correctly understand what IOWAIT means in the specific OP context. In short, use the right tool for the right job ;) – shodanshok Jul 29 '15 at 08:58
  • On a side note: I 100% agree with you that the best tools are Zabbix and the likes. However, for a simple bash script, iostat (and sar) are as good as he can get. – shodanshok Jul 29 '15 at 09:00