function couch_query($server) { $date = new DateTime(); $startdate = create_startdate($date); $enddate = create_enddate($startdate); $client = new couchClient('http://<hostname>:5984', 'watchcat_stats'); try { $opts = array("startkey" => array($server, $startdate), "endkey" => array($server, $enddate), "limit" => 12, "descending" => true); $cat_stats = $client->setQueryParameters($opts)->getView('stats', 'by_server_date'); } catch (Exception $e) { echo "something weird happened: " . $e->getMessage() . "<BR>\n"; } return $cat_stats; }
<?php $q = intval($_GET['q']); echo 'color'; require_once 'couchlib/couch.php'; require_once 'couchlib/couchClient.php'; require_once 'couchlib/couchDocument.php'; require_once 'date_functions.php'; // set a new connector to the CouchDB server $client = new couchClient('http://172.25.1.45:5984', 'watchcat_stats'); $interval = $q; //get stats from couchdb for $server (name) //but first create dates to go in our query $date = new DateTime(); $startdate = create_startdate($date); $enddate = create_enddate($startdate, $interval); var_dump($interval); try { $opts = array("startkey" => array('app11', $startdate), "endkey" => array($server, $enddate), "limit" => 24, "descending" => true); $cat_stats = $client->setQueryParameters($opts)->getView('stats', 'by_server_date'); } catch (Exception $e) { echo "something weird happened: " . $e->getMessage() . "<BR>\n"; } ?> <body> <div id="memorychart" style="height: 150px;"></div> </body> <! -- load remote js files --> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<?php require_once 'couchlib/couch.php'; require_once 'couchlib/couchClient.php'; require_once 'couchlib/couchDocument.php'; require_once 'date_functions.php'; // set a new connector to the CouchDB server server stats $client = new couchClient('http://172.25.1.45:5984', 'watchcat_stats'); $server = $_GET['server']; $status = json_decode(file_get_contents(trim("http://" . $server . ":4569/metrics"))); $health = json_decode(file_get_contents(trim("http://" . $server . ":4569/status"))); //get stats from couchdb for $server (name) //but first create dates to go in our query $date = new DateTime(); $startdate = create_startdate($date); //echo $startdate."<br>"; $enddate = create_enddate($startdate, 24); //echo $enddate."<br>"; try { $opts = array("startkey" => array($server, $startdate), "endkey" => array($server, $enddate), "limit" => 24, "descending" => true); $cat_stats = $client->setQueryParameters($opts)->getView('stats', 'by_server_date'); } catch (Exception $e) { echo "something weird happened: " . $e->getMessage() . "<BR>\n"; } // Remove decimal places $formatted_avg = number_format($status->disk_space[0]->percent_used, 2, '.', ''); #echo $formatted_avg; $time = $status->uptime; // time duration in seconds $days = floor($time / (60 * 60 * 24)); $time -= $days * (60 * 60 * 24); $hours = floor($time / (60 * 60));
<html lang="en"> <head> <link rel="stylesheet" href="bootstrap/css/bootstrap.css" type="text/css"> <link rel="stylesheet" href="http://cdn.oesmith.co.uk/morris-0.4.3.min.css"> </head> <?php require_once 'header.php'; require_once 'couchlib/couch.php'; require_once 'couchlib/couchClient.php'; require_once 'couchlib/couchDocument.php'; require_once 'date_functions.php'; $date = new DateTime(); $startdate = create_startdate($date); $enddate = create_enddate($startdate, 48); //echo $startdate; //echo $enddate; // set a new connector to the CouchDB server $client = new couchClient('http://172.25.1.45:5984', 'watchcat_stats'); // set a new connect to the couchdb hosts config database $couch_hosts_client = new couchClient('http://172.25.1.45:5984', 'watchcat_hosts'); $hostnames = $couch_client->getView('wc_hosts', 'hostnames'); $servers = array(); foreach ($hostnames as $rows) { foreach ($rows as $host) { $servers[] = $host->key; } } $i = 0; foreach ($servers as $server) {