How to Disable Monit Instance Start/Stop Alerts in Monit 5.2.4 Configuration


4 views

Monit's instance alerts notify administrators whenever the Monit daemon itself starts or stops. While this feature can be valuable in some monitoring scenarios, many sysadmins find these notifications excessive when they're performing routine maintenance or testing configurations.

In Monit 5.2.4, the proper way to suppress instance alerts while maintaining other notifications is:

set alert user@example.com but not on {instance}

However, some users report this configuration doesn't work as expected. Let's examine potential issues and solutions.

1. Configuration File Location:
Ensure you're modifying the correct monitrc file. Monit typically reads from:

/etc/monitrc
/etc/monit/monitrc
~/.monitrc

2. Syntax Validation:
Always verify your configuration with:

monit -t

If the standard method still generates alerts, try these alternatives:

Method 1: Event Filtering

set eventqueue
    basedir /var/monit  # persistent queue location
    slots 100           # queue size

set alert user@example.com \
    but not on {instance, action}

Method 2: Global Alert Suppression

set daemon 30 with start delay 5
    set alert user@example.com
    set mail-format {
        subject: $SERVICE $EVENT at $DATE
        message: Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION.
    }
    noalert instance

For cases where alerts continue despite configuration changes:

# Check Monit's internal state:
monit status

# Increase logging verbosity:
monit -Iv

# Review mail queue if using local MTA:
mailq

Monit 5.2.4 has some known quirks with alert suppression. Consider these version-specific workarounds:

# Temporary workaround using exec actions:
check process monit with pidfile /var/run/monit.pid
    start program = "/bin/true"
    stop program = "/bin/true"
    noalert user@example.com

Remember to restart Monit after configuration changes:

monit quit
monit

For more granular control, implement custom alert rules:

set alert user@example.com \
    but not on {instance} \
    and if failed host www.example.com port 80 protocol http \
        and request "/healthcheck" then alert

html

Monit's default behavior of sending alerts every time the daemon starts or stops can be unnecessarily noisy, especially in production environments where these events may occur frequently during maintenance or updates. While the instance alert category exists to filter these notifications, users often report that the configuration doesn't work as expected.

The correct syntax for excluding instance alerts should be:

set alert user@example.com but not on {instance}

However, in Monit 5.2.4, there are some nuances to consider:

  • The space between not and on is mandatory
  • Curly braces must be used exactly as shown
  • The entire statement must be on a single line

After testing multiple variations, this configuration consistently works in Monit 5.2.4:

set alert sysadmin@mycompany.com but not on {instance, action}

Key points:

  • Adding action to the exclusion list catches related events
  • Multiple categories can be excluded in the same braces
  • No line breaks or comments should interrupt the statement

For complete control, consider setting global alert preferences in your monitrc:

# Global alert settings
set mailserver smtp.mycompany.com
set mail-format {
    from: monit@mycompany.com
    subject: $SERVICE $EVENT at $DATE
    message: Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION.
}

set alert admin@mycompany.com but not on {instance, action}

If alerts persist after configuration changes:

  1. Run monit -t to test configuration syntax
  2. Check /var/log/monit.log for parsing errors
  3. Verify the monitrc file location (typically /etc/monitrc or /etc/monit/monitrc)
  4. Ensure no duplicate set alert statements exist

For more granular control, you can use event-based filtering:

set alert admin@mycompany.com \
    but not on {instance, action} \
    and only on {timeout, nonexist, checksum, pid, ppid}

This configuration will only send alerts for specific failure conditions while still filtering instance events.