Añadiendo mas metodos para mostrar informacion de sistema

master
Victor 11 months ago
parent 8221fffdea
commit aa083bf574

@ -1,2 +1,6 @@
# Proyecto_SystemStatus
El proyecto consiste de crear un menu que permite al usuario a ver informacion sobre el systema del ordenador que esta usando.
Puede ver informacion como Hilo por nucleo, sobre la memoria, sockets, modulo de plataforma y sistema operativa, conexiones tcp y otras;
Para mostar la informacion usamos metodos para que el menu es facil de entender , como por ejemplo el medotodo de mostar la información sobre el uso de cpu, memoria y swap en forma de barra de diferentes colores.

@ -1,10 +1,47 @@
import os
import platform
import socket
import subprocess
import psutil
import matplotlib.pyplot as plt
threads_por_nucleo = psutil.cpu_count(logical=False)
memoria = psutil.virtual_memory()
def display_horizontal_bar(label, value, max_value=100, bar_length=20, color='\033[0m'):
percentage = (value / max_value) * 100
bar_fill_length = int(bar_length * (percentage / 100))
bar = f"{color}|" + '=' * bar_fill_length + ' ' * (bar_length - bar_fill_length) + f'{color}|'
print(f"{label} {bar} {percentage:.2f}%\033[0m")
def get_process_states():
# Get a list of all running processes
processes = psutil.process_iter(['pid', 'name', 'status'])
# Initialize counters for different process states
running_count = 0
sleeping_count = 0
other_count = 0
# Iterate through processes and count their states
for process in processes:
status = process.info['status'].lower()
if 'running' in status:
running_count += 1
elif 'sleeping' in status:
sleeping_count += 1
else:
other_count += 1
return running_count, sleeping_count, other_count
def get_running_processes():
# Using list comprehension to get information about all running processes
return [proc.info for proc in psutil.process_iter(['pid', 'name', 'username'])]
def get_tcp_connections():
connections = psutil.net_connections(kind='inet')
return connections
def procesesRunning():
# Get and print information about all running processes
@ -22,32 +59,79 @@ ans=True
while ans:
print("""
1. Hilos por nucleo
2. Memoria Total
3. Memoria Diponible
4. Porcentaje de memoria utilizada
2. Memoria Total, Memoria Diponible y Porcentaje de memoria utilizada
3. Modulo OS
4. Informacion sobre drives en el sistema
5. El estado de bateria
6. Procesos activados
7. El uso del CPU
8. Exit/Quit
7. El uso del CPU, memoria y swap
8. Lista de connecciones TPC
9. Temperatura
10. Socket info
11. Modulo de plataforma
12. Numero de precesos activos,dormidos y otros
0.Salir
""")
ans=input("Elige que tipo de informacio deseas saber:")
if ans=="1":
print(f"Tu procesador tiene {threads_por_nucleo} hilos por núcleo.")
elif ans=="2":
print(f"Memoria total: {memoria.total} bytes")
elif ans=="3":
print(f"Memoria disponible: {memoria.available} bytes")
elif ans == "4":
print(f"Porcentaje de memoria utilizada: {memoria.percent}%")
elif ans=="3":
cpu_count = os.cpu_count()
print(f"CPU Count: {cpu_count}")
current_directory = os.getcwd()
print(f"Current Directory: {current_directory}")
elif ans == "4":
result = subprocess.run(['powershell', 'Get-PSDrive'], stdout=subprocess.PIPE, text=True)
print(result.stdout)
elif ans == "5":
print(percent+'% | '+plugged)
elif ans == "6":
procesesRunning()
elif ans == "7":
cpu_usage = psutil.cpu_percent(interval=1)
print(f"CPU Usage: {cpu_usage}%")
elif ans=="8":
print("\n Goodbye")
memory_info = psutil.virtual_memory()
swap_info = psutil.swap_memory()
display_horizontal_bar('CPU', cpu_usage, color='\033[91m')
display_horizontal_bar('Memoria', memory_info.percent, color='\033[94m')
display_horizontal_bar('Swap', swap_info.percent, color='\033[92m')
elif ans =="8":
if __name__ == "__main__":
tcp_connections = get_tcp_connections()
for connection in tcp_connections:
print(f"Local Address: {connection.laddr}")
print(f"Remote Address: {connection.raddr}")
print(f"Status: {connection.status}")
print("-----------------------------------")
elif ans=="9":
try:
temperatures = psutil.sensors_temperatures()
print("Temperatura:")
for name, entries in temperatures.items():
for entry in entries:
print(f"{name}: {entry.label} - {entry.current}°C")
except AttributeError:
print("la informacion sobre temeratura no esta disponible ens ete sitema")
elif ans == "10":
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
print(f"Hostname: {hostname}")
print(f"IP Address: {ip_address}")
elif ans == "11":
system_info = platform.system()
release_info = platform.release()
print(f"System: {system_info}")
print(f"Release: {release_info}")
elif ans == "12":
running, sleeping, other = get_process_states()
print(f"Processos activos: {running}")
print(f"procesos dormiendo: {sleeping}")
print(f"Otros procesos: {other}")
elif ans =="0":
print("\n Adios")
ans = None
else:
print("\n Not Valid Choice Try again")
print("\n no es una pocion valida")
Loading…
Cancel
Save

Powered by INFORMATICA.FP.EDU.ES.