Skip to content

Commit 58f345a

Browse files
chore: Update server time display on dashboard
1 parent ef05db8 commit 58f345a

3 files changed

Lines changed: 53 additions & 8 deletions

File tree

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
System Dashboard is a Flask app designed to monitor server stats such as CPU, Memory, Disk, and Network. It also provides real-time monitoring capabilities which can be useful for system administrators, developers, and DevOps engineers to keep track of their server's performance and troubleshoot issues. The app uses the `psutil` library to retrieve system stats and the `speedtest-cli` library to perform a network speed test.
44

5-
## Installation
5+
## Installation
6+
7+
### For running once
68

79
1. Clone the repository:
810

@@ -28,6 +30,14 @@ python app.py
2830
http://localhost:5000
2931
```
3032

33+
### For cronjob
34+
35+
Task will be added to cronjob to run the script every minute and app will be stay active on port 5050 even after closing the terminal and rebooting the system.
36+
37+
```bash
38+
bash cronjob.sh
39+
```
40+
3141
## Features
3242

3343
- Monitor server stats like CPU, Memory, Disk, and Network.
@@ -38,23 +48,23 @@ http://localhost:5000
3848

3949
### HomePage
4050

41-
![HomePage](/static/images/dashboard.png)
51+
![HomePage](/src/static/images/dashboard.png)
4252

4353
### CPU Stats
4454

45-
![CPU Stats](/static/images/cpu.png)
55+
![CPU Stats](/src/static/images/cpu.png)
4656

4757
### Memory Stats
4858

49-
![Memory Stats](/static/images/memory.png)
59+
![Memory Stats](/src/static/images/memory.png)
5060

5161
### Disk Stats
5262

53-
![Disk Stats](/static/images/disk.png)
63+
![Disk Stats](/src/static/images/disk.png)
5464

5565
### Speed Test
5666

57-
![Speed Test](/static/images/speedtest.png)
67+
![Speed Test](/src/static/images/speedtest.png)
5868

5969
## Why not use a Docker image?
6070

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1-
<div class="col-md-6 col-lg-4 mb-4"><div class="card bg-boot"><div class="card-body"><h5 class="card-title">Boot Time <i class="fas fa-clock"></i></h5><p class="card-text fs-4">{{ system_info['boot_time']}}</p></div></div></div>
1+
<div class="col-md-6 col-lg-4 mb-4">
2+
<div class="card bg-boot">
3+
<div class="card-body">
4+
<h5 class="card-title">Server Time <i class="fas fa-clock"></i></h5>
5+
<p class="card-text fs-4" id="server-time">{{ system_info['current_server_time'] }}</p>
6+
</div>
7+
</div>
8+
</div>
9+
10+
<script>
11+
// Function to format time in HH:MM:SS
12+
function formatTime(hours, minutes, seconds) {
13+
return [
14+
hours.toString().padStart(2, '0'),
15+
minutes.toString().padStart(2, '0'),
16+
seconds.toString().padStart(2, '0')
17+
].join(':');
18+
}
19+
20+
// Initialize the time from the server
21+
let serverTime = new Date('{{ system_info["current_server_time"] }}');
22+
let timeElement = document.getElementById('server-time');
23+
24+
// Update the time every second
25+
setInterval(() => {
26+
// Increment the server time by 1 second
27+
serverTime.setSeconds(serverTime.getSeconds() + 1);
28+
// Update the displayed time
29+
timeElement.textContent = formatTime(
30+
serverTime.getHours(),
31+
serverTime.getMinutes(),
32+
serverTime.getSeconds()
33+
);
34+
}, 1000);
35+
</script>

src/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def get_system_info():
122122
memory_info = psutil.virtual_memory()
123123
disk_info = psutil.disk_usage('/')
124124
net_io = psutil.net_io_counters()
125-
125+
current_server_time = datetime.datetime.now()
126126
# Prepare system information dictionary
127127
info = {
128128
'username': os.getlogin(),
@@ -142,6 +142,7 @@ def get_system_info():
142142
'timestamp': datetime.datetime.now(),
143143
'cpu_frequency': get_cpu_frequency(),
144144
'current_temp': get_cpu_temp()[0],
145+
'current_server_time': datetimeformat(current_server_time),
145146
}
146147

147148
# # Adding system info to the database

0 commit comments

Comments
 (0)