public static function addDS2RRDFile($rrdFileName, $newDS) { //Get Existing Datasources $datassources = self::getDSFromRRDFile($rrdFileName); //Add New DataSources $datassources[] = $newDS; //Create array with DS Options $dsoptions = array(); foreach ($datassources as $ds) { $dsoptions[] = RRD::getDSOption($ds); } //get RRD Options $rrdOptions = RRD::getRRDFileOptions($dsoptions); //Move OriginalFile to /tmp $tmpFileName = "/tmp/tmp.rrd"; rename($rrdFileName, $tmpFileName); //add source options $rrdOptions[] = "-r"; $rrdOptions[] = $tmpFileName; echo "\n\nUPDATE RRD\n\n"; print_r($rrdOptions); echo "\n\n+++++++++++\n\n"; echo $rrdFileName; echo "\n\n###########\n\n"; //create new RRDFile //RRD::createRRDFile($rrdFileName,$rrdOptions); $cmd = "rrdcreate " . $rrdFileName . " " . implode(" ", $rrdOptions); echo $cmd; echo "\n"; shell_exec($cmd); }
function testRRD() { $RRD = new RRD("/tmp/test.rrd"); // Add DS $RRD->AddDS(new RRDDS("test", "GAUGE", 3600)); $RRD->AddDS(new RRDDS("test2", "GAUGE", 3600)); // Add RRA $RRD->AddRRA(new RRA("HWPREDICT", array(1440, 0.1, 0.0035, 288))); $RRD->AddRRA(new RRA("AVERAGE", array(0.5, 1, 1000))); $this->assertTrue($RRD->Create(0, 3600) && file_exists("/tmp/test.rrd"), "Database created."); $this->assertTrue($RRD->Update(array(1, 2)), "Database updated."); }
private function createHardwareGraph($start, $title, $width, $height) { $options = array("--slope-mode", "--start", "-" . $start, "--title={$title}", "--vertical-label=Hardware", "--width", $width, "--height", $height, "--lower=0"); //$hardwareDS = RRD::getDSFromRRDFile($this->rrdHardwareFile); //sort($hardwareDS); $hardwareDS = array(); $hardwareDSsort = $this->hardwareMapper->getMappingSort(); foreach ($hardwareDSsort as $key => $value) { $hardwareDS[] = $key; } for ($i = 0; $i < count($hardwareDS); $i++) { $hardware = $hardwareDS[$i]; $options[] = "DEF:" . $hardware . "=" . $this->rrdHardwareFile . ":" . $hardware . ":AVERAGE"; if ($i == 0) { $options[] = "AREA:" . $hardware . ColorTable::getColor($i) . ":" . $this->hardwareMapper->getNameForCode($hardware) . "\t"; } else { $options[] = "STACK:" . $hardware . ColorTable::getColor($i) . ":" . $this->hardwareMapper->getNameForCode($hardware) . "\t"; } $options[] = 'GPRINT:' . $hardware . ':AVERAGE:%8.0lf %s\\l'; } //print_r($options); $options[] = "--tabwidth"; $options[] = "350"; RRD::createRRDGraph($this->getFileName("hardware", $start, $width, $height), $options); }
foreach ($aggregrated_graph_traffic[$aggr_id] as $name => $file) { array_push($rrdfiles, "{$file}"); $archives[$file] = $name; } } } else { foreach ($_GET['RRA'] as $file => $datasource) { $file = "{$rrd_dir}/{$file}"; array_push($rrdfiles, "{$file}"); $archives[$file] = $datasource; } if (isset($_GET['color'])) { foreach ($_GET['color'] as $file => $color) { $file = "{$rrd_dir}/{$file}"; if (array_key_exists($file, $archives)) { $colors[$file] = $color; } } } } //$rrd = new RRD($rrdfiles,$rrdtool); $rrd = new RRD($nested_aggregrated_graph_traffic[$aggr_id], $rrdtool); $graph_params = array('type' => 'aggr_traf', 'colors' => $colors, 'archives' => $archives, 'title' => $title, 'legend' => $legend, 'width' => $width, 'height' => $height, 'total' => $total, 'start' => $from, 'end' => $to); $graphfile = $rrd->get_graph($graph_params); } elseif ($type == "check") { #print "in check file is $file<br>"; // Now determin if there are any datasources we want to be ignore $graph_params = array('type' => 'check', 'title' => $title, 'legend' => $legend, 'width' => $width, 'height' => $height, 'start' => $from, 'end' => $to, 'exclude_ds' => $exclude_ds, 'ds_colors' => $ds_colors); $graphfile = $rrd->get_graph($graph_params); } $rrd->print_graph();
function displayCheckGraphs($interval = 'day') { global $tool, $form, $status_array, $status_collors; $my_colors = array("FF0000", "0404B4", "04B431", "B45F04", "F7FE2E", "8B008B", "4B0082", "FA8072", "4169E1", "D2B9D3", "B4CFEC", "eF6600", "77CEEB", "eFFF00", "6FFF00", "8E7BFF", "7B008B", "3B0082", "eA8072", "3169E1", "c2B9D3", "a4CFEC", "dF6600", "67CEEB", "dFFF00", "5FFF00", "7E7BFF", "6B008B", "2B0082", "dA8072", "2169E1", "b2B9D3", "94CFEC"); if (is_numeric($_GET[checkid])) { $check = new Check($_GET[checkid]); } else { $form->warning("Invalid check id"); } $property = new Property(); if ($rrd_dir = $property->get_property("path_rrddir")) { } else { $form->warning($property->get_error()); return false; } if ($rrdtool = $property->get_property("path_rrdtool")) { } else { return; } $filename = "checks/checkid_" . $check->get_check_id() . ".rrd"; $filepath = $rrd_dir . "/" . $filename; // Now check if there's are graphs for this check // Not all checks have these if (!file_exists($filepath)) { //$form->warning( "file $filename not there"); return false; } if ($interval == 'week') { $from = "-7d"; } elseif ($interval == 'month') { $from = "-1m"; } elseif ($interval == 'year') { $from = "-365d"; } else { $from = "-24h"; } $rrd = new RRD("{$filepath}", $rrdtool); $datasources = $rrd->get_data_sources(); ksort($datasources, SORT_STRING); $exclude_ds = array(); $color_codes = ""; $exclude = ""; $i = 0; foreach ($datasources as $ds => $value) { $color_code .= "&ds_colors[{$ds}]={$my_colors[$i]}"; $i++; if (isset($_GET[$ds]) && $_GET[$ds] == 'no') { array_push($exclude_ds, $ds); $exclude .= "&exclude_ds[{$ds}]=yes"; } } $rrd_url = "rrdgraph.php?file=" . urlencode($filename) . "&type=check&title=" . urlencode($check->get_name()) . "&width=400&height=122&from={$from}" . "{$exclude}" . $color_code; return "<img src='{$rrd_url}'>"; }
private function createGraphTrafficPackages($start, $title, $width, $height) { $options = array("--slope-mode", "--start", "-" . $start, "--title={$title}", "--vertical-label=Traffic Packages", "--width", $width, "--height", $height, "--lower=0", "DEF:trafRxPa=" . $this->getRRDFileName() . ":trafRxPa:AVERAGE", "DEF:trafTxPa=" . $this->getRRDFileName() . ":trafTxPa:AVERAGE", "DEF:trafMgmtTxPa=" . $this->getRRDFileName() . ":trafMgmtTxPa:AVERAGE", "DEF:trafMgmtRxPa=" . $this->getRRDFileName() . ":trafMgmtRxPa:AVERAGE", "DEF:trafForwardPa=" . $this->getRRDFileName() . ":trafForwardPa:AVERAGE", "LINE2:trafRxPa#00FF00:trafRxPa", "LINE2:trafTxPa#F06FF0:trafTxPa", "LINE2:trafMgmtTxPa#0F0FF0:trafMgmtTxPa", "LINE2:trafMgmtRxPa#FFFF0F:trafMgmtRxPa", "LINE2:trafForwardPa#124f77:trafForwardPa"); RRD::createRRDGraph($this->getFileName("trafficPackages", $start, $width, $height), $options); }
function render_report() { if (isset($_GET['pid']) && is_numeric($_GET['pid'])) { $pid = $_GET['pid']; } else { return "<b>Sorry invalid profile id " . $_GET['pid'] . "</b>"; } $profile_name = $this->get_accounting_profile_name($pid); // Menu bar $content .= "<div style='font-size:10px; font-weight:100px;'>\n\t\t\t<a href='{$this->url}'>Accounting</a> >> <a href='{$this->url}&pid={$pid}&action=show_accounting_profile'>{$profile_name}</a></div>"; $content .= '<h2>Accounting Report</h2>'; $from = $_GET[date1]; $to = $_GET[date2]; // Now render data $archives = ''; $files = array(); $query = "select accounting_sources.title, accounting_sources.scu_profile, \n\t\t\taccounting_sources.file \n\t\t\tFROM accounting_sources, accounting_profiles_files\n\t\t\tWHERE accounting_sources.id = accounting_profiles_files.accounting_source \n\t\t\tAND accounting_profiles_files.profile_id = '{$pid}' "; $result = mysql_query($query); if (!$result) { return "<b>Graph information not found </b>"; } while ($obj = mysql_fetch_object($result)) { $file = $obj->file; $title = $obj->title; $url2 .= "&RRA[accounting/{$file}]={$title}"; array_push($files, "{$this->rrd_dir}/accounting/{$file}"); $archives["{$this->rrd_dir}/accounting/{$file}"] = $title; } // Get summary list($year1, $month1, $day1) = split("-", $from); list($year2, $month2, $day2) = split("-", $to); $rrd_from = @mktime(0, 0, 0, $month1, $day1, $year1); #$rrd_from = "12am $month1/$day1/$year1"; $rrd_to = @mktime(0, 0, 0, $month2, $day2, $year2); // -1 sec, so it aligns perfect $rrd_to = $rrd_to - 1; #print " $rrd_from $rrd_to ->"; #echo date("i:H M/d/Y",$rrd_from); if (!is_numeric($rrd_from)) { return "Invalid From date"; } if (!is_numeric($rrd_to)) { return "Invalid To date"; } $rrd_width = round(($rrd_to - $rrd_from) / 300) + 10; $rrd = new RRD($files, $this->rrdtool); $summary = $rrd->get_summary($rrd_from, $rrd_to, $archives); // Determine highest 95% number => Billing $billing_number = "N/A"; $in_95 = $this->si_to_int($summary['95IN']); $out_95 = $this->si_to_int($summary['95OUT']); if ($in_95 > $out_95) { $billing_number = $summary['95IN']; } elseif ($out_95 >= $in_95) { $billing_number = $summary['95OUT']; } /* if ($summary{'95IN'} > $summary{'95OUT'}) { $billing_number = $summary{'95IN'}; } elseif ($summary{'95OUT'} > $summary{'95IN'}) { $billing_number = $summary{'95OUT'}; } */ $content .= "<p><form><b>Save this report as: </b><input type=hidden name=pid value={$pid}>\n\t\t\t\t<input type=hidden name=pluginID value=" . $_GET['pluginID'] . ">\n\t\t\t\t<input type=hidden name=tab value=" . $_GET['tab'] . ">\n\t\t\t\t<input type=hidden name=from value={$rrd_from}>\n\t\t\t\t<input type=hidden name=to value={$rrd_to}>\n\t\t\t\t<input type=hidden name=action value=save_report>\n\t\t\t\t<input type=text name=report_name id=report_name size='40'>"; $content .= " <input type='submit' name='mysubmit' value='Save Report'></form></p> <br> "; #$content.= "<a href='$url&action=save_report&pid=$pid&from=$rrd_from&to=$rrd_to'><b>Save Report</b></a>"; $content .= "<table><th colspan=2><b>Reporting Period {$from} - {$to}</b></th><tr><td>"; $content .= "<img src='rrdgraph.php?type=aggr_traf" . $url2 . "&title=Reporting Period {$from} - {$to}&height=150&width=700&from={$rrd_from}&to={$rrd_to}&showtotal=0'>"; $content .= "</td><td valign='top'><b><center>Summary</b></center><br>"; $content .= "<table valign='top'><tr><th></th><th>In</th><th>Out</th></tr>"; $content .= "<tr><td>Average</td><td>" . $summary['AVERAGEIN'] . "bs</td><td>" . $summary['AVERAGEOUT'] . "bs</td></tr>"; $content .= "<tr><td>Max</td><td>" . $summary['MAXIN'] . "bs</td><td>" . $summary['MAXOUT'] . "bs</td></tr>"; $content .= "<tr><td>95th Percentile</td><td>" . $summary['95IN'] . "bs</td><td>" . $summary['95OUT'] . "bs</td></tr>"; $content .= "<tr><td>Total</td><td>" . $summary['TOTALIN'] . "B</td><td>" . $summary['TOTALOUT'] . "B</td></tr>"; $content .= "</table><hr><table>"; $content .= "<tr><td>First Measurement <br>sample</td><td>" . $summary['FROM'] . "</td></tr>"; $content .= "<tr><td>Last Measurement <br>sample</td><td>" . $summary['TO'] . "</td></tr>"; $content .= "<tr><td><p>Total Traffic for <br>this accounting period</td><td> " . $summary['TOTAL'] . "B</td></tr>"; $content .= "<tr><td>Billed 95th% for <br>for this accounting period</td><td> " . $billing_number . "bs</td></tr></table>"; $content .= "</td></tr></table>"; return $content; }