In this post, I’m going to walk you through a Python-based system health check script that can monitor key system metrics such as disk usage, running services, memory usage, and CPU usage.
Additionally, the script automates the process of sending system health reports via email.
Let's dive into the details.
Prerequisites
Before you can get started, make sure you have the following:
Python 3.x
Git
SMTP Configuration: You'll need to configure your email server in a
.env
file to send reports.
Steps to Set Up
Clone the repository:
Start by cloning the repository where the script is hosted:
git clone https://github.com/khan-atiq/system-health-checker.git
Install the dependencies:
Navigate into the project directory and install the required Python dependencies:
pip install -r requirements.txt
Set up the
.env
file:Configure your SMTP server details in the
.env
file, which will be used for sending emails. Here’s an example setup:SMTP_SERVER=smtp.yourserver.com SMTP_PORT=465 SENDER_EMAIL=your-email@example.com PASSWORD=your-email-password RECEIVER_EMAIL=receiver-email@example.com
Run the system health check script:
Now that everything is set up, execute the script to start monitoring your system:
python sys_healthCheck.py
Running the Script
Once the script is running, it will present you with a menu of options to choose from:
Check Disk Usage
Monitor Running Services
Assess Memory Usage
Evaluate CPU Usage
Send a Comprehensive Report via Email (every 4 hours)
You can select the option by entering the corresponding number to perform a health check.
Additionally, the script will automatically send a detailed report via email every 4 hours.
Thanks!!!!