Files
telegram-helper-bot/tests/test_monitor.py
Andrey dc0e5d788c Implement OS detection and enhance disk monitoring in ServerMonitor
- Added OS detection functionality to the ServerMonitor class, allowing for tailored disk usage and uptime calculations based on the operating system (macOS or Ubuntu).
- Introduced methods for retrieving disk usage and I/O statistics specific to the detected OS.
- Updated the process status check to return uptime information for monitored processes.
- Enhanced the status message format to include disk space emojis and process uptime details.
- Updated tests to reflect changes in process status checks and output formatting.
2025-08-27 20:09:48 +03:00

82 lines
2.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""
Тестовый скрипт для проверки модуля мониторинга сервера
"""
import asyncio
import sys
import os
# Добавляем путь к проекту
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from helper_bot.server_monitor import ServerMonitor
class MockBot:
"""Мок объект бота для тестирования"""
async def send_message(self, chat_id, text, parse_mode=None):
print(f"\n{'='*60}")
print(f"Отправка в чат: {chat_id}")
print(f"Текст сообщения:")
print(text)
print(f"{'='*60}\n")
async def test_monitor():
"""Тестирование модуля мониторинга"""
print("🧪 Тестирование модуля мониторинга сервера")
print("=" * 60)
# Создаем мок бота
mock_bot = MockBot()
# Создаем монитор
monitor = ServerMonitor(
bot=mock_bot,
group_for_logs="-123456789",
important_logs="-987654321"
)
print("📊 Получение информации о системе...")
system_info = monitor.get_system_info()
if system_info:
print("✅ Информация о системе получена успешно")
print(f"CPU: {system_info['cpu_percent']}%")
print(f"RAM: {system_info['ram_percent']}%")
print(f"Disk: {system_info['disk_percent']}%")
print(f"Uptime: {system_info['system_uptime']}")
print("\n🤖 Проверка статуса процессов...")
voice_status, voice_uptime = monitor.check_process_status('voice_bot')
helper_status, helper_uptime = monitor.check_process_status('helper_bot')
print(f"Voice Bot: {voice_status} - {voice_uptime}")
print(f"Helper Bot: {helper_status} - {helper_uptime}")
print("\n📝 Тестирование отправки статуса...")
await monitor.send_status_message(system_info)
print("\n🚨 Тестирование отправки алерта...")
await monitor.send_alert_message(
"Использование CPU",
85.5,
"Нагрузка за 1 мин: 2.5"
)
print("\n✅ Тестирование отправки сообщения о восстановлении...")
await monitor.send_recovery_message(
"Использование CPU",
70.0,
85.5
)
else:
print("Не удалось получить информацию о системе")
print("\n🎯 Тестирование завершено!")
if __name__ == "__main__":
asyncio.run(test_monitor())