A netwatch works the best in a scenario like this.
Pick a static IP that is ALWAYS available via your specific gateway, BUT which you will never directly use (probably something like one of the x.root-servers.net)
Add this IP as a NULL route with distance 250 (if the interface goes down, this will be the route for the IP)
Add this IP as a normal route forcing it out gateway1
Add the default gateway with a comment via gateway1
Add the default gateway via gateway2 with a higher distance
Add a netwatch script to ping this IP with a script to disable/enable the default gateway
When the netwatch pings the IP and latency is higher than X, it assumes the gateway is offline, and disables the default gateway via gateway1, and let the 2nd default gateway take over.
Example script for UP:
:log info "GATEWAY1 up"
/ip route
:foreach ID in [find comment="GATEWAY1 Internet"] do={
set $ID disable=no
}
Example script for DOWN:
:log info "GATEWAY1 down"
/ip route
:foreach ID in [find comment="GATEWAY1 Internet"] do={
set $ID disable=yes
}