Пример #1
0
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * @package monit-graph
 * @author Dan Schultzer <http://abcel-online.com/>
 * @copyright Dan Schultzer
 */
$current_dirname = dirname(__FILE__) . "/";
/* First all the query strings are validated and taken care of */
if (!isset($_GET['file'])) {
    echo json_encode(array());
}
if (!isset($_GET['time_range'])) {
    $time_range = 0;
} else {
    $time_range = $_GET['time_range'];
}
$replace = array("../", "data/");
$_GET['file'] = $current_dirname . "data/" . str_replace($replace, "", $_GET['file']);
if (!file_exists($_GET['file'])) {
    echo json_encode(array());
}
/* Now let's print the actual JSON */
require_once $current_dirname . "config.php";
require_once $current_dirname . "monit-graph.class.php";
MonitGraph::printFullGoogleGraphHistoric($_GET['file'], $time_range, $limit_records_shown);
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the Dan Schultzer nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL DAN SCHULTZER BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * @package monit-graph
 * @author Dan Schultzer <http://abcel-online.com/>
 * @copyright Dan Schultzer
 */
$current_dirname = dirname(__FILE__) . "/";
/* Running cron with config options */
require_once $current_dirname . "config.php";
require_once $current_dirname . "monit-graph.class.php";
if (!MonitGraph::checkConfig($server_configs)) {
    die;
}
/* Running each instance of the config */
foreach ($server_configs as $config) {
    MonitGraph::cron($config['server_id'], $config['config']['url'], $config['config']['uri_xml'], $config['config']['url_ssl'], $config['config']['http_username'], $config['config']['http_password'], $config['config']['verify_ssl'], $chunk_size, $limit_number_of_chunks);
}
$seconds_difference_per_point = 60;
// How many seconds between each point
$data_time = time() - $number_of_data_points * $seconds_difference_per_point;
$data_memory = $data_cpu = $data_pid = $data_uptime = $data_children = $data_status = $data_alert = 0;
$data_monitor = $data_cpu = 1;
$data_memory = 5;
$file_size = -1;
$file_size_total = 0;
$name = "massive_data_points";
$type = "3";
for ($i = 0; $i < $number_of_data_points; $i++) {
    if ($file_size == -1 || $chunk_size > 0 && $file_size > $chunk_size) {
        if (isset($dom)) {
            $file = $current_dirname . $file_name;
            if (file_exists($file)) {
                MonitGraph::rotateFiles($file, $chunk_size, $limit_number_of_chunks);
            }
            echo "<p>Writting out {$file_size} bytes and reached {$i} points out of {$number_of_data_points}</p>";
            $file_size_total += $file_size;
            writeDom($dom, $file_name);
            usleep(100);
            //relaxing the cpu
        }
        $file_size = 0;
        $dom = null;
        unset($dom);
        $dom = new DOMDocument('1.0');
        $service = $dom->createElement("records");
        $dom->appendChild($service);
        $attr_name = $dom->createAttribute("name");
        $attr_name->value = $name;
Пример #5
0
            $txt = 'Are you sure to delete all files associated to the server ' . $name . '?';
        } else {
            $txt = 'Are you sure to delete all files associated to ' . $_GET['delete_data'] . ' at server ' . $name . '?';
        }
        echo '
		<form action="?delete_data=' . $_GET['delete_data'] . '&amp;id=' . $_GET['id'] . '" method="post">
			<input type="hidden" name="delete" value="true" />
			' . $txt . '
			<input type="submit" value="Delete" />
		</form>';
    }
    echo '
	</div>';
} else {
    foreach ($server_configs as $config) {
        $services = MonitGraph::getLastRecord($config['server_id']);
        if (!$services) {
            die("No log files where found. Please run cron first.");
        }
        echo '
	<div class="server_box bordered_box">
		<h2>' . $config['name'] . ' status</h2>';
        if (empty($services)) {
            echo "<span>No log files found</span>";
        } else {
            echo '<div class="service_header">';
            echo "<div><strong>Service:</strong></div>";
            echo "<div><strong>CPU:</strong></div>";
            echo "<div><strong>Memory:</strong></div>";
            echo "<div><strong>Swap:</strong></div>";
            echo "<div><strong>Last check:</strong></div>";