diff --git a/html/bandwidth-graph.php b/html/bandwidth-graph.php index 2ee7d734ef..dd90c69c72 100644 --- a/html/bandwidth-graph.php +++ b/html/bandwidth-graph.php @@ -147,9 +147,6 @@ $ave_count = count($tot_data); } $decimal = 0; -# $in_data = formatScale($in_data, $max, $decimal); -# $out_data = formatScale($out_data, $max, $decimal); -# $tot_data = formatScale($tot_data, $max, $decimal); $average = $average / $ave_count; for ($x=0;$x<=count($tot_data);$x++) { array_push($ave_data, $average); @@ -161,8 +158,11 @@ // Create the graph. These two calls are always required $graph = new Graph($xsize, $ysize, $graph_name); $graph->img->SetImgFormat("png"); + +# $graph->SetScale("textlin",0,0,$start,$end); + $graph->SetScale("textlin"); - $graph->title->Set("$graph_name"); + #$graph->title->Set("$graph_name"); $graph->title->SetFont(FF_FONT2, FS_BOLD, 10); $graph->SetMarginColor("white"); $graph->SetFrame(false); @@ -189,8 +189,8 @@ // Create the bar plots $barplot_tot = new BarPlot($tot_data); $barplot_tot->SetLegend("Traffic total"); - $barplot_tot->SetColor("#d5d5d5"); - $barplot_tot->SetFillColor("#d5d5d5@0.5"); + $barplot_tot->SetColor("darkred"); + $barplot_tot->SetFillColor("lightred@0.4"); $barplot_tot->value->Show(); $barplot_tot->value->SetFormatCallback('format_bytes_billing_short'); diff --git a/html/billing-graph.php b/html/billing-graph.php index 4e587fb8d3..83579a9cf2 100755 --- a/html/billing-graph.php +++ b/html/billing-graph.php @@ -138,7 +138,7 @@ $graph->img->SetImgFormat("png"); $graph->SetScale('datlin',0,0,$start,$end); -$graph->title->Set("$graph_name"); +#$graph->title->Set("$graph_name"); $graph->title->SetFont(FF_FONT2,FS_BOLD,10); $graph->xaxis->SetFont(FF_FONT1,FS_BOLD); diff --git a/html/includes/graphs/bill/bits.inc.php b/html/includes/graphs/bill/bits.inc.php index 10b000d131..16cd814a9a 100644 --- a/html/includes/graphs/bill/bits.inc.php +++ b/html/includes/graphs/bill/bits.inc.php @@ -28,12 +28,12 @@ $ds_out = "OUTOCTETS"; if($bill['bill_type'] == "cdr") { $custom_graph = " COMMENT:'\\r' "; - $custom_graph .= " HRULE:" . $rates['rate_95th'] * 1000 . "#cc0000:'95th %ile \: ".formatRates($rates['rate_95th']*1000)." (".$rates['dir_95th'].") (CDR\: ".formatRates($bill['bill_cdr']*1000).")'"; - $custom_graph .= " HRULE:" . $rates['rate_95th'] * 1000 * -1 . "#cc0000"; + $custom_graph .= " HRULE:" . $rates['rate_95th'] . "#cc0000:'95th %ile \: ".formatRates($rates['rate_95th'])." (".$rates['dir_95th'].") (CDR\: ".formatRates($bill['bill_cdr']).")'"; + $custom_graph .= " HRULE:" . $rates['rate_95th'] * -1 . "#cc0000"; } elseif($bill['bill_type'] == "quota") { $custom_graph = " COMMENT:'\\r' "; - $custom_graph .= " HRULE:" . $rates['rate_average'] * 1000 . "#cc0000:'Usage \: ".formatStorage($rates['total_data']*1024*1024)." (".formatRates($rates['rate_average']*1000).")'"; - $custom_graph .= " HRULE:" . $rates['rate_average'] * 1000 * -1 . "#cc0000"; + $custom_graph .= " HRULE:" . $rates['rate_average'] . "#cc0000:'Usage \: ".format_bytes_billing($rates['total_data'])." (".formatRates($rates['rate_average']).")'"; + $custom_graph .= " HRULE:" . $rates['rate_average'] * -1 . "#cc0000"; } include("includes/graphs/generic_multi_bits_separated.inc.php"); diff --git a/html/pages/bill.inc.php b/html/pages/bill.inc.php index df284c1d0c..3d90330918 100644 --- a/html/pages/bill.inc.php +++ b/html/pages/bill.inc.php @@ -24,12 +24,6 @@ if (bill_permitted($bill_id)) $bill_name = $bill_data['bill_name']; $dayofmonth = $bill_data['bill_day']; - $paidrate = $bill_data['bill_paid_rate']; - $paid_kb = $paidrate / 1000; - $paid_mb = $paid_kb / 1000; - - if ($paidrate < 1000000) { $paidrate_text = $paid_kb . "Kbps is the CDR."; } - if ($paidrate >= 1000000) { $paidrate_text = $paid_mb . "Mbps is the CDR."; } $day_data = getDates($dayofmonth); @@ -154,7 +148,7 @@ if (bill_permitted($bill_id)) if ($bill_data['bill_type'] == "quota") { - // The Customer is billed based on a pre-paid quota + // The Customer is billed based on a pre-paid quota with overage in xB echo("

