diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php
index 4d9ae9eca6..6843dab8da 100644
--- a/pandora_console/include/functions_graph.php
+++ b/pandora_console/include/functions_graph.php
@@ -4289,7 +4289,7 @@ function graph_netflow_aggregate_pie($data, $aggregate, $ttl=1, $only_image=fals
/**
* Print a circular graph with the data transmitted between IPs
*/
-function graph_netflow_circular_mesh($data, $unit, $radius=700)
+function graph_netflow_circular_mesh($data, $radius=700)
{
global $config;
@@ -4299,7 +4299,7 @@ function graph_netflow_circular_mesh($data, $unit, $radius=700)
include_once $config['homedir'].'/include/graphs/functions_d3.php';
- return d3_relationship_graph($data['elements'], $data['matrix'], $unit, $radius, true);
+ return d3_relationship_graph($data['elements'], $data['matrix'], $radius, true);
}
diff --git a/pandora_console/include/functions_netflow.php b/pandora_console/include/functions_netflow.php
index af4ca422b2..18a604dfb3 100644
--- a/pandora_console/include/functions_netflow.php
+++ b/pandora_console/include/functions_netflow.php
@@ -809,11 +809,10 @@ function netflow_get_summary($start_date, $end_date, $filter, $connection_name='
* @param string end_date Period end date.
* @param string filter Netflow filter.
* @param int max Maximum number of elements.
- * @param string unit to show.
*
* @return An array with netflow stats.
*/
-function netflow_get_record($start_date, $end_date, $filter, $max, $unit, $address_resolution=false)
+function netflow_get_record($start_date, $end_date, $filter, $max, $address_resolution=false)
{
global $nfdump_date_format;
global $config;
@@ -852,32 +851,7 @@ function netflow_get_record($start_date, $end_date, $filter, $max, $unit, $addre
$data['source_port'] = $items[5];
$data['destination_port'] = $items[6];
$data['protocol'] = $items[7];
-
- switch ($unit) {
- case 'megabytes':
- $data['data'] = ($items[12] / 1048576);
- break;
-
- case 'megabytespersecond':
- $data['data'] = ($items[12] / 1048576 / $data['duration']);
- break;
-
- case 'kilobytes':
- $data['data'] = ($items[12] / 1024);
- break;
-
- case 'kilobytespersecond':
- $data['data'] = ($items[12] / 1024 / $data['duration']);
- break;
-
- default:
- case 'bytes':
- $data['data'] = $items[12];
- break;
- case 'bytespersecond':
- $data['data'] = ($items[12] / $data['duration']);
- break;
- }
+ $data['data'] = $items[12];
$values[] = $data;
}
@@ -1329,7 +1303,7 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil
break;
case 'netflow_mesh':
- $netflow_data = netflow_get_record($start_date, $end_date, $filter, $max_aggregates, $unit, $address_resolution);
+ $netflow_data = netflow_get_record($start_date, $end_date, $filter, $max_aggregates, $address_resolution);
switch ($aggregate) {
case 'srcport':
@@ -1374,14 +1348,14 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil
}
$html = '
';
- $html .= graph_netflow_circular_mesh($data, netflow_format_unit($unit), 700);
+ $html .= graph_netflow_circular_mesh($data, 700);
$html .= '
';
return $html;
break;
case 'netflow_host_treemap':
- $netflow_data = netflow_get_record($start_date, $end_date, $filter, $max_aggregates, $unit, $address_resolution);
+ $netflow_data = netflow_get_record($start_date, $end_date, $filter, $max_aggregates, $address_resolution);
switch ($aggregate) {
case 'srcip':
@@ -1434,7 +1408,7 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil
$children_data['id'] = $id++;
$children_data['name'] = $port;
$children_data['value'] = $value;
- $children_data['tooltip_content'] = "$port: ".format_numeric($value).' '.netflow_format_unit($unit).'';
+ $children_data['tooltip_content'] = $port.': '.network_format_bytes($value).'';
$children['children'][] = $children_data;
}
diff --git a/pandora_console/include/graphs/functions_d3.php b/pandora_console/include/graphs/functions_d3.php
index 3bd3224445..70cafb221f 100644
--- a/pandora_console/include/graphs/functions_d3.php
+++ b/pandora_console/include/graphs/functions_d3.php
@@ -38,7 +38,7 @@ function include_javascript_d3($return=false)
}
-function d3_relationship_graph($elements, $matrix, $unit, $width=700, $return=false)
+function d3_relationship_graph($elements, $matrix, $width=700, $return=false)
{
global $config;
@@ -53,7 +53,7 @@ function d3_relationship_graph($elements, $matrix, $unit, $width=700, $return=fa
$output = '';
$output .= include_javascript_d3(true);
$output .= "";
if (!$return) {
diff --git a/pandora_console/include/graphs/pandora.d3.js b/pandora_console/include/graphs/pandora.d3.js
index 40dcd34ac1..fdca6d10fd 100644
--- a/pandora_console/include/graphs/pandora.d3.js
+++ b/pandora_console/include/graphs/pandora.d3.js
@@ -20,7 +20,7 @@
// matrix = [[0, 0, 2], // a[a => a, a => b, a => c]
// [5, 0, 1], // b[b => a, b => b, b => c]
// [2, 3, 0]]; // c[c => a, c => b, c => c]
-function chordDiagram(recipient, elements, matrix, unit, width) {
+function chordDiagram(recipient, elements, matrix, width) {
d3.chart = d3.chart || {};
d3.chart.chordWheel = function(options) {
// Default values
@@ -206,18 +206,14 @@ function chordDiagram(recipient, elements, matrix, unit, width) {
" → " +
elements[d.target.index] +
": " +
- d.source.value.toFixed(2) +
- " " +
- unit +
+ valueToBytes(d.source.value) +
"" +
"
" +
elements[d.target.index] +
" → " +
elements[d.source.index] +
": " +
- d.target.value.toFixed(2) +
- " " +
- unit +
+ valueToBytes(d.target.value) +
""
)
);
@@ -227,18 +223,14 @@ function chordDiagram(recipient, elements, matrix, unit, width) {
" → " +
elements[d.target.index] +
": " +
- d.source.value.toFixed(2) +
- " " +
- unit +
+ valueToBytes(d.source.value) +
"" +
"
" +
elements[d.target.index] +
" → " +
elements[d.source.index] +
": " +
- d.target.value.toFixed(2) +
- " " +
- unit +
+ valueToBytes(d.target.value) +
""
);
}
@@ -2744,3 +2736,17 @@ function printClockDigital1(
setTimeout(tick, 1000 - (now % 1000));
})();
}
+
+function valueToBytes(value) {
+ var shorts = ["", "K", "M", "G", "T", "P", "E", "Z", "Y"];
+ var pos = 0;
+ while (value >= 1024) {
+ // As long as the number can be divided by divider.
+ pos++;
+ // Position in array starting with 0.
+ value = value / 1024;
+ }
+
+ // This will actually do the rounding and the decimals.
+ return value.toFixed(2) + shorts[pos] + "B";
+}