예제 #1
0
            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();
예제 #2
0
 function insert_report($pid, $from, $to, $name)
 {
     if ($name == '') {
         print "Invalid name";
         return false;
     }
     if (!is_numeric($pid)) {
         return false;
     }
     $rrd_from = $from;
     $rrd_to = $to;
     if (!is_numeric($rrd_from)) {
         print "Invalid from date";
         return false;
     }
     if (!is_numeric($rrd_to)) {
         print "Invalid to date";
         return false;
     }
     // Now render data
     $archives = '';
     $files = array();
     $query = "select accounting_profiles.traffic_cap, accounting_sources.title, accounting_sources.scu_profile, \n\t\t\taccounting_sources.file \n\t\t\tFROM accounting_sources, accounting_profiles_files, accounting_profiles\n\t\t\tWHERE accounting_sources.id = accounting_profiles_files.accounting_source \n\t\t\tAND accounting_profiles.profile_id = '{$pid}'\n\t\t\tAND accounting_profiles_files.profile_id = '{$pid}' ";
     $result = mysql_query($query);
     if (!$result) {
         print "failed to execute query {$query}<br>";
         return false;
     }
     while ($obj = mysql_fetch_object($result)) {
         $file = $obj->file;
         $title = $obj->title;
         if ($obj->traffic_cap) {
             $sql_traffic_cap = "traffic_cap = {$obj->traffic_cap}";
         } else {
             $sql_traffic_cap = "traffic_cap = NULL";
         }
         $url2 .= "&RRA[accounting/{$file}]={$title}";
         array_push($files, "{$this->rrd_dir}/accounting/{$file}");
         $archives["{$this->rrd_dir}/accounting/{$file}"] = $title;
     }
     $rrd = new RRD($files, $this->rrdtool);
     $summary = $rrd->get_summary($rrd_from, $rrd_to, $archives);
     #print_r($summary);
     $avg_in = $this->si_to_int($summary['AVERAGEIN']);
     $avg_out = $this->si_to_int($summary['AVERAGEOUT']);
     $max_in = $this->si_to_int($summary['MAXIN']);
     $max_out = $this->si_to_int($summary['MAXOUT']);
     $in_95 = $this->si_to_int($summary['95IN']);
     $out_95 = $this->si_to_int($summary['95OUT']);
     $tot_in = $this->si_to_int($summary['TOTALIN']);
     $tot_out = $this->si_to_int($summary['TOTALOUT']);
     $sample_date1 = $summary['FROM'];
     $sample_date2 = $summary['TO'];
     // This is to get the timestamp of the 1st and last sample
     // They come in this format 14-04-2010 00:00:00
     $datetime1 = date_create($sample_date1);
     $timestamp1 = $datetime1->format('U');
     $datetime2 = date_create($sample_date2);
     $timestamp2 = $datetime2->format('U');
     /* Ok now generate graph */
     //https://nms.bc.net/cmdb/rrdgraph.php?type=aggr_traf&RRA[accounting/deviceid4_Akamai%20--%20EX%20208%20Telus%20Transit.rrd]=Akamai%20--%20EX%20208%20Telus%20Transit&RRA[accounting/deviceid4_Akamai%20--%20CU%20248%20Shaw%20Commodity%20Transit%20in%20Vancouver.rrd]=Akamai%20--%20CU%20248%20Shaw%20Commodity%20Transit%20in%20Vancouver&RRA[accounting/deviceid9_Akamai%20--%20CU%2090%20Peer1-Transit.rrd]=Akamai%20--%20CU%2090%20Peer1-Transit&title=Aggregated%20Graph&height=150&width=700&from=1271142000&to=1271314800
     $graph_params = array('type' => 'aggr_traf', 'archives' => $archives, 'total' => 0, 'title' => $name, 'width' => "700", 'height' => "150", 'start' => $rrd_from, 'end' => $rrd_to);
     $rrd->get_graph($graph_params);
     #$rrd->print_graph();
     $img = $rrd->get_graph_img();
     #print "size is ".getimagesize($img);
     $img = base64_encode($rrd->get_graph_img());
     #$img=mysql_real_escape_string($img);
     $query = "Insert into accounting_reports SET\n\t\t\tprofile_id = '{$pid}', \treport_name  = '{$name}',\n\t\t\tavg_in = '{$avg_in}', avg_out = '{$avg_out}',\n\t\t\tmax_in = '{$max_in}', max_out = '{$max_out}',\n\t\t\t95_in = '{$in_95}', 95_out = '{$out_95}',\n\t\t\ttot_in = '{$tot_in}', tot_out = '{$tot_out}',\n\t\t\tdate1 = FROM_UNIXTIME( '{$from}' ), date2 = FROM_UNIXTIME( '{$to}' ),\n\t\t\tsample_date1 = FROM_UNIXTIME( '{$timestamp1}' ), sample_date2 = FROM_UNIXTIME( '{$timestamp2}' ),\n\t\t\t`img_file` = '{$img}', {$sql_traffic_cap}\n\t\t\t";
     $result = mysql_query($query);
     if (!$result) {
         print mysql_error();
         return false;
     }
     $new_report_id = mysql_insert_id();
     return $new_report_id;
 }