Implement AnonBot integration and monitoring enhancements
- Added AnonBot service to docker-compose with resource limits and environment variables. - Updated Makefile to include commands for AnonBot logs, restart, and dependency checks. - Enhanced Grafana dashboards with AnonBot health metrics and database connection statistics. - Implemented AnonBot status retrieval in the message sender for improved monitoring. - Updated Prometheus configuration to scrape metrics from AnonBot service.
This commit was merged in pull request #2.
This commit is contained in:
@@ -64,6 +64,39 @@ class MessageSender:
|
||||
logger.error(f"Ошибка при отправке сообщения в Telegram: {e}")
|
||||
return False
|
||||
|
||||
async def get_anonbot_status(self) -> Tuple[str, str]:
|
||||
"""Получение статуса AnonBot через HTTP API"""
|
||||
try:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
# AnonBot доступен через Docker network
|
||||
url = "http://bots_anon_bot:8081/status"
|
||||
|
||||
async with session.get(url, timeout=aiohttp.ClientTimeout(total=5)) as response:
|
||||
if response.status == 200:
|
||||
data = await response.json()
|
||||
status = data.get('status', 'unknown')
|
||||
uptime = data.get('uptime', 'unknown')
|
||||
|
||||
# Форматируем статус с эмодзи
|
||||
if status == 'running':
|
||||
status_emoji = "✅"
|
||||
elif status == 'stopped':
|
||||
status_emoji = "❌"
|
||||
else:
|
||||
status_emoji = "⚠️"
|
||||
|
||||
return f"{status_emoji}", uptime
|
||||
else:
|
||||
logger.warning(f"AnonBot API вернул статус {response.status}")
|
||||
return "⚠️ AnonBot", "API недоступен"
|
||||
|
||||
except aiohttp.ClientError as e:
|
||||
logger.warning(f"Ошибка подключения к AnonBot API: {e}")
|
||||
return "❌", "Недоступен"
|
||||
except Exception as e:
|
||||
logger.error(f"Неожиданная ошибка при получении статуса AnonBot: {e}")
|
||||
return "⚠️", "Ошибка"
|
||||
|
||||
def should_send_status(self) -> bool:
|
||||
"""Проверка, нужно ли отправить статус (каждые N минут)"""
|
||||
now = datetime.now()
|
||||
@@ -147,11 +180,14 @@ class MessageSender:
|
||||
else:
|
||||
return "🚨"
|
||||
|
||||
def get_status_message(self, system_info: Dict) -> str:
|
||||
async def get_status_message(self, system_info: Dict) -> str:
|
||||
"""Формирование сообщения со статусом сервера"""
|
||||
try:
|
||||
helper_bot_status, helper_bot_uptime = self.metrics_collector.check_process_status('helper_bot')
|
||||
|
||||
# Получаем статус AnonBot
|
||||
anonbot_status, anonbot_uptime = await self.get_anonbot_status()
|
||||
|
||||
# Получаем эмодзи для всех метрик
|
||||
cpu_emoji = self._get_cpu_emoji(system_info['cpu_percent'])
|
||||
ram_emoji = self._get_memory_emoji(system_info['ram_percent'])
|
||||
@@ -183,6 +219,7 @@ Read: <b>{system_info['disk_read_speed']}</b> | Write: <b>{system_info['disk_wri
|
||||
|
||||
**🤖 Процессы:**
|
||||
{helper_bot_status} helper-bot - {helper_bot_uptime}
|
||||
{anonbot_status} AnonBot - {anonbot_uptime}
|
||||
---------------------------------
|
||||
⏰ Uptime сервера: {system_info['system_uptime']}
|
||||
🔍 Уровень мониторинга: {level_text} ({monitoring_level})"""
|
||||
@@ -259,7 +296,7 @@ Read: <b>{system_info['disk_read_speed']}</b> | Write: <b>{system_info['disk_wri
|
||||
logger.error("Не удалось получить информацию о системе")
|
||||
return False
|
||||
|
||||
status_message = self.get_status_message(system_info)
|
||||
status_message = await self.get_status_message(system_info)
|
||||
success = await self.send_telegram_message(self.group_for_logs, status_message)
|
||||
|
||||
# Обновляем время последней отправки только при успешной отправке
|
||||
|
||||
Reference in New Issue
Block a user