This lab demonstrates how to build a basic system monitoring tool using Python and the psutil library to track CPU usage, RAM usage, and disk space, set performance thresholds, and trigger automated email alerts using Mailjet when those thresholds are exceeded.
- Python 3.6 or higher
- Access to the Internet
- A Mailjet account
- An email inbox to receive alerts
- Basic understanding of virtual environments and Python scripting
- Monitor system metrics such as CPU usage, RAM usage, and disk space using Pythonβs
psutillibrary. - Define performance thresholds for key system resources.
- Configure and send automated email alerts using the Mailjet API.
- Integrate third-party libraries into Python scripts.
- Build and run a simple system monitoring script with alerting features.
- Create a Mailjet account.
- Access the Mailjet Developer Portal and generate an API Key and Secret Key.
- Create a virtual environment using
venv. - Activate the environment.
- Install the necessary libraries:
psutilandmailjet_rest.
- Create a new Python file named
monitor.py. - Import the required libraries.
- Define your Mailjet credentials either using environment variables or hardcoded.
- Get the current system time to timestamp alerts.
- Define thresholds for CPU, RAM, and disk space usage.
- Create a function that sends email alerts using the Mailjet API.
- Collect system metrics (CPU usage, RAM usage, disk space).
- Compose an alert message based on threshold violations.
- Send an email alert if any of the thresholds are exceeded.
- If no thresholds are exceeded, print a message indicating that system metrics are normal.
- Run the monitoring script.
- Monitor the terminal output and verify email delivery.
- Check your email inbox or spam folder for alert notifications.
- Validate that your monitoring alert was successfully sent and received via Mailjet.
- Ensure that the email includes timestamped information about the exceeded system metrics.