diff --git a/cpu_monitor.py b/cpu_monitor.py index 98cdee5..543b97f 100644 --- a/cpu_monitor.py +++ b/cpu_monitor.py @@ -1,45 +1,29 @@ -# CPU Monitor - Run with python cpu_monitor_gui.py -# Requirements: psutil (>=5.8.0), tkinter -# Install: pip install psutil tkinter +#!/usr/bin/env python3 +# Lancement: python cpu_monitor.py -import tkinter as tk -import psutil -import time from datetime import datetime +import time -# Main window setup -root = tk.Tk() -root.title("CPU Monitor") -root.geometry("400x200") +import psutil -# CPU usage label -cpu_label = tk.Label(root, text="CPU Usage: 0%", font=("Arial", 16)) -cpu_label.pack(pady=10) -# Progress bar for CPU usage -progress_bar = tk.Progressbar(root, orient="horizontal", maximum=100, mode="indeterminate") -progress_bar.pack(pady=10) +def format_line() -> str: + now = datetime.now().strftime("%H:%M:%S") + cpu = psutil.cpu_percent(interval=None) + ram = psutil.virtual_memory().percent + return f"{now} | CPU: {cpu:5.1f}% | RAM: {ram:5.1f}%" -# Time label -time_label = tk.Label(root, text="Time: 00:00:00", font=("Arial", 14)) -time_label.pack(pady=10) -# Quit button -quit_button = tk.Button(root, text="Quit", command=root.destroy) -quit_button.pack(pady=10) +def main() -> None: + print("Monitoring CPU/RAM. Ctrl+C pour arrĂȘter.") + try: + while True: + print(format_line()) + time.sleep(2) + except KeyboardInterrupt: + print("\nArrĂȘt propre.") -# Update GUI every 2 seconds -def update_gui(): - while True: - cpu_percent = psutil.cpu_percent() - current_time = datetime.now().strftime("%H:%M:%S") - cpu_label.config(text=f"CPU Usage: {cpu_percent}%") - progress_bar.config(value=cpu_percent) - time_label.config(text=current_time) - time.sleep(2) -# Start the update loop -update_gui() +if __name__ == "__main__": + main() -# Run the Tkinter main loop -root.mainloop() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a4d92cc --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +psutil