Skip to content

Commit 0ff455e

Browse files
chore: user installation improved and readme updated
1 parent 90f548a commit 0ff455e

4 files changed

Lines changed: 129 additions & 89 deletions

File tree

README.md

Lines changed: 40 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -26,66 +26,55 @@ System Guard is a Flask app designed to monitor server stats such as CPU, Memory
2626

2727
## Installation 🛠️
2828

29-
check the [Installation.md](/src/docs/installation.md) file for installation instructions.
29+
Check the [Installation.md](/src/docs/installation.md) file for installation instructions.
3030

31+
## How does installation work? 🤔
3132

32-
## Email Feature 📧
33+
The installation process is straightforward and can be completed in a few steps. The user needs to run a bash script that installs the required dependencies, sets up the database, create a conda environment, and add flask server to the cron job. The user can then access the SystemGuard web interface by visiting the server's IP address or domain name.
3334

34-
| Email Alert | Is implemented | who will get the email |
35-
| ----------- | -------------- | ---------------------- |
36-
| Process Killed | Yes | Logged User |
37-
| Login | Yes | Admin User and Logged User |
38-
| Logout | Yes | Logged User |
39-
| Signup | Yes | Admin User & signed up User |
40-
| Create User | Yes | Admin User & Created User |
41-
| Delete User | No | Admin User & Deleted User |
42-
| Speed Test | Yes | Logged User |
43-
| Server Up | Yes | Admin User |
44-
| Notification Settings Change | Yes | Admin User |
45-
| Signup | Yes(few changes required) | Admin User & Logged User |
46-
| Website Monitoring | Yes | Input Email |
47-
| Server Down | No | Admin User |
48-
| Server Up | No | Admin User |
35+
## Email Feature 📧
4936

37+
| Email Alert | Is implemented | who will get the email |
38+
| ---------------------------- | ------------------------- | --------------------------- |
39+
| Process Killed | Yes | Logged User |
40+
| Login | Yes | Admin User and Logged User |
41+
| Logout | Yes | Logged User |
42+
| Signup | Yes | Admin User & signed up User |
43+
| Create User | Yes | Admin User & Created User |
44+
| Delete User | No | Admin User & Deleted User |
45+
| Speed Test | Yes | Logged User |
46+
| Server Up | Yes | Admin User |
47+
| Notification Settings Change | Yes | Admin User |
48+
| Signup | Yes(few changes required) | Admin User & Logged User |
49+
| Website Monitoring | Yes | Input Email |
50+
| Server Down | No | Admin User |
51+
| Server Up | No | Admin User |
5052

5153
## Product Screenshots 📸
5254

53-
### HomePage
54-
55-
![HomePage](/src/static/images/dashboard.png)
56-
57-
### CPU Stats
58-
59-
![CPU Stats](/src/static/images/cpu.png)
60-
61-
### Memory Stats
62-
63-
![Memory Stats](/src/static/images/memory.png)
64-
65-
### Disk Stats
66-
67-
![Disk Stats](/src/static/images/disk.png)
68-
69-
### Speed Test
55+
Check the product screenshots [here](/src/docs/README.md).
7056

71-
![Speed Test](/src/static/images/speedtest.png)
7257

7358
## Why not use a Docker image?
7459

7560
A Docker image has not been created for this project because it requires access to the host machine in order to retrieve server stats. Therefore, it is not possible to obtain server stats from within a Docker container.
7661

7762
## Upcoming Features 📅
7863

79-
- Receive notifications when system metrics cross predefined thresholds.
80-
- Customizable dashboards for personalized server monitoring.
81-
- Plugin support to enhance and extend SystemGuard's functionality.
82-
- Generate and manage server logs for better tracking and troubleshooting.
83-
- Monitor disk read/write speeds for performance insights.
84-
- Check the current firewall status to ensure security.
85-
- A dedicated website monitoring page for tracking uptime and performance.
86-
- Track and save total network data sent/received in the database for data usage monitoring.
87-
- Improve website monitor, save data in database with timestamp to show the history of the website.
88-
- Key-combinding to navigate through the website.
64+
| Feature | Stattus |
65+
| ----------------------------------------------------------------------- | ------- |
66+
| Receive notifications when system metrics cross predefined thresholds | pending |
67+
| Customizable dashboards for personalized server monitoring | pending |
68+
| Plugin support to enhance and extend SystemGuard's functionality | pending |
69+
| Generate and manage server logs for better tracking and troubleshooting | pending |
70+
| Monitor disk read/write speeds for performance insights | pending |
71+
| Check the current firewall status to ensure security | pending |
72+
| A dedicated website monitoring page for tracking uptime and performance | pending |
73+
| Track and save total network data sent/received in the database | pending |
74+
| Improve website monitor, save data in database with timestamp | pending |
75+
| Key-combinding to navigate through the website | pending |
76+
| Support for more server stats like GPU, etc. | pending |
77+
| Support for more Linux distros | pending |
8978

