From 491b17f086184442e5a9d794d68424cdbef762cb Mon Sep 17 00:00:00 2001 From: Kalzu Rekku Date: Sat, 5 Apr 2025 22:41:26 +0300 Subject: [PATCH] Working to make basic information to be visible. --- Dockerfile | 5 +++-- app/database/schema.sql | 22 +++++++++++----------- app/templates/node_detail.html | 2 +- gunicorn.conf.py | 4 ++++ 4 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 gunicorn.conf.py diff --git a/Dockerfile b/Dockerfile index ae63555..dedaee9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,7 @@ RUN apk add --no-cache sqlite-libs \ && adduser -S -G appgroup appuser # Copy requirements first (optimization for caching) +COPY gunicorn.conf.py . COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt @@ -35,5 +36,5 @@ USER appuser # Expose port EXPOSE 5000 -# Run the application -CMD ["python", "main.py"] +# Run the application with Gunicorn +CMD ["gunicorn", "--config", "gunicorn.conf.py", "main:app"] diff --git a/app/database/schema.sql b/app/database/schema.sql index b39b26b..ea0a6f0 100644 --- a/app/database/schema.sql +++ b/app/database/schema.sql @@ -1,5 +1,5 @@ -- Table for node authentication information (unchanged) -CREATE TABLE node_auth ( +CREATE TABLE IF NOT EXISTS node_auth ( node_id INTEGER PRIMARY KEY AUTOINCREMENT, node_name TEXT NOT NULL UNIQUE, api_key TEXT NOT NULL, @@ -16,7 +16,7 @@ CREATE TABLE IF NOT EXISTS admin_keys ( ); -- Updated table for basic node information with new fields -CREATE TABLE node_info ( +CREATE TABLE IF NOT EXISTS node_info ( node_id INTEGER PRIMARY KEY, hostname TEXT NOT NULL, node_nickname TEXT, @@ -34,7 +34,7 @@ CREATE TABLE node_info ( ); -- Table for node-to-node connection metrics -CREATE TABLE node_connections ( +CREATE TABLE IF NOT EXISTS node_connections ( connection_id INTEGER PRIMARY KEY AUTOINCREMENT, source_node_id INTEGER, target_node_id INTEGER, @@ -46,7 +46,7 @@ CREATE TABLE node_connections ( ); -- Timeseries table for CPU usage -CREATE TABLE cpu_usage ( +CREATE TABLE IF NOT EXISTS cpu_usage ( measurement_id INTEGER PRIMARY KEY AUTOINCREMENT, node_id INTEGER, cpu_percent REAL, @@ -56,7 +56,7 @@ CREATE TABLE cpu_usage ( ); -- Timeseries table for memory usage -CREATE TABLE memory_usage ( +CREATE TABLE IF NOT EXISTS memory_usage ( measurement_id INTEGER PRIMARY KEY AUTOINCREMENT, node_id INTEGER, memory_used_mb INTEGER, @@ -67,7 +67,7 @@ CREATE TABLE memory_usage ( ); -- Timeseries table for disk usage -CREATE TABLE disk_usage ( +CREATE TABLE IF NOT EXISTS disk_usage ( measurement_id INTEGER PRIMARY KEY AUTOINCREMENT, node_id INTEGER, disk_used_gb INTEGER, @@ -79,7 +79,7 @@ CREATE TABLE disk_usage ( ); -- Table for network usage -CREATE TABLE network_usage ( +CREATE TABLE IF NOT EXISTS network_usage ( measurement_id INTEGER PRIMARY KEY AUTOINCREMENT, node_id INTEGER, bytes_sent INTEGER, @@ -91,7 +91,7 @@ CREATE TABLE network_usage ( ); -- Table process monitoring -CREATE TABLE process_stats ( +CREATE TABLE IF NOT EXISTS process_stats ( measurement_id INTEGER PRIMARY KEY AUTOINCREMENT, node_id INTEGER, process_count INTEGER, @@ -101,7 +101,7 @@ CREATE TABLE process_stats ( ); -- Table for monitoring configuration and alarm thresholds -CREATE TABLE monitoring_config ( +CREATE TABLE IF NOT EXISTS monitoring_config ( config_id INTEGER PRIMARY KEY AUTOINCREMENT, node_id INTEGER, cpu_threshold_percent REAL, @@ -116,7 +116,7 @@ CREATE TABLE monitoring_config ( ); -- Table for alarm history -CREATE TABLE alarm_history ( +CREATE TABLE IF NOT EXISTS alarm_history ( alarm_id INTEGER PRIMARY KEY AUTOINCREMENT, node_id INTEGER, alarm_type TEXT CHECK(alarm_type IN ('cpu', 'memory', 'disk', 'temperature', @@ -130,7 +130,7 @@ CREATE TABLE alarm_history ( ); -- Table for node status events -CREATE TABLE node_events ( +CREATE TABLE IF NOT EXISTS node_events ( event_id INTEGER PRIMARY KEY AUTOINCREMENT, node_id INTEGER, event_type TEXT CHECK(event_type IN ('online', 'offline', 'error', 'warning')), diff --git a/app/templates/node_detail.html b/app/templates/node_detail.html index 53987ed..c7f6744 100644 --- a/app/templates/node_detail.html +++ b/app/templates/node_detail.html @@ -177,7 +177,7 @@ x: { ticks: { color: '#aaa' }, grid: { color: 'rgba(255, 255, 255, 0.1)' } }, y: { min: 0, - max: 100, + max: 400, ticks: { color: '#aaa' }, grid: { color: 'rgba(255, 255, 255, 0.1)' } } diff --git a/gunicorn.conf.py b/gunicorn.conf.py new file mode 100644 index 0000000..b6e13c4 --- /dev/null +++ b/gunicorn.conf.py @@ -0,0 +1,4 @@ +bind = "0.0.0.0:5000" +workers = 2 # Adjust based on your needs (e.g., 2 * CPU cores + 1) +threads = 4 # Number of threads per worker +timeout = 30 # Worker timeout in seconds