iMac loses WiFi connectivity, doesn't show it
This little script will tell you when you are not connected to the Internet. If you want to Ping (and monitor) your router instead, change the Google.com to your Router address. 

It will not solve your no connection problem that can have many other reasons. Like flaky connection to the router, like crowded channel, like a limitation by the IP provider on number of connections, and so on. 

To help you solve that we need much more information on your set up and connection numbers.

repeat
    try
        do shell script "ping -c 5 google.com"
    on error
        display dialog "You are not connected to the internet"
    end try
end repeat


As for debugging, hold the alt key and click on your WiFi icon and select the Open Wireless diagnostics (at the bottom). Now you will have access to 2 tools to do some debugging.