Skip to content

locuensias/interactive-cpu-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Interactive CPU Logger (CLI)

A lightweight Python-based CLI tool to monitor CPU usage thread-by-thread in real-time. Its main feature is the ability to insert custom notes into the log without stopping execution or losing visual data, making it ideal for benchmarks, stress testing, or server monitoring.

Designed to be resource-efficient and compatible with any processor (Intel/AMD/ARM).

Features

  • Real-Time Monitoring: Displays usage percentage for each logical thread individually.
  • Persistent Logging: Automatically saves all data to a timestamped .txt file (registro_cpu.txt).
  • Interactive Notes: Allows the user to press ENTER at any time to write a note (e.g., "Starting Server", "Lag spike") which is saved and highlighted in the log for easier analysis.
  • Hardware Agnostic: Automatically detects the number of CPU cores/threads.
  • Low Overhead: Uses select for non-blocking I/O, consuming minimal CPU resources.

Requirements

  • Operating System: Linux (Ubuntu, Mint, Debian, Arch, etc.) or macOS.
    • Note: Not natively compatible with Windows due to select usage on stdin.
  • Python: Version 3.6 or higher.
  • Libraries: psutil.

Installation

On Debian / Ubuntu / Linux Mint

Modern distributions recommend installing psutil via system repositories:

sudo apt update
sudo apt install python3-psutil

On other systems (via pip)

pip install psutil

Usage & Workflow

  1. Run the script: Open your terminal and execute the file:
python3 monitoreo.py
  1. Automatic Monitoring: The script immediately starts displaying CPU usage per thread and saving the data to registro_cpu.txt every second.
  2. How to add a Note:
  • When you want to mark a specific event (e.g., before launching a heavy application), simply press ENTER.
  • The visual update pauses.
  • A prompt appears: >>> MONITOREO PAUSADO.
  1. Write & Resume:
  • Type your note (e.g., "Test 2: Opening Browser") and press ENTER again.
  • The script saves your note with a highlight separator.
  • It immediately resumes monitoring and logging.

Log File Output Example (registro_cpu.txt)

The generated file will look like this, allowing you to correlate your notes with performance spikes:

[2026-01-06 15:30:01] h0: 10.0% | h1: 2.0% | h2: 5.0% | h3: 1.0%
[2026-01-06 15:30:02] h0: 12.0% | h1: 3.0% | h2: 6.0% | h3: 2.0%

----------
[2026-01-06 15:30:05] USER NOTE:
Starting Minecraft Server
----------

[2026-01-06 15:30:06] h0: 85.0% | h1: 40.0% | h2: 90.0% | h3: 65.0%


----- Español -----

Una herramienta de terminal ligera basada en Python para monitorear el uso de la CPU hilo por hilo en tiempo real. Su característica principal es la capacidad de insertar notas personalizadas en el log sin detener la ejecución ni perder datos visuales, ideal para benchmarks, pruebas de estrés o monitoreo de servidores.

Diseñado para ser eficiente en recursos y compatible con cualquier procesador (Intel/AMD/ARM).

Características

  • Monitoreo en Tiempo Real: Muestra el porcentaje de uso de cada hilo lógico (Core/Threads) individualmente.
  • Logging Persistente: Guarda automáticamente todos los datos en un archivo .txt (registro_cpu.txt) con marca de tiempo.
  • Notas Interactivas: Permite al usuario presionar ENTER en cualquier momento para escribir una nota (ej: "Iniciando servidor", "Lag detectado") que se guarda destacada en el log, facilitando el análisis posterior.
  • Agnóstico de Hardware: Detecta automáticamente la cantidad de núcleos/hilos del procesador.
  • Bajo Consumo: Utiliza select para manejo de I/O no bloqueante, consumiendo recursos mínimos de CPU.

Requisitos

  • Sistema Operativo: Linux (Ubuntu, Mint, Debian, Arch, etc.) o macOS.

  • Nota: No compatible nativamente con Windows debido al uso de select en stdin.

  • Python: Versión 3.6 o superior.

  • Librerías: psutil.

Instalación

En Debian / Ubuntu / Linux Mint

Las distribuciones modernas recomiendan instalar psutil desde los repositorios del sistema:

sudo apt update
sudo apt install python3-psutil

En otros sistemas (vía pip)

pip install psutil

Uso y Flujo de Trabajo

  1. Ejecutar el script: Abre tu terminal y ejecuta el archivo:
python3 monitoreo.py
  1. Monitoreo Automático: Inmediatamente verás el uso de cada hilo en pantalla y la herramienta comenzará a guardar los datos en registro_cpu.txt segundo a segundo. Déjala correr en segundo plano.
  2. Cómo agregar una Nota:
  • Cuando quieras marcar un momento importante (por ejemplo, "Prueba 2"), simplemente presiona ENTER.
  • La pantalla se "congelará" momentáneamente.
  • Aparecerá: >>> MONITOREO PAUSADO.
  1. Escribir y Continuar:
  • Escribe tu texto y presiona ENTER nuevamente.
  • La herramienta guarda tu nota destacada entre guiones.
  • El monitoreo se reanuda automáticamente sin perder el ritmo.

Ejemplo del Archivo de Salida (registro_cpu.txt)

Así se verá el archivo final, permitiéndote ver qué pasó exactamente cuando escribiste tu nota:

[2026-01-06 15:30:01] h0: 10.0% | h1: 2.0% | h2: 5.0% | h3: 1.0%
[2026-01-06 15:30:02] h0: 12.0% | h1: 3.0% | h2: 6.0% | h3: 2.0%

----------
[2026-01-06 15:30:05] NOTA DEL USUARIO:
Iniciando Servidor de Minecraft
----------

[2026-01-06 15:30:06] h0: 85.0% | h1: 40.0% | h2: 90.0% | h3: 65.0%

License / Licencia

This project is open source. Feel free to modify and improve it.

Este proyecto es de código abierto. Siéntete libre de modificarlo y mejorarlo.

About

A lightweight CLI tool to monitor CPU threads in real-time with feature to add interactive notes to logs without stopping execution.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages