Skip to content

Commit 0adbfc6

Browse files
Refactor API endpoint URL in graphs.js and remove unnecessary import
1 parent f762469 commit 0adbfc6

7 files changed

Lines changed: 22 additions & 261 deletions

File tree

app.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
from src.config import app
22
from src import routes
3-
from src.background_task import start_website_monitoring, monitor_settings, fetch_file_metrics_task
4-
import os
3+
from src.background_task import start_background_tasks
4+
5+
# Start the background tasks
6+
start_background_tasks()
57

6-
# background thread to monitor system settings changes
7-
if os.getenv('FLASK_ENV') == 'production':
8-
start_website_monitoring() # Starts pinging active websites
9-
fetch_file_metrics_task()
10-
monitor_settings() # Starts monitoring for system logging changes
118

129
if __name__ == "__main__":
1310
app.run(host="0.0.0.0", port=5000, debug=True)

src/background_task/__init__.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1+
import os
12
from src.background_task.monitor_website import start_website_monitoring
23
from src.background_task.log_system_info import monitor_settings
34
from src.background_task.prometheus_helper import fetch_file_metrics_task
5+
from src.logger import logger
46

5-
__all__ = ["start_website_monitoring", "monitor_settings", "fetch_file_metrics_task"]
7+
8+
9+
def start_background_tasks():
10+
"""
11+
Starts the background tasks for the application.
12+
"""
13+
if os.getenv('FLASK_ENV') == 'production':
14+
logger.info("Starting background tasks for production environment.")
15+
start_website_monitoring()
16+
fetch_file_metrics_task()
17+
monitor_settings()
18+
else:
19+
logger.info("Background tasks are not started in development environment.")

src/background_task/log_system_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from src.logger import logger
1111
# Flag to track if logging is already scheduled
1212
is_logging_scheduled = False
13-
fetch_system_info_interval = 30
13+
fetch_system_info_interval = 10
1414

1515
# Initialize Prometheus metrics
1616
metrics = {
@@ -175,7 +175,7 @@ def monitor_settings():
175175
is_logging_scheduled = False
176176

177177
# Recheck settings every 10 seconds
178-
Timer(30, monitor_settings).start()
178+
Timer(10, monitor_settings).start()
179179

180180
except SQLAlchemyError as db_err:
181181
logger.error(f"Error fetching settings: {db_err}", exc_info=True)

src/background_task/thread_process.py

Lines changed: 0 additions & 248 deletions
This file was deleted.

src/scripts/prometheus.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mkdir -p "$PROMETHEUS_CONFIG_DIR"
2323
log "Generating prometheus.yml configuration file."
2424
cat > "$PROMETHEUS_CONFIG_FILE" <<EOL
2525
global:
26-
scrape_interval: 30s # How often Prometheus scrapes the target
26+
scrape_interval: 10s # How often Prometheus scrapes the target
2727
2828
scrape_configs:
2929
- job_name: 'flask_app_metrics' # Scraping metrics from Flask app

src/static/js/graphs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ function createChart(ctx, labels, datasets, yLabel) {
165165
scales: {
166166
x: {
167167
type: 'category',
168-
reverse: true, // Reverse the x-axis to start from the right
169168
title: {
170169
display: true,
171170
text: 'Time'

src/static/js/graphs_experimental.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ function createChart(ctx, labels, datasets, yLabel) {
167167
scales: {
168168
x: {
169169
type: 'category',
170-
reverse: true, // Reverse the x-axis to start from the right
171170
title: {
172171
display: true,
173172
text: 'Time'

0 commit comments

Comments
 (0)