/** * Will return a Google Graph JSON string or false */ public static function getLastRecord($server_id) { $files = MonitGraph::getLogFilesForServerID($server_id); if (!$files) { return false; } /* Check the directory for the Monit instance ID */ $return_array = array(); foreach ($files as $file) { if (!file_exists($file) or !($xml = simplexml_load_string(file_get_contents($file)))) { error_log("[" . self::identifier . "] " . __FILE__ . " line " . __LINE__ . ": {$filename} could not be loaded!"); return false; } $return_array[] = array("name" => $xml['name'], "time" => intVal($xml->record[0]['time']), "memory" => $xml->record[0]->memory, "cpu" => $xml->record[0]->cpu, "swap" => @$xml->record[0]->swap, "status" => $xml->record[0]->status); } return $return_array; }
$specific_services = (string) $_GET['specific_services']; } else { $specific_services = $default_specific_service; } /* If to show alerts */ if (isset($_GET['dont_show_alerts']) && $_GET['dont_show_alerts'] == "on") { $dont_show_alerts = "on"; } elseif (!isset($_GET['chart_type'])) { $dont_show_alerts = $default_dont_show_alerts; } if ($dont_show_alerts == "on") { $_SELECTED['dont_show_alerts'] = ' checked="checked"'; } /* Iterate all json files in data directory */ $i = 0; $files = MonitGraph::getLogFilesForServerID($_GET['server_id'], $specific_services); foreach ($server_configs as $config) { if ($config['server_id'] == $_GET['server_id']) { echo "<h1>" . $config['name'] . " service logs</h1>"; break; } } echo '<a href="?">Back to dashboard</a>'; foreach ($files as $file) { $filename = basename($file); /* The javascript has some logic to parse the JSON, and to keep overhead down */ $output_head .= <<<EOF \t\t<script type="text/javascript"> \t\t\tvar data{$i} = null; \t\t\tvar chart{$i} = null;