public function update() { if (!file_exists($this->file)) { return array(); } $this->name = Kwf_Util_Rrd_Field::escapeField($this->name); $this->newName = Kwf_Util_Rrd_Field::escapeField($this->newName); if (!$this->silent) { echo "renaming rrd field: " . $this->name . "\n"; } $xml = $this->_dump(); $found = false; foreach ($xml->ds as $ds) { if (trim($ds->name) == $this->name) { $ds->name = $this->newName; $found = true; break; } } if (!$found) { throw new Kwf_ClientException("Field '{$this->name}' not found"); } $this->_restore($xml); return array(); }
public function update() { if (!file_exists($this->file)) { return array(); } $this->name = Kwf_Util_Rrd_Field::escapeField($this->name); if (!$this->silent) { echo "adding rrd field: " . $this->name . "\n"; } $sXml = $this->_dump(); foreach ($sXml->rra as $rra) { $ds = $rra->cdp_prep->addChild('ds'); $ds->primary_value = 'NaN'; $ds->secondary_value = 'NaN'; $ds->value = 'NaN'; $ds->unknown_datapoints = '0'; foreach ($rra->database->row as $r) { $r->addChild('v', 'NaN'); } } $xml = dom_import_simplexml($sXml); $doc = $xml->ownerDocument; $ds = $doc->createElement('ds'); $ds = $xml->insertBefore($ds, $doc->getElementsByTagName('rra')->item(0)); $ds->appendChild($doc->createElement('name', $this->name)); $ds->appendChild($doc->createElement('type', $this->type)); $ds->appendChild($doc->createElement('minimal_heartbeat', $this->minimalHeartbeat)); $ds->appendChild($doc->createElement('min', $this->min)); $ds->appendChild($doc->createElement('max', $this->max)); $ds->appendChild($doc->createElement('last_ds', 'U')); $ds->appendChild($doc->createElement('value', 'NaN')); $ds->appendChild($doc->createElement('unknown_sec', 3)); $this->_restore(simplexml_import_dom($xml)); return array(); }
public function update() { if (!file_exists($this->file)) { return array(); } if (is_string($this->name)) { $this->name = array($this->name); } foreach ($this->name as &$n) { $n = Kwf_Util_Rrd_Field::escapeField($n); } if (!$this->silent) { echo "dropping rrd fields: " . implode($this->name) . "\n"; } $xml = $this->_dump(); $found = false; $index = 0; foreach ($xml->ds as $ds) { if (in_array(trim($ds->name), $this->name)) { $ds = dom_import_simplexml($ds); $ds->parentNode->removeChild($ds); $i = 0; foreach ($xml->rra->cdp_prep->ds as $ds2) { if ($i == $index) { $ds2 = dom_import_simplexml($ds2); $ds2->parentNode->removeChild($ds2); break; } $i++; } foreach ($xml->rra->database->row as $row) { $i = 0; foreach ($row->v as $v) { if ($i == $index) { $v = dom_import_simplexml($v); $v->parentNode->removeChild($v); break; } $i++; } } } $index++; } $this->_restore($xml); return array(); }
public function getAverageValues($fields, $start, $end) { if (!file_exists($this->_fileName)) { $ret = array(); foreach ($fields as $f) { $ret[$f] = 0; } } $cmd = "rrdtool fetch {$this->_fileName} AVERAGE --start {$start} --end {$end} 2>&1"; exec($cmd, $rows); foreach ($fields as $f) { $sum[$f] = 0; $cnt[$f] = 0; } foreach ($rows as $k => $r) { preg_match_all('#[^ ]+#', $r, $m); $r = $m[0]; if ($k == 0) { $fileFields = $r; } else { if ($k == 1) { //leerzeile } else { if (count($fileFields) + 1 != count($r)) { throw new Kwf_Exception("invalid row?!"); } $time = array_shift($r); $time = (int) substr($time, 0, -1); foreach ($fields as $f) { $v = $r[array_search(Kwf_Util_Rrd_Field::escapeField($f), $fileFields)]; if (preg_match('#^([0-9]\\.[0-9]+)e([+-])([0-9]{2})$#', $v, $m)) { $v = (double) $m[1] * ($m[2] == '-' ? -1 : 1) * pow(10, (int) $m[3]); $sum[$f] += $v; $cnt[$f]++; } } } } } $ret = array(); foreach ($fields as $f) { if ($cnt[$f]) { $ret[$f] = $sum[$f] / $cnt[$f]; } else { $ret[$f] = 0; } } return $ret; }