function set_monitor_status($server, $status) { $client = new couchClient('http://<hostname>:5984', 'watchcat_hosts'); $opts = array("key" => $server); $pre_doc = $client->setQueryParameters($opts)->getView('wc_hosts', 'by_hostname'); $doc = $client->getDoc($pre_doc->rows[0]->id); $doc->monitor_active = $status; try { $response = $client->storeDoc($doc); } catch (Exception $e) { echo "something weird happened: " . $e->getMessage() . "<BR>\n"; } var_dump($response); }
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)); $time -= $hours * (60 * 60); $minutes = floor($time / 60); $time -= $minutes * 60; $seconds = floor($time);
$mem = new Memcache(); $mem->connect(MEM_HOST, MEM_PORT); // key cache $key_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $key_date = sha1('dates'); // get cache $from_cache_url = $mem->get($key_url); $from_cache_date = $mem->get($key_date); // result cache; $results = []; $dates = '-'; try { $table = null; $head_title = null; $options = array('include_docs' => true, 'limit' => 99999, 'descending' => true); $response = $client->setQueryParameters($options); $get_posts = $response->getView('get_blog_posts', 'by_date'); $query_string = isset($_GET['action']) ? $_GET['action'] : null; switch ($query_string) { case 'edit': // update doc if (isset($_POST['update'])) { $get_doc = $client->getDoc($_GET['docid']); $get_doc->title = $_POST['title']; $get_doc->body = $_POST['body']; $get_doc->category = $_POST['category']; $d_res = (object) $get_doc; $client->storeDoc($d_res); header('Location:index.php'); } $doc = $client->getDoc($_GET['docid']);