creation du package
This commit is contained in:
@@ -13,14 +13,33 @@ def get_cpu_ram() -> tuple[float, float]:
|
||||
return cpu, ram
|
||||
|
||||
|
||||
def get_disk_usage() -> float:
|
||||
return psutil.disk_usage('/').percent
|
||||
|
||||
|
||||
def get_net_io() -> tuple[int, int]:
|
||||
counters = psutil.net_io_counters()
|
||||
return counters.bytes_sent, counters.bytes_recv
|
||||
|
||||
|
||||
def get_disk_io() -> tuple[int, int]:
|
||||
counters = psutil.disk_io_counters()
|
||||
if counters is None:
|
||||
return 0, 0
|
||||
return counters.read_bytes, counters.write_bytes
|
||||
|
||||
|
||||
def format_line() -> str:
|
||||
now = datetime.now().strftime("%H:%M:%S")
|
||||
cpu, ram = get_cpu_ram()
|
||||
return f"{now} | CPU: {cpu:5.1f}% | RAM: {ram:5.1f}%"
|
||||
disk = get_disk_usage()
|
||||
d_read, d_write = get_disk_io()
|
||||
sent, recv = get_net_io()
|
||||
return f"{now} | CPU: {cpu:5.1f}% | RAM: {ram:5.1f}% | Disk: {disk:5.1f}% | ↑{d_read:,} ↓{d_write:,} B | Net: ↑{sent:,} ↓{recv:,} B"
|
||||
|
||||
|
||||
def main() -> None:
|
||||
print("Monitoring CPU/RAM. Ctrl+C pour arrêter.")
|
||||
print("Monitoring CPU/RAM/Disk. Ctrl+C pour arrêter.")
|
||||
try:
|
||||
while True:
|
||||
print(format_line())
|
||||
|
||||
Reference in New Issue
Block a user