$data) { $totalInOctets = 0; $totalOutOctets = 0; if (!isset($colours[$i])) { $i = 0; } //fetch ports in group using existing observium functioon foreach (get_group_entities($data['group'], 'port') as $port_id) { $octets = dbFetchRow("SELECT `ifInOctets_rate`, `ifOutOctets_rate` FROM `ports` WHERE `port_id` = ?", [$port_id]); $totalInOctets += $octets['ifInOctets_rate']; $totalOutOctets += $octets['ifOutOctets_rate']; } $totals_array[$type]["in"] = $totalInOctets * 8; $totals_array[$type]["out"] = $totalOutOctets * 8; $port_ids[$type][] = $port_id; $graph_data[] = ['group_id' => $data['group'], 'descr' => $type, 'colour' => $colours[$i]]; $i++; } // total things up $totalIn = 0; $totalOut = 0; foreach ($totals_array as $type => $dir) { $totalIn = $totalIn + $dir['in']; $totalOut = $totalOut + $dir['out']; } $percentage_bar = []; $percentage_bar['border'] = "#EEE"; $percentage_bar['bg'] = "#f0f0f0"; $percentage_bar['width'] = "100%"; //$percentage_bar['text'] = $avai_perc."%"; //$percentage_bar['text_c'] = "#E25A00"; $percentage_bar_out = $percentage_bar; // do the real work $percentIn = ""; $percentOut = ""; $legend = ''; $i = 0; $table_min_height = 84; // Height of the three in/out/total bars $table_row_height = 26; // Height of single row $table_padding = 8; // Total vertical padding $table_height = ($table_row_height * count($totals_array)) + $table_padding; if ($table_height < $table_min_height) { $table_height = $table_min_height; } foreach ($totals_array as $type => $dir) { $percentIn = float_div($dir["in"], $totalIn) * 100; $percentOut = float_div($dir["out"], $totalOut) * 100; $percent = float_div(($dir["in"] + $dir["out"]), ($totalIn + $totalOut)) * 100; if (!isset($colours[$i])) { $i = 0; } $color = $config['graph_colours']['mixed'][$i]; $class = $classes[$i]; $bars_in .= '
' . round($percentIn) . '%' . '
'; $bars_out .= '
' . round($percentOut) . '%' . '
'; $bars .= '
' . round($percent) . '%' . '
'; $i++; $legend .= ''; } $legend .= '
' . $type . ' ' . format_si($dir['in']) . 'bps ' . format_si($dir['out']) . 'bps
'; $box_args = ['title' => 'Traffic Comparison', 'header-border' => TRUE, 'padding' => FALSE, ]; $box_args['header-controls'] = ['controls' => ['tooltip' => [//'icon' => $config['icon']['info'], 'anchor' => TRUE, 'text' => (($options['graph_format'] == "multi" || $options['graph_format'] == "multi_bare") ? 'DayWeekMonthYear' : '48 Hours'), 'class' => 'tooltip-from-element', //'url' => '#', 'data' => 'data-tooltip-id="tooltip-help-conditions"']]]; echo generate_box_open($box_args); ?> 'multi-port_groups_bits', 'width' => 1239, 'height' => 89, 'legend' => 'no', 'from' => get_time('twoday'), 'to' => get_time('now'), 'perc_agg' => TRUE, 'data' => var_encode($graph_data), // 'width' => '305' ]; echo ''; } if (!isset($options['legend_width'])) { $options['legend_width'] = "220"; } ?>
'; // Calculate height available for graph if (isset($width)) { $graph_array['height'] = $height - (82 + 0 + $table_height); } else { $graph_array['height'] = 100; } switch ($options['graph_format']) { case 'single': $graph_array['width'] = 1148; $graph_array['draw_all'] = 'yes'; if (isset($width)) { $graph_array['width'] = ($width - 10 - 76); if ($graph_array['width'] > 350) { $graph_array['width'] -= 6; } } echo generate_graph_tag($graph_array); break; // FIXME - This logic should probably be functionalised, and the cuttoff to switch font should be a variable. case 'multi': $graph_array['draw_all'] = 'yes'; unset($graph_array['width']); if (isset($width)) { $graph_array['width'] = round(($width - 19) / 4); if ($graph_array['width'] > 350) { $graph_array['width'] -= 82; } else { $graph_array['width'] -= 76; } } print_graph_row($graph_array); break; case 'multi_bare': $graph_array['width'] = 305; $graph_array['graph_only'] = 'yes'; if (isset($width)) { $graph_array['width'] = ($width - 19) / 4; } $graph_array['height'] += 39; print_graph_row($graph_array); break; case 'single_bare': default: $graph_array['graph_only'] = 'yes'; if (isset($width)) { $graph_array['width'] = ($width - 10); } $graph_array['height'] += 39; echo(generate_graph_tag($graph_array)); break; } echo '
In
Out
Total