I want to write a script that will kill my processes when my machine is doing "too much" swapping of process memory from disk to memory.
What is the best way to determine that? I saw top has %wa and iostat has iowait data. vmstat has swap in and swap out.
Can that be used as a metric? What is the best for me? can someone recommend something else?


Several methods and you have described them yourself.

First, top - see the cpu load and where the load is. If most of the CPU time is burning at %sys, it is some kind of system activity. Check the memory usage also, if most of the memory is in swapped state, then a continuous high cpu %sys means thrashing situation.

Next, vmstat. you know the fields to monitor.

For historical data, use sar. Again, see the column where cpu time is being burnt.

mpstat will also show the cpu usage condition.

To sum up, lots of tools are there and you can easily filter out specific field you need with some awk, cut, sort.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.