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; }
</head> <?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));