-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9636f0
commit 555d768
Showing
4 changed files
with
90 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
from flask import request, render_template, blueprints | ||
import os | ||
from flask import request, render_template, blueprints, redirect, url_for, flash | ||
|
||
from src.config import app | ||
from src.utils import get_top_processes | ||
|
||
process_bp = blueprints.Blueprint("process", __name__) | ||
|
||
|
||
@app.route("/process", methods=["GET", "POST"]) | ||
def process(): | ||
number_of_processes = 5 # Default number | ||
|
||
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: | ||
os.kill(int(pid_to_kill), 9) # Sends a SIGKILL signal | ||
flash(f"Process '{process_name}' (PID {pid_to_kill}) killed successfully.", "success") | ||
except Exception as e: | ||
flash(f"Failed to kill process '{process_name}' (PID {pid_to_kill}). Error: {e}", "danger") | ||
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)) | ||
|
||
top_processes = get_top_processes(number_of_processes) | ||
return render_template("process.html", processes=top_processes, number=number_of_processes) | ||
return render_template("process.html", processes=top_processes, number=number_of_processes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
<nav class="navbar navbar-expand-lg navbar-light bg-light shadow-sm"><a class="navbar-brand d-flex align-items-center{% if request.endpoint=='dashboard' %}active{% endif %}" href="{{ url_for('dashboard')}}"><i class="fas fa-home mr-2"></i>Home </a><button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button><div class="collapse navbar-collapse" id="navbarNav"><ul class="navbar-nav ml-auto"><li class="nav-item"><a class="nav-link{% if request.endpoint=='cpu_usage' %}active{% endif %}" href="{{ url_for('cpu_usage')}}"><i class="fas fa-microchip mr-1"></i>CPU Info </a></li><li class="nav-item"><a class="nav-link{% if request.endpoint=='memory_usage' %}active{% endif %}" href="{{ url_for('memory_usage')}}"><i class="fas fa-memory mr-1"></i>Memory Info </a></li><li class="nav-item"><a class="nav-link{% if request.endpoint=='disk_usage' %}active{% endif %}" href="{{ url_for('disk_usage')}}"><i class="fas fa-hdd mr-1"></i>Disk Info </a></li><li class="nav-item"><a class="nav-link{% if request.endpoint=='network_stats' %}active{% endif %}" href="{{ url_for('network_stats')}}"><i class="fas fa-network-wired mr-1"></i>Network Info </a></li><li class="nav-item"><a class="nav-link{% if request.endpoint=='settings' %}active{% endif %}" href="{{ url_for('settings')}}"><i class="fas fa-cog mr-1"></i>Settings </a></li><li class="nav-item"><a class="nav-link{% if request.endpoint=='process' %}active{% endif %}" href="{{ url_for('process')}}"><i class="fas fa-tasks mr-1"></i>Process </a></li></ul></div></nav> | ||
<nav class="navbar navbar-expand-lg navbar-light bg-light shadow-sm"><a | ||
class="navbar-brand d-flex align-items-center{% if request.endpoint=='dashboard' %}active{% endif %}" | ||
href="{{ url_for('dashboard')}}"><i class="fas fa-home mr-2"></i>Home </a><button class="navbar-toggler" | ||
type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" | ||
aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button> | ||
<div class="collapse navbar-collapse" id="navbarNav"> | ||
<ul class="navbar-nav ml-auto"> | ||
<li class="nav-item"><a class="nav-link{% if request.endpoint=='cpu_usage' %}active{% endif %}" | ||
href="{{ url_for('cpu_usage')}}"><i class="fas fa-microchip mr-1"></i>CPU Info </a></li> | ||
<li class="nav-item"><a class="nav-link{% if request.endpoint=='memory_usage' %}active{% endif %}" | ||
href="{{ url_for('memory_usage')}}"><i class="fas fa-memory mr-1"></i>Memory Info </a></li> | ||
<li class="nav-item"><a class="nav-link{% if request.endpoint=='disk_usage' %}active{% endif %}" | ||
href="{{ url_for('disk_usage')}}"><i class="fas fa-hdd mr-1"></i>Disk Info </a></li> | ||
<li class="nav-item"><a class="nav-link{% if request.endpoint=='network_stats' %}active{% endif %}" | ||
href="{{ url_for('network_stats')}}"><i class="fas fa-network-wired mr-1"></i>Network Info </a></li> | ||
<li class="nav-item"><a class="nav-link{% if request.endpoint=='settings' %}active{% endif %}" | ||
href="{{ url_for('settings')}}"><i class="fas fa-cog mr-1"></i>Settings </a></li> | ||
<li class="nav-item"><a class="nav-link{% if request.endpoint=='process' %}active{% endif %}" | ||
href="{{ url_for('process')}}"><i class="fas fa-tasks mr-1"></i>Process </a></li> | ||
</ul> | ||
</div> | ||
</nav> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
{% extends 'base.html' %}{% block title %}CPU Usage Details{% endblock %}{% block extra_head %}<link rel="stylesheet" href="{{ url_for('static', filename='css/process.css')}}">{% endblock %}{% block content %}<div class="container"><h1>Top Processes by Memory Usage</h1><form method="post" class="form-control"><label for="number">Number of Processes:</label><input type="number" id="number" name="number" min="1" value="{{ number}}"><button type="submit">Show</button></form><table><thead><tr><th>Process Name</th><th>CPU Usage (%)</th><th>Memory Usage (%)</th></tr></thead><tbody>{% for process in processes %} <tr><td>{{ process[0]}}</td><td>{{ process[1]}}</td><td>{{ process[2]}}</td></tr>{% endfor %} </tbody></table></div>{% endblock %} | ||
{% extends 'base.html' %} | ||
{% block title %}CPU Usage Details{% endblock %} | ||
{% block extra_head %} | ||
<link rel="stylesheet" href="{{ url_for('static', filename='css/process.css') }}"> | ||
{% endblock %} | ||
{% block content %} | ||
<div class="container"> | ||
<h1>Top Processes by Memory Usage</h1> | ||
|
||
<!-- Display flash messages --> | ||
{% include 'ext/message.html' %} | ||
|
||
<form method="post" class="form-control"> | ||
<label for="number">Number of Processes:</label> | ||
<input type="number" id="number" name="number" min="1" value="{{ number }}"> | ||
<button type="submit">Show</button> | ||
</form> | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
<th>Process Name</th> | ||
<th>CPU Usage (%)</th> | ||
<th>Memory Usage (%)</th> | ||
<th>Action</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for process in processes %} | ||
<tr> | ||
<td>{{ process[0] }}</td> | ||
<td>{{ process[1] }}</td> | ||
<td>{{ process[2] }}</td> | ||
<td> | ||
<form method="post"> | ||
<input type="hidden" name="kill_pid" value="{{ process[3] }}"> | ||
<input type="hidden" name="process_name" value="{{ process[0] }}"> | ||
<button type="submit">Kill</button> | ||
</form> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters