diff --git a/app.py b/app.py index 8bd2c2b..f9c4685 100644 --- a/app.py +++ b/app.py @@ -5,15 +5,20 @@ def register_routes(): app.register_blueprint(routes.homepage_bp) app.register_blueprint(routes.settings_bp) app.register_blueprint(routes.system_health_bp) - app.register_blueprint(routes.cpu_usage_bp) - app.register_blueprint(routes.disk_usage_bp) - app.register_blueprint(routes.memory_usage_bp) - app.register_blueprint(routes.network_stats_bp) + app.register_blueprint(routes.cpu_info_bp) + app.register_blueprint(routes.disk_info_bp) + app.register_blueprint(routes.memory_info_bp) + app.register_blueprint(routes.network_info_bp) app.register_blueprint(routes.speedtest_bp) app.register_blueprint(routes.process_bp) - - if __name__ == "__main__": + register_routes() + + # # Start the memory-consuming program in a separate thread + # memory_thread = threading.Thread(target=memory_consuming_program, daemon=True) + # memory_thread.start() + + # Run the Flask application app.run(host="0.0.0.0", port=5000, debug=True) diff --git a/locustfile.py b/locustfile.py new file mode 100644 index 0000000..2d07d4f --- /dev/null +++ b/locustfile.py @@ -0,0 +1,48 @@ +from locust import HttpUser, TaskSet, task, between +from locust.exception import StopUser + +class UserBehavior(TaskSet): + + def on_start(self): + """ Called when a Locust user starts running """ + self.login() + + def login(self): + """ Simulate a user logging in """ + response = self.client.post("/login", { + "username": "admin", + "password": "adminpassword" + }) + if response.status_code == 200 and "Invalid username or password" not in response.text: + print("Login successful") + else: + print("Login failed") + raise StopUser("Login failed") + + @task(1) + def view_dashboard(self): + """ Simulate viewing the dashboard """ + self.client.get("/") + + @task(2) + def view_cpu_usage(self): + """ Simulate viewing CPU usage """ + self.client.get("/cpu_usage") + + @task(1) + def view_disk_usage(self): + """ Simulate viewing disk usage """ + self.client.get("/disk_usage") + + @task(1) + def view_memory_usage(self): + """ Simulate viewing memory usage """ + self.client.get("/memory_usage") + +class WebsiteUser(HttpUser): + tasks = [UserBehavior] + wait_time = between(1, 5) # Time to wait between tasks + +if __name__ == "__main__": + import os + os.system("locust -f locustfile.py --host=http://localhost:5000") diff --git a/src/models.py b/src/models.py index a5453fa..c0ac68a 100644 --- a/src/models.py +++ b/src/models.py @@ -48,6 +48,8 @@ class SystemInfo(db.Model): ipv4_connections = db.Column(db.String(50)) dashboard_memory_usage = db.Column(db.String(50)) timestamp = db.Column(db.DateTime, default=datetime.datetime.now()) + cpu_frequency = db.Column(db.String(50)) + current_temp = db.Column(db.String(50)) def __repr__(self): return f"" diff --git a/src/routes/homepage.py b/src/routes/homepage.py index ae91ac9..811ee25 100644 --- a/src/routes/homepage.py +++ b/src/routes/homepage.py @@ -2,7 +2,7 @@ from flask import render_template, blueprints from src.config import app -from src.models import SpeedTestResult, DashboardSettings +from src.models import SpeedTestResult, DashboardSettings, SystemInfo from src.utils import datetimeformat, get_system_info homepage_bp = blueprints.Blueprint("homepage", __name__) diff --git a/src/routes/process.py b/src/routes/process.py index 8c07708..f1b5cb1 100644 --- a/src/routes/process.py +++ b/src/routes/process.py @@ -1,7 +1,6 @@ import os -from flask import request, render_template, blueprints, redirect, url_for, flash +from flask import request, render_template, redirect, url_for, flash, session, blueprints from flask_login import login_required, current_user - from src.config import app from src.utils import get_top_processes @@ -14,11 +13,14 @@ def process(): flash("You do not have permission to view this page.", "danger") return redirect(url_for("dashboard")) - number_of_processes = 5 # Default number + # Retrieve number of processes from session or set default + number_of_processes = session.get('number_of_processes', 50) + sort_by = request.args.get('sort', 'cpu') # Default to sort by CPU usage + order = request.args.get('order', 'asc') # Default to ascending order + toggle_order = 'desc' if order == 'asc' else 'asc' # Toggle order for next click if request.method == "POST": if "kill_pid" in request.form: - # Handle killing the process pid_to_kill = request.form.get("kill_pid") process_name = request.form.get("process_name") try: @@ -29,7 +31,18 @@ def process(): return redirect(url_for("process")) # Refresh the page after killing process # Handle the number of processes to display - number_of_processes = int(request.form.get("number", 5)) + number_of_processes = int(request.form.get("number", 50)) + session['number_of_processes'] = number_of_processes # Store the number in session + # Retrieve processes top_processes = get_top_processes(number_of_processes) - return render_template("process.html", processes=top_processes, number=number_of_processes) + + # Sorting logic based on selected criteria + if sort_by == 'cpu': + top_processes.sort(key=lambda x: x[1], reverse=(order == 'desc')) + elif sort_by == 'memory': + top_processes.sort(key=lambda x: x[2], reverse=(order == 'desc')) + elif sort_by == 'name': + top_processes.sort(key=lambda x: x[0], reverse=(order == 'desc')) + + return render_template("process.html", processes=top_processes, number=number_of_processes, toggle_order=toggle_order) diff --git a/src/static/css/process.css b/src/static/css/process.css index a61d515..d18566f 100644 --- a/src/static/css/process.css +++ b/src/static/css/process.css @@ -1,71 +1,105 @@ body { - font-family: Arial, sans-serif; - background-color: #f4f4f4; + font-family: 'Roboto', sans-serif; /* Use a modern font */ + background-color: #f8f9fa; /* Light gray background for contrast */ margin: 0; padding: 0; + color: #212529; /* Dark gray text for readability */ } .container { - width: 80%; - margin: 20px auto; - padding: 20px; - background-color: white; - border-radius: 8px; - box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + max-width: 1200px; /* Limit the maximum width */ + margin: 40px auto; /* Increased margin for spacing */ + padding: 30px; /* More padding for content */ + background-color: #ffffff; /* White background for content */ + border-radius: 10px; /* Slightly rounded corners */ + box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1); /* Subtle shadow for depth */ } h1 { - color: #333; + color: #343a40; /* Darker shade for the heading */ text-align: center; + margin-bottom: 20px; + font-weight: 700; /* Bolder font */ } .form-control { - margin-bottom: 20px; + margin-bottom: 25px; /* Consistent spacing */ display: flex; justify-content: center; align-items: center; + gap: 10px; /* Modern spacing with gap */ } label { - margin-right: 10px; + font-weight: 500; /* Medium font weight for labels */ } input[type="number"] { - width: 60px; - padding: 5px; - margin-right: 10px; + width: 80px; /* Slightly wider input */ + padding: 8px; + border: 1px solid #ced4da; /* Light border */ + border-radius: 5px; + transition: border-color 0.3s; /* Smooth transition on focus */ +} + +input[type="number"]:focus { + border-color: #007bff; /* Blue border on focus */ + outline: none; } button { - padding: 5px 15px; - background-color: #007bff; - color: white; + padding: 8px 20px; + background-color: #007bff; /* Primary color */ + color: #ffffff; /* White text */ border: none; - border-radius: 4px; + border-radius: 5px; cursor: pointer; + transition: background-color 0.3s, transform 0.2s; /* Smooth transitions */ } button:hover { - background-color: #0056b3; + background-color: #0056b3; /* Darker blue on hover */ + transform: translateY(-2px); /* Lift effect */ } - table { width: 100%; border-collapse: collapse; margin-top: 20px; + font-size: 0.9rem; } th, td { - padding: 10px; - border-bottom: 1px solid #ddd; + padding: 12px 15px; + border-bottom: 1px solid #dee2e6; text-align: left; } th { - background-color: #007bff; - color: white; + background-color: #0056b3; /* Darker blue for better contrast */ + color: #ffffff; /* White text for visibility */ + font-weight: 600; /* Slightly bolder text */ + text-transform: uppercase; /* Uppercase for a modern touch */ + position: sticky; /* Sticky header for better navigation */ + top: 0; + padding: 15px 10px; /* More padding for a balanced look */ + letter-spacing: 0.5px; /* Slight letter spacing for readability */ } tr:hover { - background-color: #f1f1f1; + background-color: #f1f3f5; /* Light gray on row hover */ } + +td button { + background-color: #dc3545; + border-radius: 5px; + transition: background-color 0.3s, transform 0.2s; +} + +td button:hover { + background-color: #c82333; + transform: translateY(-2px); +} + +.name { + color: #ffffff; /* White text for visibility */ +} \ No newline at end of file diff --git a/src/templates/cpu_info.html b/src/templates/cpu_info.html index bd6318c..8503fae 100644 --- a/src/templates/cpu_info.html +++ b/src/templates/cpu_info.html @@ -1 +1,7 @@ -{% extends 'base.html' %}{% block title %}CPU Usage Details{% endblock %}{% block content %}

CPU Details

{% include 'dasbhboard_comp/cpu/core.html' %} {% include 'dasbhboard_comp/cpu/frequency.html' %} {% include 'dasbhboard_comp/cpu/usages.html' %} {% include 'dasbhboard_comp/cpu/current_temp.html' %} {% include 'dasbhboard_comp/cpu/highest_temp.html' %} {% include 'dasbhboard_comp/cpu/critical_temp.html' %}
{% endblock %} \ No newline at end of file +{% extends 'base.html' %}{% block title %}CPU Usage Details{% endblock %}{% block content %}

CPU Details +

+
+
{% include 'dasbhboard_comp/cpu/core.html' %} {% include 'dasbhboard_comp/cpu/frequency.html' %} {% + include 'dasbhboard_comp/cpu/usages.html' %} {% include 'dasbhboard_comp/cpu/current_temp.html' %} {% include + 'dasbhboard_comp/cpu/highest_temp.html' %} {% include 'dasbhboard_comp/cpu/critical_temp.html' %}
+
{% endblock %} \ No newline at end of file diff --git a/src/templates/ext/navbar.html b/src/templates/ext/navbar.html index fcf4c20..2be91e9 100644 --- a/src/templates/ext/navbar.html +++ b/src/templates/ext/navbar.html @@ -54,6 +54,11 @@ Logout + {% else %}