Esempio n. 1
0
 function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     if ($grp->gid < 0) {
         if (!strcmp($grp->gid, VIRTUALReader::COMPLEX_ID)) {
             throw new ADEIException(translate("Data could not be retrieved from complex groups"));
         } else {
             if (!strcmp($grp->gid, VIRTUALReader::MISSING_ID)) {
                 throw new ADEIException(translate("The source tree is empty, please, select something"));
             } else {
                 if (!strcmp($grp->gid, VIRTUALReader::SRCTREE_ID)) {
                     throw new ADEIException(translate("Data could not be retrieved from source tree"));
                 }
             }
         }
     }
     if ($filter) {
         $mask = $filter->GetItemMask();
         $rate = $filter->GetSamplingRate();
         $limit = $filter->GetVectorsLimit();
     } else {
         $mask = NULL;
         $rate = false;
         $limit = 0;
     }
     $req = $this->srctree->GetGroupRequest($grp, $mask);
     $rdr = $this->CreateReader($req);
     $group = $rdr->CreateGroup();
     $mask = $rdr->CreateMask();
     $super_filter = $this->CreateDataFilter($group, $mask, $rate, $limit, $filter);
     return $rdr->GetRawData($group, $from, $to, $super_filter, $filter_data);
 }
Esempio n. 2
0
 function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     $grp = $this->CheckGroup($grp);
     $res = $this->db->Query("SELECT {$this->req_cols} FROM adt WHERE ID=" . $grp->gid);
     $row = $res->fetch();
     if ($row['writable'] > 0) {
         $writable = 1;
     } else {
         $writable = 0;
     }
     if (!$from || !$to) {
         $ivl = $this->CreateInterval($grp);
         $ivl->Limit($from, $to);
         $from = $ivl->GetWindowStart();
         $to = $ivl->GetWindowEnd();
     }
     if ($filter) {
         $mask = $filter->GetItemMask();
         $resample = $filter->GetSamplingRate();
         $limit = $filter->GetVectorsLimit();
         if (isset($filter_data)) {
             if ($mask) {
                 $filter_data['masked'] = true;
             }
             if ($resample) {
                 $filter_data['resampled'] = true;
             }
             if ($limit) {
                 $filter_data['limited'] = true;
             }
         }
     } else {
         $mask = NULL;
         $resample = 0;
         $limit = 0;
     }
     if (!$mask || !is_array($ids = $mask->GetIDs())) {
         $ids = array(0, 1);
     }
     $data_request = "";
     if (in_array(0, $ids)) {
         if ($writable) {
             $data_request .= "{$this->db->col_quote}{$this->rw_cols[0]}{$this->db->col_quote}, ";
         } else {
             $data_request .= "{$this->db->col_quote}{$this->ro_cols[0]}{$this->db->col_quote}, ";
         }
     }
     if ($writable && in_array(1, $ids)) {
         $data_request .= "{$this->db->col_quote}{$this->rw_cols[1]}{$this->db->col_quote}, ";
     }
     $data_request .= "time";
     $selopts = array("condition" => "{$this->db->col_quote}time{$this->db->col_quote} BETWEEN " . $this->db->SQLTime($from) . " and " . $this->db->SQLTime($to));
     if ($this->data_cond) {
         $selopts['condition'] .= " AND " . $this->SubstituteGroup($this->data_cond, $grp);
     }
     if ($resample) {
         $selopts['sampling'] = array("slicer" => $this->time_module->GetTimeSlicingFunction("{$this->db->col_quote}time{$this->db->col_quote}", $resample), "selector" => "{$this->db->col_quote}time{$this->db->col_quote}");
     }
     if ($limit) {
         $selopts['limit'] = abs($limit);
         if ($limit > 0) {
             $selopts['order'] = "{$this->db->col_quote}time{$this->db->col_quote} ASC";
         } else {
             $selopts['order'] = "{$this->db->col_quote}time{$this->db->col_quote} DESC";
         }
     } else {
         $selopts['order'] = "{$this->db->col_quote}time{$this->db->col_quote} ASC";
     }
     $table = $this->SubstituteGroup($this->data_table, $grp);
     $query = $this->db->SelectRequest($table, $data_request, $selopts);
     #    echo $query . "\n";
     $stmt = $this->db->Prepare($query);
     return new DATABASEData($this, $stmt, DATABASEData::EMPTY_ON_ERROR);
 }
