mirror of
https://github.com//cppla/ServerStatus
synced 2025-06-05 15:19:50 +08:00
push disk io for client-linux.py
This commit is contained in:
parent
d8c8d8fd3f
commit
2d457c66ad
@ -214,9 +214,63 @@ def _net_speed():
|
||||
time.sleep(INTERVAL)
|
||||
|
||||
def _disk_io():
|
||||
# todo, 这里希望能有人贡献下代码
|
||||
diskIO["read"] = 0
|
||||
diskIO["write"] = 0
|
||||
'''
|
||||
磁盘IO:因为IOPS原因,SSD和HDD、包括RAID卡,ZFS等阵列技术。IO对性能的影响还需要结合自身服务器情况来判断。
|
||||
比如我这里是机械硬盘,大量做随机小文件读写,那么很低的读写也就能造成硬盘长时间的等待。
|
||||
如果这里做连续性IO,那么普通机械硬盘写入到100Mb/s,那么也能造成硬盘长时间的等待。
|
||||
磁盘读写有误差:4k,8k ,https://stackoverflow.com/questions/34413926/psutil-vs-dd-monitoring-disk-i-o
|
||||
:return:
|
||||
'''
|
||||
# pre pid snapshot
|
||||
snapshot_first = {}
|
||||
# next pid snapshot
|
||||
snapshot_second = {}
|
||||
# read count snapshot
|
||||
snapshot_read = 0
|
||||
# write count snapshot
|
||||
snapshot_write = 0
|
||||
# process snapshot
|
||||
pid_snapshot = [str(i) for i in os.listdir("/proc") if i.isdigit() is True]
|
||||
for pid in pid_snapshot:
|
||||
try:
|
||||
with open("/proc/{}/io".format(pid)) as f:
|
||||
pid_io = {}
|
||||
for line in f.readlines():
|
||||
if "read_bytes" in line:
|
||||
pid_io["read"] = int(line.split("read_bytes:")[-1].strip())
|
||||
elif "write_bytes" in line and "cancelled_write_bytes" not in line:
|
||||
pid_io["write"] = int(line.split("write_bytes:")[-1].strip())
|
||||
pid_io["name"] = open("/proc/{}/comm".format(pid), "r").read().strip()
|
||||
snapshot_first[pid] = pid_io
|
||||
except:
|
||||
if pid in snapshot_first:
|
||||
snapshot_first.pop(pid)
|
||||
|
||||
time.sleep(INTERVAL)
|
||||
|
||||
for pid in pid_snapshot:
|
||||
try:
|
||||
with open("/proc/{}/io".format(pid)) as f:
|
||||
pid_io = {}
|
||||
for line in f.readlines():
|
||||
if "read_bytes" in line:
|
||||
pid_io["read"] = int(line.split("read_bytes:")[-1].strip())
|
||||
elif "write_bytes" in line and "cancelled_write_bytes" not in line:
|
||||
pid_io["write"] = int(line.split("write_bytes:")[-1].strip())
|
||||
pid_io["name"] = open("/proc/{}/comm".format(pid), "r").read().strip()
|
||||
snapshot_second[pid] = pid_io
|
||||
except:
|
||||
if pid in snapshot_first:
|
||||
snapshot_first.pop(pid)
|
||||
if pid in snapshot_second:
|
||||
snapshot_second.pop(pid)
|
||||
|
||||
for k, v in snapshot_first.items():
|
||||
if snapshot_first[k]["name"] == snapshot_second[k]["name"] and snapshot_first[k]["name"] != "bash":
|
||||
snapshot_read += (snapshot_second[k]["read"] - snapshot_first[k]["read"])
|
||||
snapshot_write += (snapshot_second[k]["write"] - snapshot_first[k]["write"])
|
||||
diskIO["read"] = snapshot_read
|
||||
diskIO["write"] = snapshot_write
|
||||
|
||||
def get_realtime_data():
|
||||
'''
|
||||
|
@ -201,6 +201,10 @@ def _disk_io():
|
||||
after the interval.
|
||||
Return a tuple including all currently running processes
|
||||
sorted by IO activity and total disks I/O activity.
|
||||
磁盘IO:因为IOPS原因,SSD和HDD、包括RAID卡,ZFS等。IO对性能的影响还需要结合自身服务器情况来判断。
|
||||
比如我这里是机械硬盘,大量做随机小文件读写,那么很低的读写也就能造成硬盘长时间的等待。
|
||||
如果这里做连续性IO,那么普通机械硬盘写入到100Mb/s,那么也能造成硬盘长时间的等待。
|
||||
磁盘读写有误差:4k,8k ,https://stackoverflow.com/questions/34413926/psutil-vs-dd-monitoring-disk-i-o
|
||||
"""
|
||||
while True:
|
||||
# first get a list of all processes and disk io counters
|
||||
|
Loading…
x
Reference in New Issue
Block a user