Refactor Docker and configuration files for improved structure and functionality
- Updated `.dockerignore` to include additional development and temporary files, enhancing build efficiency. - Modified `.gitignore` to remove unnecessary entries and streamline ignored files. - Enhanced `docker-compose.yml` with health checks, resource limits, and improved environment variable handling for better service management. - Refactored `Dockerfile.bot` to utilize a multi-stage build for optimized image size and security. - Improved `Makefile` with new commands for deployment, migration, and backup, along with enhanced help documentation. - Updated `requirements.txt` to include new dependencies for environment variable management. - Refactored metrics handling in the bot to ensure proper initialization and collection.
This commit is contained in:
@@ -307,3 +307,44 @@ async def cancel_ban_process(
|
||||
await return_to_admin_menu(message, state)
|
||||
except Exception as e:
|
||||
await handle_admin_error(message, e, state, "cancel_ban_process")
|
||||
|
||||
|
||||
@admin_router.message(Command("test_metrics"))
|
||||
async def test_metrics_handler(
|
||||
message: types.Message,
|
||||
bot_db: MagicData("bot_db")
|
||||
):
|
||||
"""Тестовый хендлер для проверки метрик"""
|
||||
from helper_bot.utils.metrics import metrics
|
||||
|
||||
try:
|
||||
# Принудительно записываем тестовые метрики
|
||||
metrics.record_command("test_metrics", "admin_handler", "admin", "success")
|
||||
metrics.record_message("text", "private", "admin_handler")
|
||||
metrics.record_error("TestError", "admin_handler", "test_metrics_handler")
|
||||
|
||||
# Проверяем активных пользователей
|
||||
if hasattr(bot_db, 'connect') and hasattr(bot_db, 'cursor'):
|
||||
active_users_query = """
|
||||
SELECT COUNT(DISTINCT user_id) as active_users
|
||||
FROM our_users
|
||||
WHERE date_changed > datetime('now', '-1 day')
|
||||
"""
|
||||
try:
|
||||
bot_db.connect()
|
||||
bot_db.cursor.execute(active_users_query)
|
||||
result = bot_db.cursor.fetchone()
|
||||
active_users = result[0] if result else 0
|
||||
finally:
|
||||
bot_db.close()
|
||||
else:
|
||||
active_users = "N/A"
|
||||
|
||||
await message.answer(
|
||||
f"✅ Тестовые метрики записаны\n"
|
||||
f"📊 Активных пользователей: {active_users}\n"
|
||||
f"🔧 Проверьте Grafana дашборд"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
await message.answer(f"❌ Ошибка тестирования метрик: {e}")
|
||||
|
||||
Reference in New Issue
Block a user