It's version 0.4
This commit is contained in:
+15
-9
@@ -1,11 +1,14 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
|
||||
async def get_macbook_battery_level():
|
||||
process = await asyncio.create_subprocess_exec(
|
||||
"pmset", "-g", "batt",
|
||||
"pmset",
|
||||
"-g",
|
||||
"batt",
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
if process.returncode != 0:
|
||||
@@ -28,9 +31,13 @@ async def get_process_usage(pid=None):
|
||||
pid = os.getpid()
|
||||
|
||||
process = await asyncio.create_subprocess_exec(
|
||||
"ps", "-p", str(pid), "-o", "%cpu,%mem,rss,comm",
|
||||
"ps",
|
||||
"-p",
|
||||
str(pid),
|
||||
"-o",
|
||||
"%cpu,%mem,rss,comm",
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
if process.returncode != 0:
|
||||
@@ -47,19 +54,18 @@ async def get_process_usage(pid=None):
|
||||
"command": comm,
|
||||
"cpu_percent": float(cpu),
|
||||
"mem_percent": float(mem_percent),
|
||||
"rss_mb": int(rss_kb) / 1024 # переводим КБ → МБ
|
||||
"rss_mb": int(rss_kb) / 1024, # переводим КБ → МБ
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
async def main():
|
||||
battery = await get_macbook_battery_level()
|
||||
usage = await get_process_usage()
|
||||
|
||||
print(f"🔋 Батарея: {battery}%")
|
||||
print(f"🖥 CPU: {usage['cpu_percent']}% | MEM: {usage['mem_percent']}% | RSS: {usage['rss_mb']:.2f} MB")
|
||||
print(
|
||||
f"🖥 CPU: {usage['cpu_percent']}% | MEM: {usage['mem_percent']}% | RSS: {usage['rss_mb']:.2f} MB"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user