Quota Bill

"); @@ -162,14 +156,12 @@ if (bill_permitted($bill_id)) $unit = "MB"; $total_data = round($total_data, 2); echo("Billing Period from " . $fromtext . " to " . $totext . " -
Transferred ".formatStorage($total_data * 1000 * 1000)." of ".formatStorage($bill_data['bill_gb'] * 1000 * 1000 * 1000)." (".$percent."%) -
Average rate " . formatRates($rate_average * 1000)); +
Transferred ".format_byes_billing($total_data)." of ".format_bytes_billing($bill_data['bill_quota'])." (".$percent."%) +
Average rate " . formatRates($rate_average)); $background = get_percentage_colours($percent); - $right_background = $background['right']; - $left_background = $background['left']; - echo("

".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $left_background, $percent . "%", "ffffff", $right_background)."

"); + echo("

".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right'])."

"); $type="&ave=yes"; } @@ -180,7 +172,7 @@ if (bill_permitted($bill_id)) echo("

CDR / 95th Bill

"); $unit = "kbps"; - $cdr = $bill_data['bill_cdr'] *1000; + $cdr = $bill_data['bill_cdr']; $rate_95th = round($rate_95th, 2); $percent = round(($rate_95th) / $cdr * 100, 2); @@ -188,16 +180,11 @@ if (bill_permitted($bill_id)) $type="&95th=yes"; echo("" . $fromtext . " to " . $totext . " -
Measured ".format_si($rate_95th)."bps of ".format_si($cdr)."bps (".$percent."%)"); +
Measured ".format_si($rate_95th)."bps of ".format_si($cdr)."bps (".$percent."%) @ 95th %ile"); - if ($percent > 100) { $perc = "100"; } else { $perc = $percent; } - if ($perc > '90') { $left_background='c4323f'; $right_background='C96A73'; - } elseif ($perc > '75') { $left_background='bf5d5b'; $right_background='d39392'; - } elseif ($perc > '50') { $left_background='bf875b'; $right_background='d3ae92'; - } elseif ($perc > '25') { $left_background='5b93bf'; $right_background='92b7d3'; - } else { $left_background='9abf5b'; $right_background='bbd392'; } + $background = get_percentage_colours($percent); - echo("

".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $left_background, $percent . "%", "ffffff", $right_background)."

"); + echo("

".print_percentage_bar (350, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right'])."

"); # echo("

