Refactor project structure and enhance Docker support

- Removed unnecessary `__init__.py` and `Dockerfile` to streamline project organization.
- Updated `.dockerignore` and `.gitignore` to improve exclusion patterns for build artifacts and environment files.
- Enhanced `Makefile` with new commands for managing Docker containers and added help documentation.
- Introduced `pyproject.toml` for better project metadata management and dependency tracking.
- Updated `requirements.txt` to reflect changes in dependencies for metrics and monitoring.
- Refactored various handler files to improve code organization and maintainability.
This commit is contained in:
2025-08-29 16:49:28 +03:00
parent 8cee629e28
commit c68db87901
37 changed files with 2177 additions and 175 deletions

92
run_metrics_only.py Normal file
View File

@@ -0,0 +1,92 @@
#!/usr/bin/env python3
"""
Standalone metrics server for testing.
Run this to start just the metrics system without the bot.
"""
import asyncio
import signal
import sys
from helper_bot.utils.metrics_exporter import MetricsManager
class MetricsServer:
"""Standalone metrics server."""
def __init__(self, host: str = "0.0.0.0", port: int = 8000):
self.host = host
self.port = port
self.metrics_manager = MetricsManager(host, port)
self.running = False
async def start(self):
"""Start the metrics server."""
try:
await self.metrics_manager.start()
self.running = True
print(f"🚀 Metrics server started on {self.host}:{self.port}")
print(f"📊 Metrics endpoint: http://{self.host}:{self.port}/metrics")
print(f"🏥 Health check: http://{self.host}:{self.port}/health")
print(f" Info: http://{self.host}:{self.port}/")
print("\nPress Ctrl+C to stop the server")
# Keep the server running
while self.running:
await asyncio.sleep(1)
except Exception as e:
print(f"❌ Error starting metrics server: {e}")
raise
async def stop(self):
"""Stop the metrics server."""
if self.running:
self.running = False
await self.metrics_manager.stop()
print("\n🛑 Metrics server stopped")
def signal_handler(self, signum, frame):
"""Handle shutdown signals."""
print(f"\n📡 Received signal {signum}, shutting down...")
asyncio.create_task(self.stop())
async def main():
"""Main function."""
# Parse command line arguments
host = "0.0.0.0"
port = 8000
if len(sys.argv) > 1:
host = sys.argv[1]
if len(sys.argv) > 2:
port = int(sys.argv[2])
# Create and start server
server = MetricsServer(host, port)
# Setup signal handlers
signal.signal(signal.SIGINT, server.signal_handler)
signal.signal(signal.SIGTERM, server.signal_handler)
try:
await server.start()
except KeyboardInterrupt:
print("\n📡 Keyboard interrupt received")
finally:
await server.stop()
if __name__ == "__main__":
print("🔧 Starting standalone metrics server...")
print("Usage: python run_metrics_only.py [host] [port]")
print("Default: host=0.0.0.0, port=8000")
print()
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\n🛑 Server stopped by user")
except Exception as e:
print(f"❌ Server error: {e}")
sys.exit(1)