Enhance bot functionality with new features and improvements
- Added a new `/status` endpoint in `server_prometheus.py` to provide process status information, including uptime and resource usage metrics. - Implemented a PID manager in `run_helper.py` to track the bot's process, improving monitoring capabilities. - Introduced a method to delete audio moderation records in `audio_repository.py`, enhancing database management. - Updated voice message handling in callback handlers to ensure proper deletion of audio moderation records. - Improved error handling and logging in various services, ensuring better tracking of media processing and file downloads. - Refactored media handling functions to streamline operations and improve code readability. - Enhanced metrics tracking for file downloads and media processing, providing better insights into bot performance.
This commit is contained in:
@@ -155,30 +155,27 @@ class MetricsMiddleware(BaseMiddleware):
|
||||
bdf = get_global_instance()
|
||||
bot_db = bdf.get_db()
|
||||
|
||||
await bot_db.connect()
|
||||
|
||||
# Используем правильные методы AsyncBotDB для выполнения запросов
|
||||
# Простой подсчет всех пользователей в базе
|
||||
total_users_query = "SELECT COUNT(DISTINCT user_id) FROM our_users"
|
||||
await bot_db.cursor.execute(total_users_query)
|
||||
total_users_result = await bot_db.cursor.fetchone()
|
||||
total_users = total_users_result[0] if total_users_result else 1
|
||||
daily_users_query = "SELECT COUNT(DISTINCT user_id) as active_users FROM our_users WHERE date_changed > datetime('now', '-1 day')"
|
||||
await bot_db.cursor.execute(daily_users_query)
|
||||
daily_users_result = await bot_db.cursor.fetchone()
|
||||
daily_users = daily_users_result[0] if daily_users_result else 1
|
||||
total_users_query = "SELECT COUNT(DISTINCT user_id) as total FROM our_users"
|
||||
total_users_result = await bot_db.fetch_one(total_users_query)
|
||||
total_users = total_users_result['total'] if total_users_result else 1
|
||||
|
||||
await bot_db.close()
|
||||
# Подсчет активных за день пользователей (date_changed - это Unix timestamp)
|
||||
daily_users_query = "SELECT COUNT(DISTINCT user_id) as daily FROM our_users WHERE date_changed > (strftime('%s', 'now', '-1 day'))"
|
||||
daily_users_result = await bot_db.fetch_one(daily_users_query)
|
||||
daily_users = daily_users_result['daily'] if daily_users_result else 1
|
||||
|
||||
# Устанавливаем метрики с правильными лейблами
|
||||
metrics.set_active_users(daily_users, "daily")
|
||||
metrics.set_active_users(total_users, "total")
|
||||
metrics.set_total_users(total_users)
|
||||
self.logger.info(f"📊 Active users metric updated: {daily_users} (daily), {total_users} (total)")
|
||||
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"❌ Failed to update users metric: {e}")
|
||||
# Устанавливаем 1 как fallback
|
||||
metrics.set_active_users(1, "daily")
|
||||
metrics.set_active_users(1, "total")
|
||||
metrics.set_total_users(1)
|
||||
|
||||
async def _record_comprehensive_message_metrics(self, message: Message) -> Dict[str, Any]:
|
||||
"""Record comprehensive message metrics."""
|
||||
|
||||
Reference in New Issue
Block a user