Use PHP-CLI to publish server stats via json

If you need great server monitoring, use copper egg. It inexpensive, easy to install and very very good.

If you happen to use PHP with Linux, a lot of usesful information can be extracted from the /proc filesystem. Enough to provide basic monitoring. The attached script dumps and processes the output from proc every minute as json.

Make sure to protect the directory you're outputing this into to.

Download livestats.php code

Is this a private IP address?

I need to show different content to folks who are outside our network.
This snippet will detect a private ip address using php's built in filter class.

function is_private_ip($ip) {
return !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
}

FILTER_FLAG_NO_PRIV_RANGE gets you:

"Fails validation for the following private IPv4 ranges:10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16.

Fails validation for the IPv6 addresses starting with FDor FC."

and FILTER_FLAG_NO_RES_RANGE gets you:

"Fails validation for the following reserved IPv4 ranges:0.0.0.0/8, 169.254.0.0/16, 192.0.2.0/24 and224.0.0.0/4. This flag does not apply to IPv6 addresses."

Source: PHP Docs