From 6b3766c65af44154eae26ecc0a0b3a7bca9b2ea3 Mon Sep 17 00:00:00 2001 From: Kyomotoi <0w0@imki.moe> Date: Tue, 9 May 2023 17:03:24 +0800 Subject: =?UTF-8?q?=E2=9C=A8=20=E6=96=B0=E5=A2=9E=E5=8F=AF=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ATRI/utils/machine.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'ATRI/utils') diff --git a/ATRI/utils/machine.py b/ATRI/utils/machine.py index ee2b533..1c13d3f 100644 --- a/ATRI/utils/machine.py +++ b/ATRI/utils/machine.py @@ -46,6 +46,7 @@ class DiskInfo(BaseModel): used: int free: int drive: int + speed: list[int] class NetInfo(BaseModel): @@ -104,6 +105,22 @@ def get_mem_info() -> MemInfo: ) +last_disk_io = [0, 0] +now_disk_io = [0, 0] + + +@scheduler.scheduled_job("interval", seconds=1, misfire_grace_time=15) +async def _(): + global last_disk_io, now_disk_io + + disk_counters = psutil.disk_io_counters() + now_disk_io = [ + disk_counters.write_bytes - last_disk_io[0], # type: ignore + disk_counters.read_bytes - last_disk_io[1], # type: ignore + ] + last_disk_io = [disk_counters.write_bytes, disk_counters.read_bytes] # type: ignore + + def get_disk_info(): disk_name = "ATRI Disk Pro Plus" disk_total = int() @@ -133,6 +150,7 @@ def get_disk_info(): used=disk_used, free=disk_free, drive=disk_drive, + speed=now_disk_io, ) -- cgit v1.2.3