Esempio n. 3
0
 function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     $grp = $this->CheckGroup($grp);
     $postfix = $this->cache->GetCachePostfix($grp->gid);
     $ivl = $this->CreateInterval($grp);
     $ivl->Limit($from, $to);
     if ($filter) {
         $limit = $filter->GetVectorsLimit();
         $resample = $filter->GetSamplingRate();
         $mask = $filter->GetItemMask();
         if (isset($filter_data)) {
             if ($mask) {
                 $filter_data['masked'] = true;
             }
             if ($resample) {
                 $filter_data['resampled'] = true;
             }
             if ($limit) {
                 $filter_data['limited'] = true;
             }
         }
     } else {
         $mask = NULL;
         $resample = 0;
         $limit = 0;
     }
     if (!$mask) {
         $minfo = array("db_mask" => "");
         $mask = $this->cache->CreateCacheMask($postfix, $minfo);
     }
     return $this->cache->GetCachePoints($postfix, $mask, $ivl, CACHEDB::TYPE_ALL, $limit, $resample);
 }
Esempio n. 4
0
 function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     $grp = $this->CheckGroup($grp);
     $ivl = $this->CreateInterval($grp);
     $ivl->Limit($from, $to);
     if ($filter) {
         $mask = $filter->GetItemMask();
         $resample = $filter->GetSamplingRate();
         $limit = $filter->GetVectorsLimit();
         if ($limit) {
             $ivl->SetItemLimit($limit);
         }
         if (isset($filter_data)) {
             if ($mask) {
                 $filter_data['masked'] = true;
             }
             if ($resample) {
                 $filter_data['resampled'] = true;
             }
             if ($limit) {
                 $filter_data['limited'] = true;
             }
         }
     } else {
         $mask = NULL;
         $resample = 0;
         $limit = 0;
     }
     $opts = $this->req->GetGroupOptions($grp);
     $items = $opts->Get('items', $this->items);
     if ($mask && is_array($ids = $mask->GetIDs())) {
         $tmp = array();
         foreach ($ids as $id) {
             if ($id >= sizeof($items)) {
                 throw new ADEIException(translate("Invalid item mask is supplied. The ID:%d refers non-existing item.", $id));
             }
             array_push($tmp, $items[$id]);
         }
         $items = $tmp;
     }
     return new TESTData($this, $this->req->GetGroupOptions($grp), $items, $ivl, $resample);
 }
Esempio n. 5
0
 function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     $grp = $this->CheckGroup($grp);
     if (!$from || !$to) {
         $ivl = $this->CreateInterval($grp);
         $ivl->Limit($from, $to);
         $from = $ivl->GetWindowStart();
         $to = $ivl->GetWindowEnd();
     }
     if ($filter) {
         $mask = $filter->GetItemMask();
         $resample = $filter->GetSamplingRate();
         $limit = $filter->GetVectorsLimit();
         if (isset($filter_data)) {
             if ($mask) {
                 $filter_data['masked'] = true;
             }
             if ($resample) {
                 $filter_data['resampled'] = true;
             }
             if ($limit) {
                 $filter_data['limited'] = true;
             }
         }
     } else {
         $mask = NULL;
         $resample = 0;
         $limit = 0;
     }
     $data_columns = $this->FindColumns($grp, $mask);
     if ($this->emit_delays) {
         log_message("Sleeping");
         usleep($this->emit_delays);
     }
     $selopts = array("condition" => $this->db->col_quote . $this->columns['time'] . "{$this->db->col_quote} BETWEEN " . $this->ImportUnixTime($from) . " and " . $this->ImportUnixTime($to));
     if ($resample) {
         $slicer_col = $this->slicer_column[$grp->gid];
         $selopts['sampling'] = array("slicer" => $this->time_module->GetTimeSlicingFunction("{$slicer_col}", $resample), "selector" => "{$this->db->col_quote}{$this->columns['time']}{$this->db->col_quote}");
     }
     if ($limit) {
         $selopts['limit'] = abs($limit);
         if ($limit > 0) {
             $selopts['order'] = $this->time_sort;
         } else {
             if (!$this->inverse_sort) {
                 throw new ADEIException(translate("The inverse_timesort should be specified in order to select items from the end"));
             }
             $selopts['order'] = $this->inverse_sort;
             if ($limit < -1) {
                 throw new ADEIException(translate("Current version supports only selecting a single item from the end"));
             }
         }
     } else {
         $selopts['order'] = $this->time_sort;
     }
     $query = $this->db->SelectRequest($grp->table, $data_columns, $selopts);
     #    echo $query . "\n";
     $stmt = $this->db->Prepare($query);
     return new DATABASEData($this, $stmt);
 }
Esempio n. 6
0
 function GetRawData(LOGGROUP $grp = NULL, $from = false, $to = false, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     $grp = $this->CheckGroup($grp);
     $ivl = $this->CreateInterval($grp);
     $ivl->Limit($from, $to);
     if ($grp) {
         $groups = array();
         $options = $this->opts;
         # Get Groups
         $groups = $options->Get('groups', false);
         foreach ($groups as $gid => &$group) {
             if ($grp && strcmp($grp->gid, $gid)) {
                 continue;
             }
             $design_view = $groups[$gid]['design_view'];
             $this->view_url = str_replace("%design_view%", $design_view, $this->base_view_url);
         }
     }
     if ($filter) {
         $mask = $filter->GetItemMask();
         $resample = $filter->GetSamplingRate();
         $limit = $filter->GetVectorsLimit();
         if ($limit) {
             $ivl->SetItemLimit($limit);
         }
         if (isset($filter_data)) {
             #if ($mask) $filter_data['masked'] = true;
             if ($resample) {
                 $filter_data['resampled'] = true;
             }
             if ($limit) {
                 $filter_data['limited'] = true;
             }
         }
     } else {
         $mask = NULL;
         $resample = 0;
         $limit = 0;
     }
     foreach ($this->itemList as $key => $value) {
         if (strcmp($grp->gid, $key)) {
             continue;
         }
         $itemList = $value;
     }
     $items = array();
     if ($mask && is_array($ids = $mask->GetIDs())) {
         $tmp = array();
         foreach ($ids as $id) {
             if ($id >= sizeof($itemList)) {
                 throw new ADEIException(translate("Invalid item mask is supplied. The ID:%d refers non-existing item.", $id));
             }
             array_push($tmp, $itemList[$id]);
         }
         $items = $tmp;
     }
     return new COUCHData($this->view_url, $this->alldata_view, $this->req->GetGroupOptions($grp), $items, $ivl);
 }
Esempio n. 7
0
 function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     $grp = $this->CheckGroup($grp);
     $items = $this->GetItemList($grp, new MASK());
     if (!$from || !$to) {
         $ivl = $this->CreateInterval($grp);
         $ivl->Limit($from, $to);
         $from = $ivl->GetWindowStart();
         $to = $ivl->GetWindowEnd();
     }
     if ($filter) {
         $limit = $filter->GetVectorsLimit();
         $resample = $filter->GetSamplingRate();
         if (isset($filter_data)) {
             if ($resample) {
                 $filter_data['resampled'] = true;
             }
             if ($limit) {
                 $filter_data['limited'] = true;
             }
         }
     } else {
         $limit = 0;
         $resample = 0;
     }
     $selopts = array("condition" => "ts BETWEEN " . $this->ImportUnixTime($from) . " and " . $this->ImportUnixTime($to));
     if ($resample) {
         $selopts['sampling'] = array("slicer" => $this->time_module->GetTimeSlicingFunction("ts", $resample), "selector" => "ts");
     }
     if ($limit) {
         $selopts['limit'] = abs($limit);
         if ($limit > 0) {
             $selopts['order'] = "ts ASC";
         } else {
             $selopts['order'] = "ts DESC";
             if ($limit < -1) {
                 throw new ADEIException(translate("Current version supports only selecting a single item from the end"));
             }
         }
     } else {
         $selopts['order'] = "ts ASC";
     }
     $query = $this->db->SelectRequest($grp->table, "ts, data", $selopts);
     $stmt = $this->db->Prepare($query);
     return new ZEUSData($this, $stmt);
 }
Esempio n. 8
0
 function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     //get iterator for raw data of rrd:s archives
     $grp = $this->CheckGroup($grp);
     //checks if the group is valid
     $ivl = $this->CreateInterval($grp);
     //creates a data interval for the group
     if ($filter) {
         $mask = $filter->GetItemMask();
         $resample = $filter->GetSamplingRate();
         $limit = $filter->GetVectorsLimit();
         if ($limit) {
             $ivl->SetItemLimit($limit);
         }
         //if item limit was specified for the filter, then set item limit for interval
         if (isset($filter_data)) {
             if ($mask) {
                 $filter_data['masked'] = true;
             }
             if ($resample) {
                 $filter_data['resampled'] = true;
             }
             if ($limit) {
                 $filter_data['limited'] = true;
             }
         }
     } else {
         $mask = NULL;
         $resample = 0;
         $limit = 0;
     }
     $ivl->Limit($from, $to);
     //set interval timelimit
     $opts = $this->req->GetGroupOptions($grp);
     //get options for group
     $null_mask = new MASK($mreq = array());
     $items = $this::GetItemList($grp, $null_mask);
     //get list of items for current group
     if ($mask && is_array($ids = $mask->GetIDs())) {
         $tmp = array();
         foreach ($ids as $id) {
             if ($id >= sizeof($items)) {
                 throw new ADEIException(translate("Invalid item mask is supplied. The ID:%d refers non-existing item.", $id));
             }
             array_push($tmp, $items[$id]);
             // create a new items array that contains just the items specified by the mask
         }
         $items = $tmp;
     }
     if ($this->munin_datafile) {
         return new MUNINData($this, $opts, $items, $ivl, $resample);
     } else {
         $gid = $grp->gid;
         $info = $this::GetRRDInfo($gid, $this);
         //get rrd info for the current rrd-file
         $step = $info["info"]["step"];
         //get the minimum and maximum interval between two archive datapoints in seconds
         $min_itv = 0;
         $max_itv = 0;
         $max_itv_index = -1;
         foreach ($info["rra"] as $key => $rra) {
             if ($mask) {
                 if (!$mask->Check($key)) {
                     continue;
                 }
             }
             $itv = $info["info"]["step"] * $rra["pdp_per_row"];
             if ($itv > $max_itv) {
                 $max_itv = $itv;
                 $max_itv_index = $key;
             }
             if ($min_itv === 0) {
                 $min_itv = $itv;
             } else {
                 if ($itv < $min_itv) {
                     $min_itv = $itv;
                 }
             }
         }
         //passing a few parameters in options to RRDData
         $opts->options[count($opts->options)]['step'] = $min_itv;
         $opts->options[count($opts->options)]['file'] = $gid;
         $opts->options[count($opts->options)]['data_start'] = time() - $max_itv * $info["rra"][$max_itv_index]["rows"];
         return new RRDData($this, $opts, $items, $ivl, $resample);
         // return raw data
     }
 }