billing fixes and improvements

git-svn-id: http://www.observium.org/svn/observer/trunk@2764 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2011-12-07 13:52:46 +00:00
parent 810788fd84
commit d0cee15757
7 changed files with 67 additions and 71 deletions

View File

@@ -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');

View File

@@ -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);

View File

@@ -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");

View File

@@ -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("<h4>Quota Bill</h4>");
@@ -162,14 +156,12 @@ if (bill_permitted($bill_id))
$unit = "MB";
$total_data = round($total_data, 2);
echo("Billing Period from " . $fromtext . " to " . $totext . "
<br />Transferred ".formatStorage($total_data * 1000 * 1000)." of ".formatStorage($bill_data['bill_gb'] * 1000 * 1000 * 1000)." (".$percent."%)
<br />Average rate " . formatRates($rate_average * 1000));
<br />Transferred ".format_byes_billing($total_data)." of ".format_bytes_billing($bill_data['bill_quota'])." (".$percent."%)
<br />Average rate " . formatRates($rate_average));
$background = get_percentage_colours($percent);
$right_background = $background['right'];
$left_background = $background['left'];
echo("<p>".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $left_background, $percent . "%", "ffffff", $right_background)."</p>");
echo("<p>".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right'])."</p>");
$type="&amp;ave=yes";
}
@@ -180,7 +172,7 @@ if (bill_permitted($bill_id))
echo("<h4>CDR / 95th Bill</h4>");
$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="&amp;95th=yes";
echo("<strong>" . $fromtext . " to " . $totext . "</strong>
<br />Measured ".format_si($rate_95th)."bps of ".format_si($cdr)."bps (".$percent."%)");
<br />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("<p>".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $left_background, $percent . "%", "ffffff", $right_background)."</p>");
echo("<p>".print_percentage_bar (350, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right'])."</p>");
# echo("<p>Billing Period : " . $fromtext . " to " . $totext . "<br />
# " . $paidrate_text . " <br />
@@ -206,7 +193,6 @@ if (bill_permitted($bill_id))
# <font face=\"Trebuchet MS, Verdana, Arial, Sans-Serif\" color=" . $bill_color . "><B>" . $rate_95th . "Kbps @ 95th Percentile.</b> (" . $dir_95th . ") (" . $bill_text . ")</font>
# </td><td><img src=\"images/billing-key.png\"></td></tr></table>
# <br />");
}
$lastmonth = dbFetchCell("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))");

View File

@@ -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 .= "&amp;x=1190&amp;y=250";
$mi .= "$type'>";
echo("<h3>Billing View</h3>$bi");
#echo("<h3>Previous Bill View</h3>$li");
echo("<h3>24 Hour View</h3>$di");
echo("<h3>Monthly View</h3>$mi");
echo("<h3>Billing Period View</h3>$bi");
echo("<h3>Rolling 24 Hour View</h3>$di");
echo("<h3>Rolling Monthly View</h3>$mi");
?>

View File

@@ -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);
}

View File

@@ -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);
}
}