Enhance metrics handling and logging in bot
- Integrated metrics scheduler start and stop functionality in `run_helper.py` for better resource management. - Improved logging for metrics server operations in `server_prometheus.py`, ensuring clearer error reporting and status updates. - Updated metrics middleware to collect comprehensive metrics for all event types, enhancing monitoring capabilities. - Added active user metrics tracking in `admin_handlers.py` to provide insights on user engagement. - Refactored command and callback handling in `metrics_middleware.py` to improve clarity and error handling.
This commit is contained in:
@@ -383,11 +383,19 @@ async def test_metrics_handler(
|
||||
else:
|
||||
active_users = "N/A"
|
||||
|
||||
# ВАЖНО: Записываем метрику активных пользователей
|
||||
if isinstance(active_users, int):
|
||||
metrics.set_active_users(active_users, "daily")
|
||||
metrics.set_active_users(active_users, "total")
|
||||
|
||||
await message.answer(
|
||||
f"✅ Тестовые метрики записаны\n"
|
||||
f"📊 Активных пользователей: {active_users}\n"
|
||||
f"🔧 Проверьте Prometheus метрики"
|
||||
f"🔧 Проверьте Prometheus метрики\n"
|
||||
f"📈 Метрика active_users обновлена"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
await message.answer(f"❌ Ошибка тестирования метрик: {e}")
|
||||
# Записываем ошибку в метрики
|
||||
metrics.record_error(str(type(e).__name__), "admin_handler", "test_metrics_handler")
|
||||
|
||||
Reference in New Issue
Block a user