mirror of
https://github.com//cppla/ServerStatus
synced 2025-07-04 08:25:58 +08:00
The io_counters is not available on OS X, 兼容处理
This commit is contained in:
parent
25917f0883
commit
34b1bca5b1
@ -206,43 +206,47 @@ def _disk_io():
|
|||||||
如果这里做连续性IO,那么普通机械硬盘写入到100Mb/s,那么也能造成硬盘长时间的等待。
|
如果这里做连续性IO,那么普通机械硬盘写入到100Mb/s,那么也能造成硬盘长时间的等待。
|
||||||
磁盘读写有误差:4k,8k ,https://stackoverflow.com/questions/34413926/psutil-vs-dd-monitoring-disk-i-o
|
磁盘读写有误差:4k,8k ,https://stackoverflow.com/questions/34413926/psutil-vs-dd-monitoring-disk-i-o
|
||||||
"""
|
"""
|
||||||
while True:
|
if "darwin" in sys.platform:
|
||||||
# first get a list of all processes and disk io counters
|
diskIO["read"] = 0
|
||||||
procs = [p for p in psutil.process_iter()]
|
diskIO["write"] = 0
|
||||||
for p in procs[:]:
|
else:
|
||||||
try:
|
while True:
|
||||||
p._before = p.io_counters()
|
# first get a list of all processes and disk io counters
|
||||||
except psutil.Error:
|
procs = [p for p in psutil.process_iter()]
|
||||||
procs.remove(p)
|
for p in procs[:]:
|
||||||
continue
|
|
||||||
disks_before = psutil.disk_io_counters()
|
|
||||||
|
|
||||||
# sleep some time, only when INTERVAL==1 , io read/write per_sec.
|
|
||||||
# when INTERVAL > 1, io read/write per_INTERVAL
|
|
||||||
time.sleep(INTERVAL)
|
|
||||||
|
|
||||||
# then retrieve the same info again
|
|
||||||
for p in procs[:]:
|
|
||||||
with p.oneshot():
|
|
||||||
try:
|
try:
|
||||||
p._after = p.io_counters()
|
p._before = p.io_counters()
|
||||||
p._cmdline = ' '.join(p.cmdline())
|
except psutil.Error:
|
||||||
if not p._cmdline:
|
|
||||||
p._cmdline = p.name()
|
|
||||||
p._username = p.username()
|
|
||||||
except (psutil.NoSuchProcess, psutil.ZombieProcess):
|
|
||||||
procs.remove(p)
|
procs.remove(p)
|
||||||
disks_after = psutil.disk_io_counters()
|
continue
|
||||||
|
disks_before = psutil.disk_io_counters()
|
||||||
|
|
||||||
# finally calculate results by comparing data before and
|
# sleep some time, only when INTERVAL==1 , io read/write per_sec.
|
||||||
# after the interval
|
# when INTERVAL > 1, io read/write per_INTERVAL
|
||||||
for p in procs:
|
time.sleep(INTERVAL)
|
||||||
p._read_per_sec = p._after.read_bytes - p._before.read_bytes
|
|
||||||
p._write_per_sec = p._after.write_bytes - p._before.write_bytes
|
|
||||||
p._total = p._read_per_sec + p._write_per_sec
|
|
||||||
|
|
||||||
diskIO["read"] = disks_after.read_bytes - disks_before.read_bytes
|
# then retrieve the same info again
|
||||||
diskIO["write"] = disks_after.write_bytes - disks_before.write_bytes
|
for p in procs[:]:
|
||||||
|
with p.oneshot():
|
||||||
|
try:
|
||||||
|
p._after = p.io_counters()
|
||||||
|
p._cmdline = ' '.join(p.cmdline())
|
||||||
|
if not p._cmdline:
|
||||||
|
p._cmdline = p.name()
|
||||||
|
p._username = p.username()
|
||||||
|
except (psutil.NoSuchProcess, psutil.ZombieProcess):
|
||||||
|
procs.remove(p)
|
||||||
|
disks_after = psutil.disk_io_counters()
|
||||||
|
|
||||||
|
# finally calculate results by comparing data before and
|
||||||
|
# after the interval
|
||||||
|
for p in procs:
|
||||||
|
p._read_per_sec = p._after.read_bytes - p._before.read_bytes
|
||||||
|
p._write_per_sec = p._after.write_bytes - p._before.write_bytes
|
||||||
|
p._total = p._read_per_sec + p._write_per_sec
|
||||||
|
|
||||||
|
diskIO["read"] = disks_after.read_bytes - disks_before.read_bytes
|
||||||
|
diskIO["write"] = disks_after.write_bytes - disks_before.write_bytes
|
||||||
|
|
||||||
def get_realtime_data():
|
def get_realtime_data():
|
||||||
'''
|
'''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user