This script monitors the average CPU load on a system with Docker installed. If the load exceeds a specified threshold, it will generate a report containing the top 5 containers contributing to the high CPU load and the top 50 processes on the host, sorted by CPU usage. The report can be sent to a Slack channel as an attachment using a Slack webhook URL.
- Docker must be installed on the system.
- Slack webhook URL (optional) for sending reports to a Slack channel.
- Set up the script to run periodically using cron or another scheduling tool.
- Provide the threshold as a mandatory argument when running the script.
- Optionally, provide a Slack webhook URL as a second argument to send reports to a Slack channel.
./monitor_cpu_load.sh <threshold> [slack_webhook]
Example:
./monitor_cpu_load.sh 40 "https://hooks.slack.com/services/your-webhook-url"
Example cron job:
*/5 * * * * /bin/bash /path/to/monitor_cpu_load.sh 40 "https://hooks.slack.com/services/your-webhook-url"
This project is licensed under the MIT License.
Use this script at your own risk. The author and contributors are not responsible for any damages or issues caused by the use of this script.
Feel free to contact me on Twitter, DEV Community or LinkedIn if you have any questions or suggestions.
Or just visit my website to see what I do.