Skip to content

Commit de03d7e

Browse files
chore: Set up Dockerfile, app.py, docker-compose.yml, requirements.txt, static files, and templates for server dashboard application
1 parent 6ddb600 commit de03d7e

7 files changed

Lines changed: 160 additions & 0 deletions

File tree

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use an official Python runtime as a parent image
2+
FROM python:3.9-slim
3+
4+
# Set the working directory in the container
5+
WORKDIR /app
6+
7+
# Copy the current directory contents into the container at /app
8+
COPY . /app
9+
10+
# Install any needed packages specified in requirements.txt
11+
RUN pip install --no-cache-dir -r requirements.txt
12+
13+
# Make port 5000 available to the world outside this container
14+
EXPOSE 5000
15+
16+
# Define environment variable
17+
ENV FLASK_APP=app.py
18+
19+
# Run app.py when the container launches
20+
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "app:app"]

app.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from flask import Flask, render_template
2+
import os
3+
import psutil
4+
5+
app = Flask(__name__)
6+
7+
def get_system_info():
8+
info = {
9+
'username': os.getlogin(),
10+
'cpu_percent': psutil.cpu_percent(interval=1),
11+
'memory_percent': psutil.virtual_memory().percent,
12+
'disk_usage': psutil.disk_usage('/').percent,
13+
'battery_percent': psutil.sensors_battery().percent if psutil.sensors_battery() else "N/A",
14+
}
15+
return info
16+
17+
@app.route('/')
18+
def dashboard():
19+
system_info = get_system_info()
20+
return render_template('dashboard.html', system_info=system_info)
21+
22+
if __name__ == '__main__':
23+
app.run(host='0.0.0.0', port=5000)

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: '3'
2+
3+
services:
4+
flask-app:
5+
build: .
6+
ports:
7+
- "5000:5000"
8+
volumes:
9+
- .:/app
10+
environment:
11+
FLASK_ENV: producntion

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Flask==2.3.3
2+
psutil==5.9.5
3+
gunicorn

static/css/style.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
body {
2+
font-family: 'Arial', sans-serif;
3+
background-color: #f4f4f4;
4+
color: #333;
5+
}
6+
7+
header {
8+
background: linear-gradient(135deg, #007bff, #00d2ff);
9+
color: #fff;
10+
padding: 20px;
11+
border-bottom: 2px solid #0056b3;
12+
}
13+
14+
.card {
15+
transition: transform 0.3s ease, box-shadow 0.3s ease;
16+
border: 1px solid #e0e0e0;
17+
}
18+
19+
.card:hover {
20+
transform: translateY(-10px);
21+
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
22+
}
23+
24+
.card-title {
25+
font-size: 1.25rem;
26+
font-weight: bold;
27+
}
28+
29+
.card-text {
30+
font-size: 1.125rem;
31+
}
32+
33+
@media (max-width: 768px) {
34+
.card {
35+
margin-bottom: 1rem;
36+
}
37+
}

static/js/script.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$(document).ready(function() {
2+
// Any custom JS animations or functionalities can go here.
3+
});

templates/dashboard.html

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Server Dashboard</title>
7+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
8+
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
9+
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
10+
</head>
11+
<body>
12+
<header class="bg-primary text-white text-center py-4">
13+
<h1 class="display-4">Server Dashboard</h1>
14+
</header>
15+
<div class="container mt-5">
16+
<div class="row mt-4">
17+
<div class="col-md-6 col-lg-4 mb-4">
18+
<div class="card shadow-sm border-0 rounded-3">
19+
<div class="card-body">
20+
<h5 class="card-title">Username <i class="fa fa-user"></i></h5>
21+
<p class="card-text fs-4">{{ system_info['username'] }}</p>
22+
</div>
23+
</div>
24+
</div>
25+
<div class="col-md-6 col-lg-4 mb-4">
26+
<div class="card shadow-sm border-0 rounded-3">
27+
<div class="card-body">
28+
<h5 class="card-title">CPU Usage <i class="fa fa-microchip"></i></h5>
29+
<p class="card-text fs-4">{{ system_info['cpu_percent'] }}%</p>
30+
</div>
31+
</div>
32+
</div>
33+
<div class="col-md-6 col-lg-4 mb-4">
34+
<div class="card shadow-sm border-0 rounded-3">
35+
<div class="card-body">
36+
<h5 class="card-title">Memory Usage <i class="fa fa-memory"></i></h5>
37+
<p class="card-text fs-4">{{ system_info['memory_percent'] }}%</p>
38+
</div>
39+
</div>
40+
</div>
41+
<div class="col-md-6 col-lg-4 mb-4">
42+
<div class="card shadow-sm border-0 rounded-3">
43+
<div class="card-body">
44+
<h5 class="card-title">Disk Usage <i class="fa fa-hdd"></i></h5>
45+
<p class="card-text fs-4">{{ system_info['disk_usage'] }}%</p>
46+
</div>
47+
</div>
48+
</div>
49+
<div class="col-md-6 col-lg-4 mb-4">
50+
<div class="card shadow-sm border-0 rounded-3">
51+
<div class="card-body">
52+
<h5 class="card-title">Battery Percentage <i class="fa fa-battery-three-quarters"></i></h5>
53+
<p class="card-text fs-4">{{ system_info['battery_percent'] }}%</p>
54+
</div>
55+
</div>
56+
</div>
57+
</div>
58+
</div>
59+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
60+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
61+
<script src="{{ url_for('static', filename='js/script.js') }}"></script>
62+
</body>
63+
</html>

0 commit comments

Comments
 (0)