function __construct($uuid, $name, $start, $end, $cnt = 400)
 {
     $db = Reconnoiter_DB::getDB();
     $this->derive = $derive;
     $this->data = $db->get_var_for_window($uuid, $name, $start, $end, $cnt);
     $last = end($this->data);
     if ($last) {
         $this->last_value = $last['value'];
     }
     $this->uuid = $db->get_uuid_by_sid($uuid);
 }
 function __construct($uuid, $name, $derive, $expr, $start, $end, $cnt = 400)
 {
     $db = Reconnoiter_DB::getDB();
     $pgd = 'false';
     $this->default_attr = 'avg_value';
     $this->derive = $derive;
     $this->uuid = $db->get_uuid_by_sid($uuid);
     if ($derive == 'derive' || $derive == 'true') {
         $pgd = 'true';
     } else {
         if ($derive == 'counter') {
             $this->default_attr = 'counter_dev';
         }
     }
     $this->data = $db->get_data_for_window($uuid, $name, $start, $end, $cnt, $pgd);
     $this->expr = $expr;
 }
function createGraphsFromCombos($combo, $var_vals, $i, $sid_vars, $genesis_base, $rparams, $templateid, $graph_num, $update)
{
    global $graphs_to_update;
    $genesis = $genesis_base;
    if ($i >= count($var_vals)) {
        $vals_combo = explode(",", $combo);
        for ($j = 0; $j < count($vals_combo); $j++) {
            $rparams[$sid_vars[$j]] = $vals_combo[$j];
            $genesis .= "," . $sid_vars[$j] . "=" . $vals_combo[$j];
        }
        $template = new Reconnoiter_GraphTemplate($templateid);
        $db = Reconnoiter_DB::getDB();
        $graph_json = $template->getNewGraphJSON($rparams);
        $graph_json = stripslashes($graph_json);
        $graph_json = json_decode($graph_json, true);
        $graph_json['genesis'] = $genesis;
        // Check to see if this title exists
        $titlerow = $db->getGraphByTitle($title);
        // if it does, append $graph_num to it
        if ($titlerow['graphid']) {
            $graph_json['title'] = $graph_json['title'] . $graph_num;
        }
        $grow = $db->getGraphByGenesis($genesis);
        if ($grow['graphid']) {
            if ($update) {
                $graph_json['id'] = $grow['graphid'];
                $graph_id = $db->saveGraph($graph_json);
            }
            $graphs_to_update[] = array('graphid' => $grow['graphid'], 'title' => $grow['title']);
            return;
        }
        if ($update) {
            $graph_id = $db->saveGraph($graph_json);
            $graph_json['id'] = $graph_id;
            $graph_id = $db->saveGraph($graph_json);
        }
        return;
    } else {
        foreach ($var_vals[$i] as $vval) {
            $graph_num++;
            createGraphsFromCombos($combo ? "{$combo},{$vval}" : $vval, $var_vals, $i + 1, $sid_vars, $genesis_base, $rparams, $templateid, $graph_num, $update);
        }
    }
}
 public function find_sids($json)
 {
     $this->num_sids = 0;
     $sids = array();
     $vs = Reconnoiter_GraphTemplate::find_variables($json);
     //vs will be multiD array containing variable names, their types (text/sid) and metric
     //names and metric types
     foreach ($vs as $v => $d) {
         if (isset($d['SID'])) {
             $this->num_sids++;
             $sql = "select m.* from noit.check_currently as m";
             $binds = array();
             $t = 1;
             $sids[$v] = array();
             foreach ($d['SID'] as $m) {
                 $sql = "{$sql}\n                    join noit.metric_name_summary t{$t}\n                      on (    m.sid = t{$t}.sid\n                          and t{$t}.metric_name = ?\n                          and t{$t}.metric_type = ?)";
                 $binds[] = $m[0];
                 $binds[] = $m[1];
                 $t++;
             }
             if (count($binds)) {
                 $db = Reconnoiter_DB::getDB();
                 $sth = $db->prepare($sql);
                 $sth->execute($binds);
                 while ($row = $sth->fetch()) {
                     $sids[$v][] = $row;
                 }
             }
         }
     }
     return $sids;
 }
<?php

require_once 'Reconnoiter_DB.php';
$graph = json_decode($_POST['json'], true);
$saved_id = $graph['id'];
$db = Reconnoiter_DB::getDB();
header('Content-Type: application/json; charset=utf-8');
try {
    $id = $db->saveGraph($graph);
    print json_encode(array('id' => $id));
} catch (Exception $e) {
    print json_encode(array('id' => $saved_id, 'error' => $e->getMessage()));
}
<?php

require_once 'Reconnoiter_DB.php';
$db = Reconnoiter_DB::GetDB();
header('Content-Type: application/json; charset=utf-8');
try {
    print json_encode($db->get_datapoints($_GET['q'], $_GET['o'], $_GET['l']));
} catch (Exception $e) {
    print json_encode(array('count' => 0, 'query' => $_GET['q'], 'offset' => $_GET['o'], 'limit' => $_GET['l'], 'error' => $e->getMessage()));
}
 function __calc()
 {
     if ($this->units) {
         return;
     }
     $db = Reconnoiter_DB::getDB();
     foreach ($db->percentile(array_values($this->sets), array_keys($this->ps_to_calc)) as $p => $v) {
         $this->percentile[$p] = $v;
     }
     if (is_array($this->agg_to_calc)) {
         foreach ($db->aggregate(array_values($this->sets), array_keys($this->agg_to_calc)) as $p => $v) {
             $this->aggregate[$p] = $v;
         }
     }
     $this->units = pow(1000, floor(log($this->percentile[100], 1000)));
     if ($this->units == 0) {
         $this->units = 1;
     }
 }