Billing Period : " . $fromtext . " to " . $totext . "
# " . $paidrate_text . "
@@ -206,7 +193,6 @@ if (bill_permitted($bill_id)) # " . $rate_95th . "Kbps @ 95th Percentile. (" . $dir_95th . ") (" . $bill_text . ") # #
"); - } $lastmonth = dbFetchCell("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))"); diff --git a/html/pages/bill/transfer.inc.php b/html/pages/bill/transfer.inc.php index 22ddcc18e2..59af48f049 100644 --- a/html/pages/bill/transfer.inc.php +++ b/html/pages/bill/transfer.inc.php @@ -63,7 +63,7 @@ $in['per'] = round(($bill_data['total_data_in'] / $bill_data['total_data'] * 100), 2); $in['bg'] = get_percentage_colours($in['per']); - $out['data'] = format_number($bill_data['total_data_out'] , $config['billing']['base']); + $out['data'] = format_bytes_billing($bill_data['total_data_out']); $out['allow'] = $total['allow']; $out['ave'] = format_bytes_billing($bill_data['total_data_out'] / $cur_days); $out['est'] = format_bytes_billing($bill_data['total_data_out'] / $cur_days * $total_days); @@ -84,7 +84,7 @@ $background = get_percentage_colours($per); $right_background = $background['right']; $left_background = $background['left']; - $res = print_percentage_bar(350, 20, $perc, NULL, "ffffff", $left_background, $per."%", "ffffff", $right_background); + $res = print_percentage_bar(350, 20, $per, NULL, "ffffff", $left_background, $per."%", "ffffff", $right_background); return $res; } @@ -165,9 +165,8 @@ $mi .= "&x=1190&y=250"; $mi .= "$type'>"; - echo("

Billing View

$bi"); - #echo("

Previous Bill View

$li"); - echo("

24 Hour View

$di"); - echo("

Monthly View

$mi"); + echo("

Billing Period View

$bi"); + echo("

Rolling 24 Hour View

$di"); + echo("

Rolling Monthly View

