Patrol monitors system resources and records information to a log file in case of excessive RAM or CPU usage. When the log file reaches a certain size, it archives old log files up to a specified number. This is a useful tool for monitoring system performance and managing log files regularly.
- Monitors system resources (RAM and CPU usage).
- Records information to a log file.
- Archives old log files when the log file size exceeds a specified limit.
- Allows for customization of the log file size limit and the maximum number of archived log files.
-
Clone the repository:
git clone https://github.com/mkdemir/patrol.git
-
Navigate to the project directory:
cd patrol
-
Make the script executable:
chmod +x patrol.sh
Run the script using the following command:
./patrol.sh
Alternatively, you can specify custom RAM and CPU thresholds using:
./patrol.sh -ram 20 -cpu 10
The script will start monitoring system resources and logging information to a file named patrol-output.log
. When the log file size exceeds a certain limit, old log files will be archived.
You can customize the following parameters in the script:
RAM_THRESHOLD
: The threshold for RAM usage (in percentage).CPU_THRESHOLD
: The threshold for CPU usage (in percentage).RESET_THRESHOLD
: The threshold for resetting the log file (in percentage). (Old)MAX_COMPRESSED_FILES
: The maximum number of compressed log files to keep.LOG_FILE
: The name of the log file.COMPRESSED_LOG_FILE
: The name of the compressed log file.
To run the script as a service on Linux systems using systemd, follow these steps:
-
Navigate to the project directory:
cd /path/to/patrol
-
Create a new service file using a text editor, for example:
sudo nano patrol.service
-
Paste the following content into the service file:
[Unit] Description=Patrol After=network.target [Service] ExecStart=/path/to/patrol/patrol.sh WorkingDirectory=/path/to/patrol Restart=always [Install] WantedBy=multi-user.target
Note: Update the
ExecStart
andWorkingDirectory
paths according to the location of your project. -
Save and close the file (if you're using nano, press
Ctrl + X
, thenY
, and finallyEnter
). -
Copy the service file to the systemd directory:
sudo cp patrol.service /etc/systemd/system/
-
Reload systemd to read the new service file and start the service:
sudo systemctl daemon-reload sudo systemctl start patrol
-
Check the status of the service to verify that it started successfully:
sudo systemctl status patrol
The status output will indicate whether the service is running and if there are any errors.
-
Optionally, enable the service to start automatically at boot:
sudo systemctl enable patrol
The system monitor and log rotator service is now successfully running! It will automatically monitor system resources and manage log files when the system starts up.
This project is licensed under the MIT License - see the LICENSE file for details.