Skip to content

Commit f2a1d51

Browse files
chore; chart improved, prometheus basic auth changed to flask login
1 parent 9a47e88 commit f2a1d51

File tree

11 files changed

+36
-20
lines changed

11 files changed

+36
-20
lines changed

src/docs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Home Page
44

5-
![screenshot_002](/src/static/images/screenshot_002.png)
5+
![screenshot_002](/src/static/images/screenshot_009.png)
66

77
## Cpu Info
88

src/docs/Release.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
# Release Notes: SystemGuard
22

3+
## SystemGuard v1.0.5 Stable Release
4+
5+
- Version: v1.0.5
6+
- Release Date:
7+
- Status: Testing
8+
9+
### Key Features
10+
11+
All the features of the previous pre-release version are included in this stable release with additional improvements and bug fixes.
12+
313
## SystemGuard v1.0.5 Pre Release
414

515
- Version: v1.0.5-pre
6-
- Release Date: September 20, 2024
7-
- Status: In Development
16+
- Release Date: September 24, 2024
17+
- Status: Released
818

919
### Key Features
1020

21+
- **Prometheus Integration:** Added Prometheus support for advanced monitoring capabilities.
22+
- **Central Monitoring:** Centralized monitoring of multiple servers from a single dashboard.
1123
- **Admin Privileges:** Improved User/Admin roles for better access control.
1224
- **User Settings:** Added some basic user settings for user customization.
1325
- **UI Enhancements:** Improved control panel UI for better user experience.

src/routes/prometheus.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import os
44
import yaml
55
from collections import OrderedDict
6+
from werkzeug.security import check_password_hash
67

