When setting up monitoring with Monit, it's crucial to verify that your entire alerting pipeline works before you encounter real system issues. This includes testing email delivery, SMS gateways, and any custom alert scripts you've configured.
The simplest way to trigger a test alert is by manipulating the monitored service's status:
# Force monitor a service (will trigger alert if not already monitored)
monit monitor nginx
# Then unmonitor to return to normal state
monit unmonitor nginx
A more controlled approach is to create a dummy service specifically for testing:
# /etc/monit.d/testalert
check process testalert with pidfile /var/run/testalert.pid
start program = "/bin/true"
stop program = "/bin/true"
if does not exist then alert
Then test with:
monit start testalert # Will generate "does not exist" alert
monit stop testalert # Clears the alert state
For systems with Monit's web interface enabled (port 2812 by default):
# Send test alert via API (replace credentials)
curl -u admin:monit \
-H "Content-Type: application/x-www-form-urlencoded" \
-X POST \
-d "action=testalert" \
http://localhost:2812/_send_test_alert
After triggering a test alert, check:
- Mail server logs (typically /var/log/mail.log)
- Monit's own logs (/var/log/monit.log)
- SMS gateway delivery receipts
- Any external alert processors you've configured
If you have alert throttling configured, test it by sending multiple alerts:
# Script to generate multiple alerts
for i in {1..5}; do
monit monitor nginx
sleep 1
monit unmonitor nginx
sleep 1
done
If alerts aren't arriving:
- Verify mailserver settings in /etc/monit/monitrc
- Check spam folders for test emails
- Test mail delivery independently with mutt or mailx
- Ensure monit has proper permissions to send alerts
To immediately trigger a test alert in Monit without simulating actual service failures:
monit -t
This command tests your Monit configuration and sends alerts through all configured notification channels (email, HTTP, etc.).
For more precise notification testing of specific services:
# Test Apache alert monit monitor apache monit unmonitor apache
This sequence will:
- Force-monitor the service (if not already monitored)
- Trigger an "unmonitor" event that sends an alert
If you're using custom alert scripts in your Monit configuration (/etc/monitrc):
check system $HOST if loadavg(5min) > 0 then alert alert admin@example.com with mail-format { subject: "Monit Test Alert" message: "This is a test notification from Monit" }
After saving changes:
monit reload monit validate
For automated testing in CI/CD pipelines:
#!/bin/bash # Send test alert via monit's HTTP interface curl -u admin:secret \ -d "action=testalert&service=system" \ http://localhost:2812/_send_test