Closed GoogleCodeExporter closed 9 years ago
Keep in mind that psutil values are expressed in bytes while it seems iostat is
using... megabytes? I'm not sure.
Original comment by g.rodola
on 5 Dec 2012 at 8:06
Sorry but read_bytes can't be 95gb... or can?
>>> print 'kb: ' + str(102514605568L / 1024)
kb: 100111919
>>> print 'kb: ' + str(102514605568L / 1024 / 1024)
kb: 97765
>>> print 'mb: ' + str(102514605568L / 1024 / 1024)
mb: 97765
>>> print 'gb: ' + str(102514605568L / 1024 / 1024 / 1024)
gb: 95
Original comment by sebastia...@gmail.com
on 5 Dec 2012 at 8:16
It might be possible as they are *total cumulative* bytes since last boot.
I wrote this simple script which writes and read a 1MB file every second.
====================================================================
import psutil, time
def read():
f = open('/tmp/xxx', 'r')
f.read(99999999)
f.close()
def write():
f = open('/tmp/xxx', 'w')
f.write('x' * 1024 * 1024) # 1MB
f.flush()
f.close()
while 1:
write()
read()
io = psutil.disk_io_counters()
print "read=%sMB, written=%sMB" % (io.read_bytes / 1024 / 1024,
io.write_bytes / 1024 / 1024)
time.sleep(1)
====================================================================
Here's the output:
bash-3.2$ python foo2.py
read=499MB, written=767MB
read=499MB, written=768MB
read=499MB, written=769MB
read=499MB, written=770MB
read=499MB, written=771MB
It shows that the increment of the written bytes is very accurate, so I would
rule out a precision issue.
The read counter apparently doesn't change though, so there might be another
problem worth investigating.
After re-running the script after a couple of minutes the read bytes counter
increased though, so it might be that the kernel updates that counter only
after a certain period of time and we can't do nothing about that (just an
hypothesis).
Original comment by g.rodola
on 5 Dec 2012 at 9:17
What i really need is how i get the input/output bytes when the method is
called. The data since boot is useful, but i need just information that is
happening now. This is possible? if is, how i can do this?
Anyway, thanks for your help.
Original comment by sebastia...@gmail.com
on 10 Dec 2012 at 10:14
IO metrics since last boot is everything you need.
What you have to do is subtract input/output metrics every second, and you'll
have a real time representation of disk IO usage:
while 1:
io1 = psutil.disk_io_counters()
time.sleep(1)
io2 = psutil.disk_io_counters()
# bytes which were read/written in the last (1) second
r = io2.read_bytes - io1.read_bytes
w = io2.write_bytes - io1.write_bytes
print "read=%sMB/sec, written=%sMB/sec" % (r / 1024 / 1024,
w / 1024 / 1024)
The same concept is adopted by iotop.py and nettop.py example scripts:
http://code.google.com/p/psutil/source/browse/trunk/examples/iotop.py
http://code.google.com/p/psutil/source/browse/trunk/examples/nettop.py
Anyways, as for what concerns this issue I'm going to assume everything is fine.
Closing it out.
Original comment by g.rodola
on 10 Dec 2012 at 2:26
Original issue reported on code.google.com by
sebastia...@gmail.com
on 5 Dec 2012 at 8:02