Are you a system administrator or web hosting provider looking to monitor real-time CPU usage in cPanel and get instant notifications on Discord? This step-by-step guide shows you how to track server CPU usage and send alerts via Discord Webhooks using a simple Bash script and cron jobs.
🔧 Prerequisites
Before you begin, ensure you have the following:
- Access to a cPanel server via SSH.
- A Discord server with the ability to create webhooks.
- Basic knowledge of Bash scripting, cron jobs, and Linux command-line tools.
- Required utilities installed on your server:
curl
,top
,awk
,grep
.

🔗 Step 1: Create a Discord Webhook
To send notifications from your server to Discord, you’ll first need a webhook.
- Open your Discord server.
- Go to Server Settings > Integrations > Webhooks.
- Click Create Webhook, set a name and channel.
- Copy the Webhook URL — you’ll need this for the script.
📝 Step 2: Create a Bash Script to Monitor CPU Usage
We’ll now How to Monitor cPanel CPU Usage in Real-Time and Send Alerts to Discord
1. Create the Script Directory and File
bashCopyEditmkdir -p /home/username/scripts
nano /home/username/scripts/cpu_notification.sh
2. Add the Monitoring Code
Paste the following code into the script file:
bashCopyEdit#!/bin/bash
# cPanel username and server details
cpanel_user="username" # Replace with your actual cPanel username
cpanel_host="hostmdn.com" # Replace with your server hostname
# Your Discord webhook URL
webhook_url="https://discord.com/api/webhooks/yourwebhookurl"
# Get current CPU usage percentage
cpu_usage=$(top -bn1 | grep "Cpu(s)" | awk '{print 100 - $8}')
cpu_allocated="100" # Adjust based on actual CPU quota
# Send data to Discord
curl -X POST -H "Content-Type: application/json" -d @- "$webhook_url" << EOF
{
"content": "**cPanel CPU Usage Alert** 🚨\nUser: $cpanel_user\nHost: $cpanel_host\nCPU Usage: $cpu_usage%\nCPU Limit: $cpu_allocated%"
}
EOF
3. Save and Exit
Save with Ctrl + X
, press Y
for yes, then Enter
to confirm.
🔓 Step 3: Make the Script Executable
bashCopyEditchmod +x /home/username/scripts/cpu_notification.sh
🧪 Step 4: Test the Script
Run the script manually to check if it works:
bashCopyEdit/home/username/scripts/cpu_notification.sh
Check your Discord channel — you should receive a message with CPU usage details.
⏲️ Step 5: Automate with Cron to Run Every 20 Seconds
To simulate real-time monitoring, schedule the script to run every 20 seconds using cron.
Edit Cron Jobs
bashCopyEditcrontab -e
Add These Lines
bashCopyEdit* * * * * /home/username/scripts/cpu_notification.sh
* * * * * sleep 20; /home/username/scripts/cpu_notification.sh
* * * * * sleep 40; /home/username/scripts/cpu_notification.sh
This setup ensures the script runs three times per minute, every 20 seconds.
🧩 Step 6: Extend the Script (Optional)
Want to monitor more than just CPU usage? You can also track:
Memory Usage:
bashCopyEditmemory_usage=$(free -m | awk '/Mem:/ {print $3 "MB used of " $2 "MB"}')
Disk Usage:
bashCopyEditdisk_usage=$(df -h /home | awk 'NR==2 {print $3 " used of " $2}')
Then add them to your Discord payload:
bashCopyEdit"content": "**Resource Usage Alert** 🚨\nCPU: $cpu_usage%\nMemory: $memory_usage\nDisk: $disk_usage"
✅ Step 7: Monitor and Verify
After everything is set up:
- Watch your Discord channel for notifications.
- Check
/var/log/cron
or/var/log/syslog
if the messages aren’t showing up. - Adjust thresholds or notification frequency as needed.
🎯 Conclusion
By following this guide, you’ve successfully built a real-time cPanel CPU monitoring system with automated Discord notifications. This setup helps:
- Monitor server resource usage 24/7.
- Get alerts before CPU mysql , spikes affect performance.
- Easily expand to track memory, disk, or other metrics.
📈 Whether you’re managing a shared hosting server or maintaining your own web infrastructure, this lightweight solution keeps you informed and responsive.