343343
<?php
header("Content-Type: application/json");
$health = [];
////////////////////////////////////////////////////////////////////////////////
// Instance Type
$health['instance'] = trim(file_get_contents("http://169.254.169.254/latest/meta-data/instance-type"));
////////////////////////////////////////////////////////////////////////////////
// Database
/*
include("includes/mysql_connect.php");
$rs = mysql_query("SELECT * FROM ORDERS ORDER BY order_id DESC LIMIT 1");
if( $row = mysql_fetch_assoc($rs) ) {
$health["database"] = "good";
} else {
$health["database"] = "bad";
}
*/
////////////////////////////////////////////////////////////////////////////////
// PHP Version
$health["php"] = phpversion();
////////////////////////////////////////////////////////////////////////////////
// Word Press (if applicable)
$wpVersion = "/var/www/html/wp-includes/version.php";
if( file_exists($wpVersion) ) {
include($wpVersion);
$health["wordpress"] = $wp_version;
$verify = shell_exec("/usr/local/bin/wp core --path=/var/www/html verify-checksums 2>&1");
if( !preg_match('/success/mi',$verify) ) {
$health["wordpress_error"] = "Checksums Failed";
} else if( preg_match('/warning/mi', $verify) ) {
$health["wordpress_error"] = "Extra Files";
}
}
////////////////////////////////////////////////////////////////////////////////
// CPU Load (normalized by processor count)
$cpuCt = intval(shell_exec("grep processor /proc/cpuinfo | wc -l"));
if( $cpuCt > 0 ) {
$loads = explode(" ",file_get_contents("/proc/loadavg"));
$health["load"] = join(" ", [ round(floatval($loads[0]) / $cpuCt, 1),
round(floatval($loads[1]) / $cpuCt, 1),
round(floatval($loads[2]) / $cpuCt, 1),
]);
}
////////////////////////////////////////////////////////////////////////////////
// File System
$df = disk_free_space("/");
$dt = disk_total_space("/");
$health["disk"] = ["free" => round($df / 1024 / 1024,2),
"total" => round($dt / 1024 / 1024,2) ];
////////////////////////////////////////////////////////////////////////////////
// Updates
$updates = [];
//exec("yum check-updates -q",$updates);
$health['updates'] = count($updates);
////////////////////////////////////////////////////////////////////////////////
// Version
$health['version'] = trim(file_get_contents("/etc/system-release"));
echo json_encode($health);