[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_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/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][1] = format_for_graph(
$data[$j]['data'],
2,
'.',
',',
1024,
'B'
);
$table->data[$x][1] = network_format_bytes($data[$j]['data']);
$j++;
$x++;
@ -362,13 +356,8 @@ function netflow_data_table($data, $start_date, $end_date, $aggregate, $unit)
foreach ($data['data'] as $timestamp => $values) {
$table->data[$i][0] = date($time_format, $timestamp);
for ($j = 0; $j < $source_count; $j++) {
$table->data[$i][($j + 1)] = format_for_graph(
(isset($values[$source_index[$j]])) ? $values[$source_index[$j]] : 0,
2,
'.',
',',
1024,
'B'
$table->data[$i][($j + 1)] = network_format_bytes(
$values[$source_index[$j]]
);
}
@ -402,32 +391,32 @@ function netflow_summary_table($data)
$row = [];
$row[] = __('Total flows');
$row[] = format_numeric($data['totalflows']);
$row[] = format_for_graph($data['totalflows'], 2);
$table->data[] = $row;
$row = [];
$row[] = __('Total bytes');
$row[] = format_numeric($data['totalbytes']);
$row[] = network_format_bytes($data['totalbytes']);
$table->data[] = $row;
$row = [];
$row[] = __('Total packets');
$row[] = format_numeric($data['totalpackets']);
$row[] = format_for_graph($data['totalpackets'], 2);
$table->data[] = $row;
$row = [];
$row[] = __('Average bits per second');
$row[] = format_numeric($data['avgbps']);
$row[] = network_format_bytes($data['avgbps']);
$table->data[] = $row;
$row = [];
$row[] = __('Average packets per second');
$row[] = format_numeric($data['avgpps']);
$row[] = format_for_graph($data['avgpps'], 2);
$table->data[] = $row;
$row = [];
$row[] = __('Average bytes per packet');
$row[] = format_numeric($data['avgbpp']);
$row[] = format_for_graph($data['avgbpp'], 2);
$table->data[] = $row;
$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 .= '<td>';
$html .= netflow_summary_table($data_summary);
$html .= '<b>'.__('Unit').':</b> '.netflow_format_unit($unit);
$html .= '&nbsp;<b>'.__('Aggregate').':</b> '.netflow_format_aggregate($aggregate);
$html .= '</td>';
$html .= '<td>';

View File

@ -128,3 +128,29 @@ function network_print_explorer_header(
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['bytes'] = format_for_graph(
$item['sum_bytes'],
2,
'.',
',',
1024,
'B'
);
$row['bytes'] = network_format_bytes($item['sum_bytes']);
if (!$is_network) {
$row['bytes'] .= ' ('.$item['pct_bytes'].'%)';
}