9079
## Learnings 📖
9180

@@ -98,10 +87,10 @@ A Docker image has not been created for this project because it requires access
9887

9988
## Acknowledgments
10089

101-
| Project | License | Repository |
102-
| -------------- | ------------------- | ----------------------------------------------- |
103-
| `speedtest-cli`| Apache License 2.0 | [GitHub repository](https://github.com/sivel/speedtest-cli) |
104-
| `psutil` | BSD 3-Clause License| [GitHub repository](https://github.com/giampaolo/psutil) |
105-
| `flask` | BSD 3-Clause License| [GitHub repository](https://github.com/pallets/flask) |
106-
| `chart.js` | MIT License | [GitHub repository](https://github.com/chartjs/Chart.js) |
90+
| Project | License | Repository |
91+
| --------------- | -------------------- | ----------------------------------------------------------- |
92+
| `speedtest-cli` | Apache License 2.0 | [GitHub repository](https://github.com/sivel/speedtest-cli) |
93+
| `psutil` | BSD 3-Clause License | [GitHub repository](https://github.com/giampaolo/psutil) |
94+
| `flask` | BSD 3-Clause License | [GitHub repository](https://github.com/pallets/flask) |
95+
| `chart.js` | MIT License | [GitHub repository](https://github.com/chartjs/Chart.js) |
10796

setup.sh

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -223,56 +223,64 @@ else
223223
crontab_cmd="crontab"
224224
fi
225225

226-
# Function to validate the user input
227-
validate_choice() {
228-
local choice="$1"
229-
if [[ "$choice" != "true" && "$choice" != "false" ]]; then
230-
echo "Invalid input. Please enter 'true' or 'false'."
231-
return 1
232-
fi
233-
return 0
226+
# Function to create a environment variable in the .bashrc file
227+
prompt_user() {
228+
echo "Do you want to enable $var_name for automatic updates for $APP_NAME?"
229+
echo "1) Yes (Enable automatic updates)"
230+
echo "2) No (Disable automatic updates)"
231+
read -p "Enter your choice (1 or 2): " user_choice
232+
233+
# Convert the user's choice to true/false
234+
case "$user_choice" in
235+
1)
236+
user_choice="true"
237+
;;
238+
2)
239+
user_choice="false"
240+
;;
241+
*)
242+
echo "Invalid choice. Please enter 1 or 2."
243+
return 1
244+
;;
245+
esac
234246
}
235247

248+
# Function to update the environment variable in the env file
236249
update_env_variable() {
237-
local var_name="$1"
238-
local var_value="$2"
239-
240-
# Check if the variable already exists in the environment file
241-
if grep -q "^export $var_name=" "$ENV_FILE"; then
242-
# Update existing entry
243-
sed -i "s/^export $var_name=.*/export $var_name=$var_value/" "$ENV_FILE"
250+
var_name=$1
251+
var_value=$2
252+
253+
# Ensure the environment file exists
254+
touch "$ENV_FILE"
255+
256+
# Update or add the variable in the environment file
257+
if grep -q "^$var_name=" "$ENV_FILE"; then
258+
# Replace existing variable
259+
sed -i "s/^$var_name=.*/$var_name=$var_value/" "$ENV_FILE"
244260
else
245-
# Add new entry
246-
echo "export $var_name=$var_value" >> "$ENV_FILE"
261+
# Add new variable
262+
echo "$var_name=$var_value" >> "$ENV_FILE"
247263
fi
248-
249-
# Notify user of change
250-
echo "$var_name set to $var_value in $ENV_FILE."
251-
}
252-
253-
prompt_user() {
254-
echo "Do you want to enable $var_name? (true/false) This will enable automatic updates for $APP_NAME."
255-
read -p "Enter your choice (true/false): " user_choice
256-
echo "$user_choice"
257264
}
258265

259-
# set the auto update variable
266+
# Function to set the auto update variable
260267
set_auto_update() {
261268
var_name=$1
262269
prompt_user # Prompt user for input
263-
# Validate input
264-
if ! validate_choice "$user_choice"; then
270+
271+
# If prompt_user returned an error (invalid choice), exit early
272+
if [ $? -ne 0 ]; then
265273
return 1
266274
fi
267-
# Update environment variable
275+
276+
# Update the environment variable with the user's choice
268277
update_env_variable "$var_name" "$user_choice"
269-
# Reload environment file
278+
279+
# Reload the environment file to apply changes
270280
source "$ENV_FILE"
271281
}
272282

273283
# this function will change the ownership of the directory
274-
# from root to the user, as the script is run as root
275-
# and the installation directory should be owned by the user
276284
change_ownership() {
277285
local directory="$1"
278286
if [ -d "$directory" ]; then

src/docs/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Product Screenshots 📸
2+
3+
### HomePage
4+
5+
![HomePage](/src/static/images/dashboard.png)
6+
7+
### CPU Stats
8+
9+
![CPU Stats](/src/static/images/cpu.png)
10+
11+
### Memory Stats
12+
13+
![Memory Stats](/src/static/images/memory.png)
14+
15+
### Disk Stats
16+
17+
![Disk Stats](/src/static/images/disk.png)
18+
19+
### Speed Test
20+
21+
![Speed Test](/src/static/images/speedtest.png)

src/scripts/dashboard.sh

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,34 @@ LOG_FILE="/home/$(whoami)/logs/flask.log"
6060
USERNAME="$(whoami)"
6161
CONDA_ENV_NAME=$APP_NAME
6262
GIT_REMOTE_URL="https://github.com/codeperfectplus/SystemDashboard" # Set this if you want to add a remote
63+
ENV_FILE="/home/$(whoami)/.bashrc"
64+
65+
# Function to fetch the value of an environment variable from a file
66+
fetch_env_variable() {
67+
var_name=$1 # The name of the environment variable to fetch
68+
# Check if the environment file exists
69+
if [ ! -f "$ENV_FILE" ]; then
70+
echo "Error: Environment file '$ENV_FILE' not found."
71+
return 1
72+
fi
73+
74+
# Fetch the value of the environment variable
75+
var_value=$(grep -E "^${var_name}=" "$ENV_FILE" | sed -E "s/^${var_name}=(.*)/\1/")
76+
77+
# Check if the variable was found and has a value
78+
if [ -z "$var_value" ]; then
79+
echo "Error: Variable '$var_name' not found in '$ENV_FILE'."
80+
return 1
81+
fi
82+
83+
# Print the value of the environment variable
84+
echo "$var_value"
85+
}
6386

87+
auto_update=$(fetch_env_variable "sg_auto_update")
6488
# Fetch from bashrc for auto-update
65-
auto_update=$(grep -E "^export sg_auto_update=" /home/$(whoami)/.bashrc | cut -d'=' -f2)
66-
echo "SystemGuard Auto Update: $auto_update"
67-
#
89+
echo "Auto update for $APP_NAME is set to $auto_update"
90+
6891
# Ensure log directory exists
6992
LOG_DIR="$(dirname "$LOG_FILE")"
7093
mkdir -p "$LOG_DIR"
@@ -177,13 +200,12 @@ fetch_latest_changes() {
177200
# Return to the original directory
178201
popd > /dev/null
179202
fi
180-
181203
}
182204

183205
# Check if Flask app is running
184206
if ! pgrep -f "flask run --host=0.0.0.0 --port=$FLASK_PORT" > /dev/null; then
185207
log_message "Flask app is not running. Checking repository and starting it..."
186-
[ "$$APP_NAME-AUTO-UPDATE" = true ] &&
208+
[ "$auto_update" = true ] &&
187209
fetch_latest_changes $PROJECT_DIR $GIT_REMOTE_URL
188210
log_message "Starting Flask app..."
189211
# Ensure environment activation and `flask` command

0 commit comments

Comments
 (0)