$mi"); ?> diff --git a/includes/billing.php b/includes/billing.php index 06b26dd67e..9d6dc7fcdf 100644 --- a/includes/billing.php +++ b/includes/billing.php @@ -9,7 +9,7 @@ function format_bytes_billing($value) function format_bytes_billing_short($value) { global $config; - return format_number($value, $config['billing']['base'], 1); + return format_number($value, $config['billing']['base'], 2, 3); } diff --git a/includes/common.php b/includes/common.php index fb4edb4981..42460a7a22 100644 --- a/includes/common.php +++ b/includes/common.php @@ -2,6 +2,23 @@ ## Common Functions +function format_number_short($number, $sf) +{ + // This formats a number so that we only send back three digits plus an optional decimal point. + // Example: 723.42 -> 723 72.34 -> 72.3 2.23 -> 2.23 + + list($whole, $decimal) = explode (".", $number); + + if(strlen($whole) >= $sf || !is_numeric($decimal)) + { + $number = $whole; + } elseif(strlen($whole) < $sf) { + $diff = $sf - strlen($whole); + $number = $whole .".".substr($decimal, 0, $diff); + } + return $number; +} + function external_exec($command) { global $debug; @@ -126,10 +143,10 @@ function get_port_by_ifIndex($device_id, $ifIndex) function get_all_devices($device, $type = "") { global $cache; - + # FIXME needs access control checks! # FIXME respect $type (server, network, etc) -- needs an array fill in topnav. - + if (isset($cache['devices']['hostname'])) { $devices = array_keys($cache['devices']['hostname']); @@ -165,7 +182,6 @@ function get_port_by_id($port_id) { $port = dbFetchRow("SELECT * FROM `ports` WHERE `interface_id` = ?", array($port_id)); } - if (is_array($port)) { return $port; @@ -180,7 +196,6 @@ function get_application_by_id($application_id) { $application = dbFetchRow("SELECT * FROM `applications` WHERE `app_id` = ?", array($application_id)); } - if (is_array($application)) { return $application; @@ -195,7 +210,6 @@ function get_sensor_by_id($sensor_id) { $sensor = dbFetchRow("SELECT * FROM `sensors` WHERE `sensor_id` = ?", array($sensor_id)); } - if (is_array($sensor)) { return $sensor; @@ -210,7 +224,6 @@ function get_device_id_by_interface_id($interface_id) { $device_id = dbFetchCell("SELECT `device_id` FROM `ports` WHERE `interface_id` = ?", array($interface_id)); } - if (is_numeric($device_id)) { return $device_id; @@ -225,7 +238,6 @@ function get_device_id_by_app_id($app_id) { $device_id = dbFetchCell("SELECT `device_id` FROM `applications` WHERE `app_id` = ?", array($app_id)); } - if (is_numeric($device_id)) { return $device_id; @@ -237,11 +249,9 @@ function get_device_id_by_app_id($app_id) function ifclass($ifOperStatus, $ifAdminStatus) { $ifclass = "interface-upup"; - if ($ifAdminStatus == "down") { $ifclass = "interface-admindown"; } if ($ifAdminStatus == "up" && $ifOperStatus== "down") { $ifclass = "interface-updown"; } if ($ifAdminStatus == "up" && $ifOperStatus== "up") { $ifclass = "interface-upup"; } - return $ifclass; } @@ -266,7 +276,6 @@ function device_by_id_cache($device_id, $refresh = '0') } $cache['devices']['id'][$device_id] = $device; } - return $device; } @@ -358,13 +367,13 @@ function getidbyname($hostname) function gethostosbyid($id) { global $cache; - + if (isset($cache['devices']['id'][$id]['os'])) { $os = $cache['devices']['id'][$id]['os']; } else - { + { $os = dbFetchCell("SELECT `os` FROM `devices` WHERE `device_id` = ?", array($id)); } @@ -437,45 +446,45 @@ function del_dev_attrib($device, $attrib_type) return dbDelete('devices_attribs', "`device_id` = ? AND `attrib_type` = ?", array($device['device_id'], $attrib_type)); } -function formatRates($rate) +function formatRates($value, $round = '2', $sf = '3') { - $rate = format_si($rate) . "bps"; - return $rate; + $value = format_si($value, $round, $sf) . "bps"; + return $value; } -function formatStorage($rate, $round = '2') +function formatStorage($value, $round = '2', $sf = '3') { - $rate = format_bi($rate, $round) . "B"; - return $rate; + $value = format_bi($value, $round) . "B"; + return $value; } -function format_si($rate, $round = 2) +function format_si($value, $round = '2', $sf = '3') { - if($rate < "0") + if($value < "0") { $neg = 1; - $rate = $rate * -1; + $value = $value * -1; } - if ($rate >= "0.1") + if ($value >= "0.1") { $sizes = Array('', 'k', 'M', 'G', 'T', 'P', 'E'); $ext = $sizes[0]; - for ($i = 1; (($i < count($sizes)) && ($rate >= 1000)); $i++) { $rate = $rate / 1000; $ext = $sizes[$i]; } + for ($i = 1; (($i < count($sizes)) && ($value >= 1000)); $i++) { $value = $value / 1000; $ext = $sizes[$i]; } } else { $sizes = Array('', 'm', 'u', 'n'); $ext = $sizes[0]; - for ($i = 1; (($i < count($sizes)) && ($rate != 0) && ($rate <= 0.1)); $i++) { $rate = $rate * 1000; $ext = $sizes[$i]; } + for ($i = 1; (($i < count($sizes)) && ($value != 0) && ($value <= 0.1)); $i++) { $value = $value * 1000; $ext = $sizes[$i]; } } - if($neg) { $rate = $rate * -1; } + if($neg) { $value = $value * -1; } - return round($rate, $round).$ext; + return format_number_short(round($value, $round),$sf).$ext; } -function format_bi($value, $round = '2') +function format_bi($value, $round = '2', $sf = '3') { if($value < "0") { @@ -485,17 +494,19 @@ function format_bi($value, $round = '2') $sizes = Array('', 'k', 'M', 'G', 'T', 'P', 'E'); $ext = $sizes[0]; for ($i = 1; (($i < count($sizes)) && ($value >= 1024)); $i++) { $value = $value / 1024; $ext = $sizes[$i]; } + if($neg) { $value = $value * -1; } - return round($value, $round).$ext; + + return format_number_short(round($value, $round), $sf).$ext; } -function format_number($value, $base = '1000', $round=2) +function format_number($value, $base = '1000', $round=2, $sf=3) { if($base == '1000') { - return format_si($value, $round); + return format_si($value, $round, $sf); } else { - return format_bi($value, $round); + return format_bi($value, $round, $sf); } }