71 lines
2.3 KiB
Python
71 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
|
|
# main.py
|
|
# Exibe informações agradáveis do servidor no terminal
|
|
# Comentários explicativos incluídos conforme sua preferência
|
|
|
|
import platform
|
|
import psutil
|
|
import socket
|
|
from datetime import datetime
|
|
|
|
def get_server_info():
|
|
"""\ Coleta informações do sistema operacional, hardware e rede.
|
|
"""
|
|
info = {}
|
|
|
|
# Informações gerais do sistema
|
|
info["system"] = platform.system()
|
|
info["release"] = platform.release()
|
|
info["version"] = platform.version()
|
|
info["machine"] = platform.machine()
|
|
info["processor"] = platform.processor()
|
|
|
|
# Informações da rede
|
|
hostname = socket.gethostname()
|
|
ip_address = socket.gethostbyname(hostname)
|
|
info["hostname"] = hostname
|
|
info["ip_address"] = ip_address
|
|
|
|
# Informações de recursos
|
|
info["cpu_percent"] = psutil.cpu_percent(interval=1)
|
|
info["memory_percent"] = psutil.virtual_memory().percent
|
|
info["total_memory_gb"] = round(psutil.virtual_memory().total / (1024**3), 2)
|
|
info["uptime"] = datetime.now() - datetime.fromtimestamp(psutil.boot_time())
|
|
|
|
return info
|
|
|
|
|
|
def display_server_info(info):
|
|
"""\ Exibe as informações no terminal de maneira estilizada.
|
|
"""
|
|
# Exibe horário do início do teste
|
|
now = datetime.now().strftime("%H:%M:%S")
|
|
print(f"Início do teste às {now}")
|
|
print("=" * 60)
|
|
print(" 🖥️ SERVER STATUS - INFORMACOES DO SERVIDOR")
|
|
print("=" * 60)
|
|
|
|
print(f"📌 Sistema Operacional: {info['system']} {info['release']}")
|
|
print(f"📌 Versão: {info['version']}")
|
|
print(f"📌 Arquitetura: {info['machine']}")
|
|
print(f"📌 Processador: {info['processor']}")
|
|
print()
|
|
|
|
print(f"🌐 Hostname: {info['hostname']}")
|
|
print(f"🌐 IP: {info['ip_address']}")
|
|
print()
|
|
|
|
print(f"⚙️ Uso de CPU: {info['cpu_percent']}%")
|
|
print(f"⚙️ Uso de Memória: {info['memory_percent']}%")
|
|
print(f"⚙️ Memória Total: {info['total_memory_gb']} GB")
|
|
print(f"⚙️ Uptime: {str(info['uptime']).split('.')[0]}")
|
|
|
|
print("=" * 60)
|
|
print(" Finalizado ✔️")
|
|
print("=" * 60)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
info = get_server_info()
|
|
display_server_info(info)
|