mirror of
https://github.com/sstent/consul-monitor.git
synced 2025-12-06 08:01:58 +00:00
Phase 2 working
This commit is contained in:
@@ -6,13 +6,25 @@ WORKDIR /app
|
|||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
# Install SQLite for debugging
|
||||||
|
RUN apt-get update && apt-get install -y sqlite3
|
||||||
|
|
||||||
# Copy application
|
# Copy application
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Create non-root user
|
# Create non-root user and ensure data directory exists
|
||||||
RUN useradd -m appuser && chown -R appuser:appuser /app
|
RUN mkdir -p /data && \
|
||||||
|
useradd -m appuser && \
|
||||||
|
chown -R appuser:appuser /app /data
|
||||||
|
|
||||||
USER appuser
|
USER appuser
|
||||||
|
|
||||||
|
# Set working directory to application code
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Create data directory for database
|
||||||
|
RUN mkdir -p /data && chown appuser:appuser /data
|
||||||
|
|
||||||
# Expose port
|
# Expose port
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ def get_db():
|
|||||||
"""Get a thread-local database connection"""
|
"""Get a thread-local database connection"""
|
||||||
if 'db_conn' not in g:
|
if 'db_conn' not in g:
|
||||||
g.db_conn = database.init_database()
|
g.db_conn = database.init_database()
|
||||||
database.create_tables(g.db_conn)
|
|
||||||
return g.db_conn
|
return g.db_conn
|
||||||
|
|
||||||
@app.teardown_appcontext
|
@app.teardown_appcontext
|
||||||
@@ -222,6 +221,30 @@ def aggregate_health_data(raw_history, granularity_minutes):
|
|||||||
|
|
||||||
return chart_data
|
return chart_data
|
||||||
|
|
||||||
|
@app.route('/api/debug/db')
|
||||||
|
def debug_db():
|
||||||
|
"""Debug endpoint to inspect database contents"""
|
||||||
|
db_conn = get_db()
|
||||||
|
cursor = db_conn.cursor()
|
||||||
|
|
||||||
|
# Get services
|
||||||
|
cursor.execute("SELECT * FROM services")
|
||||||
|
services = cursor.fetchall()
|
||||||
|
services = [dict(id=row[0], name=row[1], address=row[2], port=row[3],
|
||||||
|
tags=json.loads(row[4]), meta=json.loads(row[5]),
|
||||||
|
first_seen=row[6], last_seen=row[7]) for row in services]
|
||||||
|
|
||||||
|
# Get health checks
|
||||||
|
cursor.execute("SELECT * FROM health_checks")
|
||||||
|
health_checks = cursor.fetchall()
|
||||||
|
health_checks = [dict(id=row[0], service_id=row[1], check_name=row[2],
|
||||||
|
status=row[3], timestamp=row[4]) for row in health_checks]
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'services': services,
|
||||||
|
'health_checks': health_checks
|
||||||
|
})
|
||||||
|
|
||||||
@app.route('/health')
|
@app.route('/health')
|
||||||
def health_check():
|
def health_check():
|
||||||
"""Health check endpoint"""
|
"""Health check endpoint"""
|
||||||
|
|||||||
@@ -67,6 +67,11 @@ class ConsulPoller:
|
|||||||
if not service_data:
|
if not service_data:
|
||||||
logger.warning("No service data received from Consul")
|
logger.warning("No service data received from Consul")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Detailed logging of service data
|
||||||
|
logger.info(f"Received {len(service_data)} services from Consul")
|
||||||
|
for service_id, data in list(service_data.items())[:5]: # Log first 5 services
|
||||||
|
logger.info(f"Service: {service_id}, Name: {data['name']}, Checks: {len(data['health_checks'])}")
|
||||||
|
|
||||||
# Get database connection
|
# Get database connection
|
||||||
conn = self.get_db_conn()
|
conn = self.get_db_conn()
|
||||||
|
|||||||
@@ -44,8 +44,10 @@ def create_tables(conn):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
def init_database():
|
def init_database():
|
||||||
"""Initialize database and return connection"""
|
"""Initialize database, create tables, and return connection"""
|
||||||
return sqlite3.connect('file:consul-monitor.db?mode=memory&cache=shared', uri=True)
|
conn = sqlite3.connect('/data/consul-monitor.db')
|
||||||
|
create_tables(conn)
|
||||||
|
return conn
|
||||||
|
|
||||||
def upsert_service(conn, service_data):
|
def upsert_service(conn, service_data):
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|||||||
Reference in New Issue
Block a user