mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-31 16:23:50 +02:00
billing rewrite (disabling svn after)
git-svn-id: http://www.observium.org/svn/observer/trunk@2758 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
+56
-69
@@ -1,74 +1,63 @@
|
||||
<?php
|
||||
|
||||
function getDates($dayofmonth)
|
||||
function format_bytes_billing($value)
|
||||
{
|
||||
global $config;
|
||||
return format_number($value, $config['billing']['base'])."B";
|
||||
}
|
||||
|
||||
function format_bytes_billing_short($value)
|
||||
{
|
||||
global $config;
|
||||
return format_number($value, $config['billing']['base'], 1);
|
||||
}
|
||||
|
||||
|
||||
function getDates($dayofmonth, $months=0)
|
||||
{
|
||||
$dayofmonth = zeropad($dayofmonth);
|
||||
$year = date('Y');
|
||||
$month = date('m');
|
||||
|
||||
if (date('d') > $dayofmonth)
|
||||
$dayofmonth = "03";
|
||||
$year = date('Y');
|
||||
$month = date('m');
|
||||
|
||||
|
||||
if (date('d') > $dayofmonth) // Billing day is past, so it is next month
|
||||
{
|
||||
$newmonth = zeropad($month + 1);
|
||||
if ($newmonth == 13)
|
||||
{
|
||||
$newmonth = "01";
|
||||
$newyear = $year + 1;
|
||||
} else {
|
||||
$newyear = $year;
|
||||
}
|
||||
|
||||
$lastmonth = zeropad($month - 1);
|
||||
if ($lastmonth == 0)
|
||||
{
|
||||
$lastmonth = 12;
|
||||
$lastyear = $year - 1;
|
||||
} else {
|
||||
$lastyear = $year;
|
||||
}
|
||||
|
||||
$date_from = $year . $month . $dayofmonth;
|
||||
$date_to = $newyear . $newmonth . $dayofmonth;
|
||||
|
||||
$last_from = $lastyear . $lastmonth . $dayofmonth;
|
||||
$last_to = $year . $month . $dayofmonth;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$newmonth = zeropad($month - 1);
|
||||
if ($newmonth == 0)
|
||||
{
|
||||
$newmonth = 12;
|
||||
$newyear = $year - 1;
|
||||
} else {
|
||||
$newyear = $year;
|
||||
}
|
||||
|
||||
$lastmonth = zeropad($month - 2);
|
||||
if ($lastmonth == -1)
|
||||
{
|
||||
$lastmonth = 10;
|
||||
$lastyear = $year - 1;
|
||||
} elseif ($lastmonth == 0)
|
||||
{
|
||||
$lastmonth = 11;
|
||||
$lastyear = $year - 1;
|
||||
} else {
|
||||
$lastyear = $year;
|
||||
}
|
||||
|
||||
$date_from = $newyear . $newmonth . $dayofmonth;
|
||||
$date_to = $year . $month . $dayofmonth;
|
||||
|
||||
$last_from = $lastyear . $lastmonth . $dayofmonth;
|
||||
$last_to = $newyear . $newmonth . $dayofmonth;
|
||||
|
||||
$date_end = date_create($year.'-'.$month.'-'.$dayofmonth);
|
||||
$date_start = date_create($year.'-'.$month.'-'.$dayofmonth);
|
||||
date_add($date_end, date_interval_create_from_date_string('1 month'));
|
||||
} else { // Billing day will happen this month, therefore started last month
|
||||
$date_end = date_create($year.'-'.$month.'-'.$dayofmonth);
|
||||
$date_start = date_create($year.'-'.$month.'-'.$dayofmonth);
|
||||
date_sub($date_start, date_interval_create_from_date_string('1 month'));
|
||||
}
|
||||
|
||||
$return['0'] = $date_from . "000001";
|
||||
$return['1'] = $date_to . "000000";
|
||||
$return['2'] = $last_from . "000001";
|
||||
$return['3'] = $last_to . "000000";
|
||||
if($months > 0)
|
||||
{
|
||||
date_sub($date_start, date_interval_create_from_date_string($months.' month'));
|
||||
date_sub($date_end, date_interval_create_from_date_string($months.' month'));
|
||||
}
|
||||
|
||||
|
||||
# date_sub($date_start, date_interval_create_from_date_string('1 month'));
|
||||
date_sub($date_end, date_interval_create_from_date_string('1 day'));
|
||||
|
||||
$date_from = date_format($date_start, 'Ymd') . "000000";
|
||||
$date_to = date_format($date_end, 'Ymd') . "235959";
|
||||
|
||||
date_sub($date_start, date_interval_create_from_date_string('1 month'));
|
||||
date_sub($date_end, date_interval_create_from_date_string('1 month'));
|
||||
|
||||
$last_from = date_format($date_start, 'Ymd') . "000000";
|
||||
$last_to = date_format($date_end, 'Ymd') . "235959";
|
||||
|
||||
$return['0'] = $date_from;
|
||||
$return['1'] = $date_to;
|
||||
$return['2'] = $last_from;
|
||||
$return['3'] = $last_to;
|
||||
|
||||
return($return);
|
||||
}
|
||||
@@ -132,7 +121,7 @@ function get95thin($bill_id,$datefrom,$dateto)
|
||||
$measurements = dbFetchCell($mq_sql);
|
||||
$measurement_95th = round($measurements /100 * 95) - 1;
|
||||
|
||||
$q_95_sql = "SELECT (in_delta / period / 1000 * 8) AS rate FROM bill_data WHERE bill_id = '".mres($bill_id)."'";
|
||||
$q_95_sql = "SELECT (in_delta / period * 8) AS rate FROM bill_data WHERE bill_id = '".mres($bill_id)."'";
|
||||
$q_95_sql .= " AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."' ORDER BY in_delta ASC";
|
||||
$a_95th = dbFetchColumn($q_95_sql);
|
||||
$m_95th = $a_95th[$measurement_95th];
|
||||
@@ -147,7 +136,7 @@ function get95thout($bill_id,$datefrom,$dateto)
|
||||
$measurements = dbFetchCell($mq_sql);
|
||||
$measurement_95th = round($measurements /100 * 95) - 1;
|
||||
|
||||
$q_95_sql = "SELECT (out_delta / period / 1000 * 8) AS rate FROM bill_data WHERE bill_id = '".mres($bill_id)."'";
|
||||
$q_95_sql = "SELECT (out_delta / period * 8) AS rate FROM bill_data WHERE bill_id = '".mres($bill_id)."'";
|
||||
$q_95_sql .= " AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."' ORDER BY out_delta ASC";
|
||||
|
||||
$a_95th = dbFetchColumn($q_95_sql);
|
||||
@@ -171,11 +160,9 @@ function getRates($bill_id,$datefrom,$dateto)
|
||||
$m_95th = $a_95th[$measurement_95th];
|
||||
|
||||
$sum_data = getSum($bill_id,$datefrom,$dateto);
|
||||
# $mtot = getTotal($bill_id,$datefrom,$dateto);
|
||||
$mtot = $sum_data['total'];
|
||||
$mtot_in = $sum_data['inbound'];
|
||||
$mtot_out = $sum_data['outbound'];
|
||||
# $ptot = getPeriod($bill_id,$datefrom,$dateto);
|
||||
$ptot = $sum_data['period'];
|
||||
|
||||
$data['rate_95th_in'] = get95thIn($bill_id,$datefrom,$dateto);
|
||||
@@ -190,10 +177,10 @@ function getRates($bill_id,$datefrom,$dateto)
|
||||
$data['dir_95th'] = 'in';
|
||||
}
|
||||
|
||||
$data['total_data'] = round($mtot / 1000 / 1000, 2);
|
||||
$data['total_data_in'] = round($mtot_in / 1000 / 1000, 2);
|
||||
$data['total_data_out'] = round($mtot_out / 1000 / 1000, 2);
|
||||
$data['rate_average'] = round($mtot / $ptot / 1000 * 8, 2);
|
||||
$data['total_data'] = $mtot;
|
||||
$data['total_data_in'] = $mtot_in;
|
||||
$data['total_data_out'] = $mtot_out;
|
||||
$data['rate_average'] = $mtot / $ptot * 8;
|
||||
|
||||
# print_r($data);
|
||||
|
||||
|
||||
+10
-2
@@ -460,14 +460,12 @@ function format_si($rate, $round = 2)
|
||||
if ($rate >= "0.1")
|
||||
{
|
||||
$sizes = Array('', 'k', 'M', 'G', 'T', 'P', 'E');
|
||||
# $round = Array('2','2','2','2','2','2','2','2','2');
|
||||
$ext = $sizes[0];
|
||||
for ($i = 1; (($i < count($sizes)) && ($rate >= 1000)); $i++) { $rate = $rate / 1000; $ext = $sizes[$i]; }
|
||||
}
|
||||
else
|
||||
{
|
||||
$sizes = Array('', 'm', 'u', 'n');
|
||||
# $round = Array('2','2','2','2');
|
||||
$ext = $sizes[0];
|
||||
for ($i = 1; (($i < count($sizes)) && ($rate != 0) && ($rate <= 0.1)); $i++) { $rate = $rate * 1000; $ext = $sizes[$i]; }
|
||||
}
|
||||
@@ -485,6 +483,16 @@ function format_bi($size, $round = '2')
|
||||
return round($size, $round).$ext;
|
||||
}
|
||||
|
||||
function format_number($value, $base = '1000', $round=2)
|
||||
{
|
||||
if($base == '1000')
|
||||
{
|
||||
return format_si($value, $round);
|
||||
} else {
|
||||
return format_bi($value, $round);
|
||||
}
|
||||
}
|
||||
|
||||
function is_valid_hostname($hostname)
|
||||
{
|
||||
// The Internet standards (Request for Comments) for protocols mandate that
|
||||
|
||||
@@ -173,14 +173,14 @@ $config['enable_billing'] = 0; # Enable Billing
|
||||
$config['billing']['customer_autoadd'] = 0; # Enable Auto-add bill per customer
|
||||
$config['billing']['circuit_autoadd'] = 0; # Enable Auto-add bill per circuit_id
|
||||
$config['billing']['bill_autoadd'] = 0; # Enable Auto-add bill per bill_id
|
||||
$config['billing']['base'] = 1000; # Set the base to divider bytes to kb, mb, gb ,... (this only works for the text based conversion and not for the graphs)
|
||||
$config['billing']['base'] = 1000; # Set the base to divider bytes to kB, MB, GB ,... (1000|1024)
|
||||
|
||||
### External Integration
|
||||
|
||||
#$config['rancid_configs'][] = '/var/lib/rancid/network/configs/';
|
||||
$config['rancid_ignorecomments'] = 0; # Ignore lines starting with #
|
||||
#$config['collectd_dir'] = '/var/lib/collectd/rrd';
|
||||
#$config['smokeping']['dir'] = "/var/lib/smokeping/";
|
||||
#$config['smokeping']['dir'] = "/var/lib/smokeping/";
|
||||
|
||||
# NFSen RRD dir.
|
||||
$config['nfsen_enable'] = 0;
|
||||
|
||||
Reference in New Issue
Block a user