78
from src.config import app, db
8-
from src.models import ExternalMonitornig
9+
from src.models import ExternalMonitornig, UserProfile
910
from src.utils import ROOT_DIR
1011
from src.routes.helper.common_helper import admin_required
1112
from src.routes.helper.prometheus_helper import (
@@ -21,15 +22,16 @@
2122
# Define the Prometheus Blueprint
2223
prometheus_bp = Blueprint('prometheus', __name__)
2324

24-
# todo, find a better way to store the username and password
25-
username = 'prometheus_admin'
26-
password = 'prometheus_password'
25+
def verify_user(username, password):
26+
user = UserProfile.query.filter_by(username=username).first()
27+
if user and check_password_hash(user.password, password):
28+
return True
2729

2830
# Define a route to serve Prometheus metrics
2931
@app.route('/metrics')
3032
def metrics():
3133
auth = request.authorization
32-
if not auth or not (auth.username == username and auth.password == password):
34+
if not verify_user(auth.username, auth.password):
3335
return Response('Could not verify', 401, {'WWW-Authenticate': 'Basic realm="Login required"'})
3436
output = generate_latest()
3537
output = '\n'.join([line for line in output.decode().split('\n') if not line.startswith('#') and line])

src/scripts/prometheus.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ FLASK_APP_IP=$(hostname -I | cut -d' ' -f1)
2828
FLASK_APP_PORT="5050"
2929
SCRAPING_INTERVAL="10s"
3030
monitor='systemguard-metrics'
31+
# fetch the prometheus username and password from the .env file
32+
prometheus_username='prometheus_admin'
33+
prometheus_password='prometheus_password'
3134

3235
# Logging function for better readability
3336
log() {
@@ -55,8 +58,8 @@ scrape_configs:
5558
- targets:
5659
- '$FLASK_APP_IP:$FLASK_APP_PORT'
5760
basic_auth:
58-
username: prometheus_admin
59-
password: prometheus_password
61+
username: $prometheus_username
62+
password: $prometheus_password
6063
6164
EOL
6265

src/static/images/screenshot_009.png

482 KB
Loading

src/static/js/cardChart.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const maxDataPoints = 500; // Number of data points to show on the chart
22

33
// Generalized function to create and update a line chart
4-
function createLineChart(canvasId, label, dataStorage, updateFunc) {
5-
console.log(dataStorage);
4+
function createLineChart(canvasId, label, dataStorage, borderColor, updateFunc) {
65
const ctx = document.getElementById(canvasId).getContext('2d');
76
const chart = new Chart(ctx, {
87
type: 'line',
@@ -11,7 +10,7 @@ function createLineChart(canvasId, label, dataStorage, updateFunc) {
1110
datasets: [{
1211
label: label,
1312
data: dataStorage,
14-
borderColor: 'red',
13+
borderColor: borderColor,
1514
borderWidth: 2,
1615
fill: true,
1716
opacity: 0.5,
@@ -57,7 +56,7 @@ function createLineChart(canvasId, label, dataStorage, updateFunc) {
5756
// Set interval to fetch and update data every 2 seconds
5857
setInterval(() => {
5958
const newUsage = updateFunc(); // Call the update function to get the current usage
60-
console.log(`${label} Usage:`, newUsage);
59+
// console.log(`${label} Usage:`, newUsage);
6160
updateChart(newUsage);
6261
}, 300);
6362
}

src/templates/card_comp/cpu/current_temp.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<h5 class="card-title mb-3">CPU Temperature <i class="fas fa-microchip"></i></h5>
77
<p class="card-text fs-4 temp-value">{{ system_info['current_temp'] }} &deg;C</p>
88
<div class="temp-indicator mt-2">
9-
<div class="temp-bar" style="width: {{ system_info['current_temp'] }}%;"></div>
9+
<div id="temp-bar" class="temp-bar" style="width: {{ system_info['current_temp'] }}%;"></div>
1010
</div>
1111
<canvas id="cpuTempLineChart" height="30"></canvas>
1212
</div>
@@ -17,7 +17,7 @@ <h5 class="card-title mb-3">CPU Temperature <i class="fas fa-microchip"></i></h5
1717
<script>
1818
// Initialize CPU Usage Chart
1919
const cpuTempData = [];
20-
createLineChart('cpuTempLineChart', '', cpuTempData, () => {
20+
createLineChart('cpuTempLineChart', '', cpuTempData, 'red', () => {
2121
return parseFloat(document.querySelector('.temp-value').textContent);
2222
});
2323
</script>

src/templates/card_comp/cpu/frequency.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ <h5 class="card-title mb-3">CPU Frequency <i class="fas fa-microchip"></i></h5>
2020
<script>
2121
// Initialize CPU Usage Chart
2222
const cpuFrequencyData = [];
23-
createLineChart('cpuFrequencyLineChart', 'frequency', cpuFrequencyData, () => {
23+
createLineChart('cpuFrequencyLineChart', 'frequency', cpuFrequencyData, 'red', () => {
2424
return 100 * parseFloat(document.querySelector('.frequency-value').textContent) / {{ system_info['cpu_max_frequency'] }};
2525
});
2626
</script>

src/templates/card_comp/cpu/usages.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ <h5 class="card-title mb-3">CPU Usage <i class="fas fa-microchip"></i></h5>
1717
<script>
1818
// Initialize CPU Usage Chart
1919
const cpuUsageData = [];
20-
createLineChart('cpuUsageLineChart', '', cpuUsageData, () => {
20+
createLineChart('cpuUsageLineChart', '', cpuUsageData, 'red', () => {
2121
return parseFloat(document.querySelector('.cpu-usage-value').textContent);
2222
});
2323
</script>

src/templates/card_comp/disk/usage.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ <h5 class="card-title mb-3">Disk Usage <i class="fas fa-hdd"></i></h5>
1717
<script>
1818
// Initialize CPU Usage Chart
1919
const diskUsageData = [];
20-
createLineChart('diskUsageLineChart', '', diskUsageData, () => {
20+
createLineChart('diskUsageLineChart', '', diskUsageData, 'red', () => {
2121
return parseFloat(document.querySelector('.disk-usage-value').textContent);
2222
});
2323
</script>

src/templates/card_comp/memory/usage.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ <h5 class="card-title mb-3">Memory Usage <i class="fas fa-memory"></i></h5>
1919
<script>
2020
// Initialize CPU Usage Chart
2121
const memoryUsageData = [];
22-
createLineChart('memoryUsageLineChart', '', memoryUsageData, () => {
22+
createLineChart('memoryUsageLineChart', '', memoryUsageData, 'red', () => {
2323
return parseFloat(document.querySelector('.memory-usage-value').textContent);
2424
});
2525
</script>

0 commit comments

Comments
 (0)