This repository contains a set of Bash scripts for performing health checks on a Linux system. These scripts monitor various aspects of the system, including CPU usage, RAM usage, disk space, process count, SWAP usage, uptime, and more. The purpose of these scripts is to help you monitor the health of your Linux server and take appropriate actions based on predefined thresholds.
- CPU load: Keep tabs on CPU load averages and receive alerts when they surpass predefined limits.
- Disk usage: Monitor free disk space, triggering alerts if it drops below a specified threshold.
- Service failed: Receive alerts if any service failed.
- Memory usage: Monitor RAM usage and receive alerts if it exceeds a set limit to optimize system performance.
- Needrestart: Monitor the need for system restarts and receive alerts if necessary, ensuring system stability.
- Process count: Keep a check on the number of running processes and receive alerts if it exceeds a predefined limit.
- SWAP usage: Monitor SWAP usage and receive alerts if it surpasses a specified threshold to maintain optimal system functionality.
- Update (APT): Stay informed about available updates through APT and receive alerts for timely system maintenance.
- Uptime: Keep track of system uptime and receive alerts if it extends beyond a specified limit to maintain system reliability.
- Reboot required: Check whether a restart is required. If yes, a restart will be carried out in 24 hours.
Before you get started, ensure you have the following prerequisites:
- Install Git:
sudo apt update && sudo apt install git
- A health-check provider
- Create a user for the health-check scripts.
- Create the directory
mkdir -p /opt/git
. - Change to the directory
cd /opt/git
. - Clone this repository using the following command:
git clone https://github.com/CubyVerse/health-checks.git
- Log in as the user with whom the scripts are to be executed.
- Change to the directory
cd /opt/git/health-checks
. - Run the installation script:
./installation.sh
- Perform a Git pull to ensure you have the latest updates:
git pull
- Customize settings by run the script
./installation.sh
or by editing the.env
file.
- Create a user for health-checks.
- Configure the sudo permissions. Open the sudoers file:
vi /etc/sudoers.d/health-check
and paste the content into the file.
health-check ALL=(ALL) NOPASSWD: /usr/sbin/needrestart -p
health-check ALL=(ALL) NOPASSWD: /usr/bin/apt-get update
health-check ALL=(ALL) NOPASSWD: /usr/bin/apt list --upgradable
- To configure the crontab. Open the crontab file:
vi /etc/cron.d/health-checks
and paste the content into the file.
*/5 * * * * health-check /opt/git/health-checks/check_memory_usage.sh >/dev/null 2>&1
*/5 * * * * health-check /opt/git/health-checks/check_cpu_load.sh >/dev/null 2>&1
*/5 * * * * health-check /opt/git/health-checks/check_swap_usage.sh >/dev/null 2>&1
*/5 * * * * health-check /opt/git/health-checks/check_disk_usage.sh >/dev/null 2>&1
*/5 * * * * health-check /opt/git/health-checks/check_process_count.sh >/dev/null 2>&1
*/15 * * * * health-check /opt/git/health-checks/check_service_failed.sh >/dev/null 2>&1
0 */6 * * * health-check /opt/git/health-checks/check_needrestart.sh >/dev/null 2>&1
0 */12 * * * health-check /opt/git/health-checks/check_update_apt.sh >/dev/null 2>&1
0 */24 * * * health-check /opt/git/health-checks/check_reboot_required.sh >/dev/null 2>&1
0 */24 * * * health-check /opt/git/health-checks/check_uptime.sh >/dev/null 2>&1
We welcome contributions from the community. To contribute, follow these steps:
- Fork the repository.
- Create a new branch.
- Make your enhancements or fixes.
- Submit a pull request.