Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to measure the total amount of disk writing and reading that is done to a particular volume by a particular process over a specified duration.

I've found iotop, which can output IO every second for a particular process like this:

iotop --batch --pid $(pidof my_process)

Where you can specify x iterations with -n x.

But then I have to filter out the actual number, and tally it up myself.

Is there an easier way to do this?

share|improve this question
2  
Next time tell us the platform :) You might consider editing this question to say it has to work on a Nokia n810 .... –  Tim Post Oct 7 '09 at 18:26

3 Answers 3

up vote 6 down vote accepted

Don't know of an easier way off hand, but this bash snippet might help you with parsing out what you need from iotop:

iotop --batch --pid 1 > log
line_num=0
while read line; do 
    line_num=$(($line_n+1)) 
    if [[ $(($line_num % 3)) -eq 0 ]]; then 
        #print Column 3
        echo $line | awk '{print $3}'
    fi 
done < log > processed_file
#Get total of column three:
cat processed_file | (tr '\n' +; echo 0) | bc

Actually, Might be easier to read /proc/$PID/io every x seconds:

val=0
total=0
counter=0
pid=2323
while [[ $counter < 100 ]]; do 
    counter=$(($counter +1 ))
    #Change the sed number for different line, 5 is read_bytes
    val=$(cat /proc/$pid/io | sed -n '5p' | awk '{ print $2 }')
    total=$(($total + $val))
    echo $total 
    sleep 1 
done

Actually, looks like the above script is wrong, because it seems like /proc/<pid>/io is just the total, so really, just grab it once, wait however long, grab it again, find the differnce and there is your answer. You might want to look at the source code and find out its data type to see if it eventually wraps around. Probably not a problem for a little tablet though.

share|improve this answer
    
looks like unsigned long long in my kernel. –  Kyle Brandt Oct 7 '09 at 19:10
    
This is the kind of answer this website needs: deep tech, no nonsense. It's starting to show that throwing around words like 'munin', 'ubuntu' and 'hyper-v' are the way to harvest a lot of rep real quick, but in the end, it's answers like this that make SV an interesting place. +1 dude. –  wzzrd Oct 7 '09 at 19:19
    
@Kyle Brandt: I'm doing this on a Nokia n810, which has an old kernel that doesn't have /proc/$PID/io. Do you know where else to look for these numbers? –  Neil Oct 9 '09 at 15:33
    
Afraid not, you can look at Documentation/accounting/taskstats.txt and getdelay.c in that same of the source code for whatever kernel you are using, but that is going to require you to figure out that interface, and use C. So at this point, parsing out iotop would be easier probably. –  Kyle Brandt Oct 9 '09 at 17:52
    
Or, grab the python source for io top and see if you can build something on top of that. –  Kyle Brandt Oct 9 '09 at 17:52

It might be over kill, and you might need to customize a plugin, but you could try "Munin", which is a graphing application that does just what you need.

It does not have a plugin for per process IO, but I'm sure hacking one up is not too hard. You'll then get all the added value of munin/rrdtool with avereges over day/week/year, graphing, limits, warnings, etc.

share|improve this answer
1  
+1 for Munin. Great tool. –  EEAA Oct 7 '09 at 17:45
    
Another +1 for Munin –  Tim Post Oct 7 '09 at 18:01
    
Looks good, but I have to do this on a Nokia n810 which is pretty limited. I think I'll write a Perl script to filter iotop output. –  Neil Oct 7 '09 at 18:10

You can install sysstat with apt-get in most Debian-based distros, including Maemo, and run iostat to monitor disk read/write totals.

Just make sure nothing else is writing to the disk, which may or may not be possible in your situation.

iostat prints total Blocks read and written since bootup, or some other arbitrary point in time. You have to figure out how big a block is to know how much data is written.

I did this by having dd write a known amount of data, and dividing the blocks.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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