[Netflow live] Added removed unit from pie graph and summary table and refactorized bytes format

Former-commit-id: 35b9fd71ad97869e23119bd0d2031ec12400d745
This commit is contained in:
fermin831 2019-03-14 09:25:50 +01:00
parent 834c18e49e
commit e16d48804e
3 changed files with 37 additions and 30 deletions

View File

@ -14,6 +14,7 @@
require_once $config['homedir'].'/include/functions_users.php'; require_once $config['homedir'].'/include/functions_users.php';
require_once $config['homedir'].'/include/functions_io.php'; require_once $config['homedir'].'/include/functions_io.php';
require_once $config['homedir'].'/include/functions_io.php'; require_once $config['homedir'].'/include/functions_io.php';
require_once $config['homedir'].'/include/functions_network.php';
enterprise_include_once($config['homedir'].'/enterprise/include/pdf_translator.php'); enterprise_include_once($config['homedir'].'/enterprise/include/pdf_translator.php');
enterprise_include_once($config['homedir'].'/enterprise/include/functions_metaconsole.php'); enterprise_include_once($config['homedir'].'/enterprise/include/functions_metaconsole.php');
@ -268,14 +269,7 @@ function netflow_stat_table($data, $start_date, $end_date, $aggregate)
} }
$table->data[$x][0] = $agg; $table->data[$x][0] = $agg;
$table->data[$x][1] = format_for_graph( $table->data[$x][1] = network_format_bytes($data[$j]['data']);
$data[$j]['data'],
2,
'.',
',',
1024,
'B'
);
$j++; $j++;
$x++; $x++;
@ -362,13 +356,8 @@ function netflow_data_table($data, $start_date, $end_date, $aggregate, $unit)
foreach ($data['data'] as $timestamp => $values) { foreach ($data['data'] as $timestamp => $values) {
$table->data[$i][0] = date($time_format, $timestamp); $table->data[$i][0] = date($time_format, $timestamp);
for ($j = 0; $j < $source_count; $j++) { for ($j = 0; $j < $source_count; $j++) {
$table->data[$i][($j + 1)] = format_for_graph( $table->data[$i][($j + 1)] = network_format_bytes(
(isset($values[$source_index[$j]])) ? $values[$source_index[$j]] : 0, $values[$source_index[$j]]
2,
'.',
',',
1024,
'B'
); );
} }
@ -402,32 +391,32 @@ function netflow_summary_table($data)
$row = []; $row = [];
$row[] = __('Total flows'); $row[] = __('Total flows');
$row[] = format_numeric($data['totalflows']); $row[] = format_for_graph($data['totalflows'], 2);
$table->data[] = $row; $table->data[] = $row;
$row = []; $row = [];
$row[] = __('Total bytes'); $row[] = __('Total bytes');
$row[] = format_numeric($data['totalbytes']); $row[] = network_format_bytes($data['totalbytes']);
$table->data[] = $row; $table->data[] = $row;
$row = []; $row = [];
$row[] = __('Total packets'); $row[] = __('Total packets');
$row[] = format_numeric($data['totalpackets']); $row[] = format_for_graph($data['totalpackets'], 2);
$table->data[] = $row; $table->data[] = $row;
$row = []; $row = [];
$row[] = __('Average bits per second'); $row[] = __('Average bits per second');
$row[] = format_numeric($data['avgbps']); $row[] = network_format_bytes($data['avgbps']);
$table->data[] = $row; $table->data[] = $row;
$row = []; $row = [];
$row[] = __('Average packets per second'); $row[] = __('Average packets per second');
$row[] = format_numeric($data['avgpps']); $row[] = format_for_graph($data['avgpps'], 2);
$table->data[] = $row; $table->data[] = $row;
$row = []; $row = [];
$row[] = __('Average bytes per packet'); $row[] = __('Average bytes per packet');
$row[] = format_numeric($data['avgbpp']); $row[] = format_for_graph($data['avgbpp'], 2);
$table->data[] = $row; $table->data[] = $row;
$html = html_print_table($table, true); $html = html_print_table($table, true);
@ -1319,7 +1308,6 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil
$html .= '<tr>'; $html .= '<tr>';
$html .= '<td>'; $html .= '<td>';
$html .= netflow_summary_table($data_summary); $html .= netflow_summary_table($data_summary);
$html .= '<b>'.__('Unit').':</b> '.netflow_format_unit($unit);
$html .= '&nbsp;<b>'.__('Aggregate').':</b> '.netflow_format_aggregate($aggregate); $html .= '&nbsp;<b>'.__('Aggregate').':</b> '.netflow_format_aggregate($aggregate);
$html .= '</td>'; $html .= '</td>';
$html .= '<td>'; $html .= '<td>';

View File

@ -128,3 +128,29 @@ function network_print_explorer_header(
return $cell; return $cell;
} }
/**
* Alias for format_for_graph to print bytes.
*
* @param integer $value Value to parse like bytes.
*
* @return string Number parsed.
*/
function network_format_bytes($value)
{
if (!isset($value)) {
$value = 0;
}
$value = (int) $value;
return format_for_graph(
$value,
2,
'.',
',',
1024,
'B'
);
}

View File

@ -299,14 +299,7 @@ foreach ($data as $item) {
$row['pkts'] .= ' ('.$item['pct_pkts'].'%)'; $row['pkts'] .= ' ('.$item['pct_pkts'].'%)';
} }
$row['bytes'] = format_for_graph( $row['bytes'] = network_format_bytes($item['sum_bytes']);
$item['sum_bytes'],
2,
'.',
',',
1024,
'B'
);
if (!$is_network) { if (!$is_network) {
$row['bytes'] .= ' ('.$item['pct_bytes'].'%)'; $row['bytes'] .= ' ('.$item['pct_bytes'].'%)';
} }