Uptime Monitoring in 5.3

How does this work? I’ve activated it and it should do a GET request to all sites, but I don’t see anything in the access logs of the sites, so is it even working? How would it be recognised in access logs? Does it have specific user agent?

A GET request also does a complete pageload. Uptime Robot reduces load and traffic by only doing a HEAD request. Is dat also possible?

In my settings (/wp-admin/admin.php?page=MonitoringSites - Page settings) the “Up HTTP Codes” is filled only with 403 (no 2xx codes). I guess it’s based on an old setting, because I’ve entered 403 in the past to ignore the status as it was sometimes shown when there was no issue.

Notifications are sent by email, but monitoring like this is much more suited to send a signal to Discord/Slack or another webhook. Can that please be added as well? It shouldn’t be too hard. The basics can be found in GitHub - sprucely-designed/mainwp-discord-notifications and (in time) it could be used for other notifications as well.

Hey Jos,

I am not 100% sure if the checks should be logged in access log. I will need to look into it but from what I see in the code, the monitoring feature runs HTTP requests via cURL. By deafut, GET method is used, but it can be changed to other methods as well. Checks are using the User-Agent: 'Mozilla/5.0 (compatible; MainWP/5.3; +http://mainwp.com)'

I talked quickly to the dev team and they said that they will add the option to do only HEAD requests, we should have this ready in RC2.

By default, 2XX codes are considered as Up Status, however, we did not have them pre-selected in the settings, so we will make this tweak and in RC2, 2xx codes will be pre-selected. 403 Code was set for you since you had it in the Ignored list in Basic Uptime monitoring.

We are still thinking about this, but the way we will handle the notifications, however for the initial release, we will add a hook in the process that will fire after checks so custom code can be hooked for various needs.

2 Likes

I guess this would be expected, because it loads content from the site. Of course I mean the access log of the child sites. UptimeRobot and other site monitoring tools are logged as well.

Great!

That would be nice, although I might need a hand to create the notifications, but we’ll see how that goes.

Hey Jos,
Just a quick update, I reviewed access longs on our test servers and I found that checks are being logged:

Regarding the custom notifications, here is a quick example how you can trigger a custom Discord webhook to get notifications from Uptime Monitor:

function mycustom_mainwp_uptime_monitoring_after_check_uptime( $heartbeat, $monitor, $previous_heartbeat ){    
    if( empty( $heartbeat['status'] ) && empty( $heartbeat['importance'] ) ) {
		$payload = array(
			'content' => 'Monitor Down!',
		);

		$args = array(
			'body'        => wp_json_encode( $payload ),
			'headers'     => array( 'Content-Type' => 'application/json' ),
			'method'      => 'POST',
			'data_format' => 'body',
			'timeout'     => 50,
		);

        wp_remote_post( 'https://discord.com/api/webhooks/yourcustomweebkook', $args );    
    }
}```

This hook will be included in RC2
2 Likes

I do see the lines in the log, but very irregular and definitely not every 5 minutes like I’ve set in the MainWP Settings - General Settings - Uptime Monitoring on the Monitoring Interval. Can I see some logging if checks are fired or not? How are they fired?
I’ve got both UptimeRobot (this is the last week) and a cron job on my server doing requests to my dashboard: GET /wp-cron.php?doing_wp_cron every 5 minutes, so if it’s cron based there should be enough activity.
Requests should be sent to all my 325 sites, so I hope it’s not a capacity issue? I don’t see a higher load on my server, so that’s not the problem.

Thanks for the hook and the snippet. I’ll defenitely will test that later (with RC2)!

You can enable the Custome Even Monitor (CEM) in MainWP > Info > Custom Event Montior page and set it for Uptime Monitor logging.

Once enabled, it will start logging Uptime checks.

On our test sites, we have not noticed any performance issues.

1 Like

It looks like it’s only checking 10 sites per minute and that way it can’t check 325 sites in 5 minutes, so it will take more than 30 minutes.

2024-11-25 20:30:02 CRON :: Uptime Monitoring :: [count_monitors=10]
.
.
.
2024-11-25 20:28:57 CRON :: Uptime Monitoring :: [count_monitors=10]

Hi Jos,

In the MainWP > Settings > Advanced Settings there is an option that allows you t set Maximum simultaneous uptime monitoring requests , by default it’s 10, but you can set it anywhere between 1 and 100:

In case there is a visual problem with this setting on your setup, you can redownload the RC2 version from the Early Release page and install it, that should fix it.

I indeed had to reinstall RC2 (apparently it was changed after the first publication).

It says that it’s 10 by default, but mine showed it was 3, although that doesn’t match the findings in the log.

I’ve set it to 50 and will see how it goes. I’ve also changed the request type from GET to HEAD now.

I’ve enabled the log again and still see [count_monitors=10] and only 10 sites are checked every 5 minutes (not every minute like earlier).

Hi Jos, it might be that the scheduled before you made the change was not processed yet and is still in the queue.

In my test setup, I have 10 sites and when I change the number of monitors to be processed in one batch it works correctly.

Can you please give it more time and see how it goes? If there is still the problem, can you please make a copy of the CEM log and send it via support ticket so our dev team can check?

The number of checks is indeed increasing, and so is the interval of the checks (from 5 to now 2 minutes). it’s still logged that [count_monitors=10], so maybe that’s just a logging issue?

There are no other messages that indicate an issue, only the success message and the fact that data=EMPTY (because of the HEAD request I think).