- Introduction
- Installation
- Recommendations
- Development Environment Setup
- Running the Service
- Updating
settings.json
- Uninstalling the Program
The Linux Monitoring Service provides real-time monitoring of CPU and memory usage, with notifications sent via a Telegram bot. This service is designed to run in the background on Linux-based systems and automatically restart upon failure. Configuration settings are stored in the settings.json
file, and users can modify thresholds and other parameters as needed.
To install the Linux Monitoring Service, follow these steps:
-
Open a terminal.
-
Run the following command to download and install the service from GitHub:
bash <(curl -Ls https://raw.githubusercontent.com/Hsnmsri/linux_monitoring/main/install.sh)
-
During installation, you will be prompted to provide the following details:
- Telegram Bot Token: The token for your Telegram bot.
- Chat ID: The chat ID where notifications will be sent.
- CPU Check Duration (default: 500 ms): Interval for checking CPU usage.
- Memory Check Duration (default: 500 ms): Interval for checking memory usage.
- CPU Usage Limit (default: 30%): CPU usage threshold for sending alerts.
- Memory Usage Limit (default: 30%): Memory usage threshold for sending alerts.
-
After installation, the service will automatically start and monitor your system's CPU and memory usage, sending alerts based on the configured thresholds.
- Default Configuration: It is recommended to start with the default thresholds for CPU and memory usage (30%) and adjust them as needed based on your system's workload.
- Notifications: Ensure that your Telegram bot and chat ID are correctly configured to receive real-time alerts.
- System Resource Monitoring: You can view the resource usage via Telegram commands such as
/usage
to check CPU and memory status.
For developers looking to contribute to or modify the Linux Monitoring Service, here are the steps to set up the development environment:
-
Clone the Repository: Clone the repository from GitHub:
git clone https://github.com/Hsnmsri/linux_monitoring.git cd linux_monitoring
-
Install Dependencies: Install the required dependencies using the following command:
sudo chmod +x require ./require
-
Build the Project: To build the project, you can use g++ or CMake (if a CMakeLists.txt is provided):
g++ -o linux_monitoring main.cpp -lcurl -lboost_system -lssl -ltgbot -lpthread
-
Run the Program: You can run the program locally using:
./linux_monitoring
Once installed, the Linux Monitoring Service will automatically run as a background service. The service is managed via systemd
, and you can interact with it using the following commands:
-
Start the Service:
sudo systemctl start linuxmonitoring
-
Stop the Service:
sudo systemctl stop linuxmonitoring
-
Restart the Service:
sudo systemctl restart linuxmonitoring
-
Check Service Status:
sudo systemctl status linuxmonitoring
If you make changes to the settings.json
file, such as updating thresholds or changing the bot token, you must restart the service for the changes to take effect.
- dit the
settings.json
file:sudo nano /opt/linuxmonitoring/settings.json
- After saving your changes, restart the service:
This ensures that the service picks up the latest changes.
sudo systemctl restart linuxmonitoring
To completely remove the Linux Monitoring Service from your system, follow these steps:
- Stop the Service:
sudo systemctl stop linuxmonitoring
- Disable the Service (to prevent it from starting on boot):
sudo systemctl disable linuxmonitoring
- Remove the Service Files:
sudo rm /etc/systemd/system/linuxmonitoring.service sudo rm -r /opt/linuxmonitoring
- Reload
systemd
to apply the changes:This will remove all traces of the service from your system.sudo systemctl daemon-reload