|
|
|
@@ -1,19 +1,17 @@
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use LibreNMS\Config;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function format_bytes_billing($value)
|
|
|
|
|
{
|
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
|
|
return format_number($value, $config['billing']['base']).'B';
|
|
|
|
|
return format_number($value, Config::get('billing.base')).'B';
|
|
|
|
|
}//end format_bytes_billing()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function format_bytes_billing_short($value)
|
|
|
|
|
{
|
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
|
|
return format_number($value, $config['billing']['base'], 2, 3);
|
|
|
|
|
return format_number($value, Config::get('billing.base'), 2, 3);
|
|
|
|
|
}//end format_bytes_billing_short()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -75,10 +73,8 @@ function getPredictedUsage($bill_day, $cur_used)
|
|
|
|
|
|
|
|
|
|
function getValue($host, $port, $id, $inout)
|
|
|
|
|
{
|
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
|
|
$oid = 'IF-MIB::ifHC'.$inout.'Octets.'.$id;
|
|
|
|
|
$device = dbFetchRow("SELECT * from `devices` WHERE `hostname` = '".mres($host)."' LIMIT 1");
|
|
|
|
|
$device = dbFetchRow("SELECT * from `devices` WHERE `hostname` = ? LIMIT 1", array($host));
|
|
|
|
|
$value = snmp_get($device, $oid, '-Oqv');
|
|
|
|
|
|
|
|
|
|
if (!is_numeric($value)) {
|
|
|
|
@@ -123,41 +119,55 @@ function getLastMeasurement($bill_id)
|
|
|
|
|
return ($return);
|
|
|
|
|
}//end getLastMeasurement()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function get95thin($bill_id, $datefrom, $dateto)
|
|
|
|
|
function get95thagg($bill_id, $datefrom, $dateto)
|
|
|
|
|
{
|
|
|
|
|
$mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = '".mres($bill_id)."'";
|
|
|
|
|
$mq_sql .= " AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'";
|
|
|
|
|
$measurements = dbFetchCell($mq_sql);
|
|
|
|
|
$mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = ?";
|
|
|
|
|
$mq_sql .= " AND timestamp > ? AND timestamp <= ?";
|
|
|
|
|
$measurements = dbFetchCell($mq_sql, array($bill_id, $datefrom, $dateto));
|
|
|
|
|
$measurement_95th = (round(($measurements / 100 * 95)) - 1);
|
|
|
|
|
|
|
|
|
|
$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 rate ASC";
|
|
|
|
|
$a_95th = dbFetchColumn($q_95_sql);
|
|
|
|
|
$q_95_sql = "SELECT (delta / period * 8) AS rate FROM bill_data WHERE bill_id = ?";
|
|
|
|
|
$q_95_sql .= " AND timestamp > ? AND timestamp <= ? ORDER BY rate ASC";
|
|
|
|
|
$a_95th = dbFetchColumn($q_95_sql, array($bill_id, $datefrom, $dateto));
|
|
|
|
|
$m_95th = $a_95th[$measurement_95th];
|
|
|
|
|
|
|
|
|
|
return (round($m_95th, 2));
|
|
|
|
|
}//end get95thin()
|
|
|
|
|
}//end get95thagg()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function get95thIn($bill_id, $datefrom, $dateto)
|
|
|
|
|
{
|
|
|
|
|
$mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = ?";
|
|
|
|
|
$mq_sql .= " AND timestamp > ? AND timestamp <= ?";
|
|
|
|
|
$measurements = dbFetchCell($mq_sql, array($bill_id, $datefrom, $dateto));
|
|
|
|
|
$measurement_95th = (round(($measurements / 100 * 95)) - 1);
|
|
|
|
|
|
|
|
|
|
$q_95_sql = "SELECT (in_delta / period * 8) AS rate FROM bill_data WHERE bill_id = ?";
|
|
|
|
|
$q_95_sql .= " AND timestamp > ? AND timestamp <= ? ORDER BY rate ASC";
|
|
|
|
|
$a_95th = dbFetchColumn($q_95_sql, array($bill_id, $datefrom, $dateto));
|
|
|
|
|
$m_95th = $a_95th[$measurement_95th];
|
|
|
|
|
|
|
|
|
|
return (round($m_95th, 2));
|
|
|
|
|
}//end get95thIn()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function get95thout($bill_id, $datefrom, $dateto)
|
|
|
|
|
{
|
|
|
|
|
$mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = '".mres($bill_id)."'";
|
|
|
|
|
$mq_sql .= " AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'";
|
|
|
|
|
$measurements = dbFetchCell($mq_sql);
|
|
|
|
|
$mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = ?";
|
|
|
|
|
$mq_sql .= " AND timestamp > ? AND timestamp <= ?";
|
|
|
|
|
$measurements = dbFetchCell($mq_sql, array($bill_id, $datefrom, $dateto));
|
|
|
|
|
$measurement_95th = (round(($measurements / 100 * 95)) - 1);
|
|
|
|
|
|
|
|
|
|
$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 rate ASC";
|
|
|
|
|
|
|
|
|
|
$a_95th = dbFetchColumn($q_95_sql);
|
|
|
|
|
$m_95th = $a_95th[$measurement_95th];
|
|
|
|
|
$q_95_sql = "SELECT (out_delta / period * 8) AS rate FROM bill_data WHERE bill_id = ?";
|
|
|
|
|
$q_95_sql .= " AND timestamp > ? AND timestamp <= ? ORDER BY rate ASC";
|
|
|
|
|
$a_95th = dbFetchColumn($q_95_sql, array($bill_id, $datefrom, $dateto));
|
|
|
|
|
$m_95th = $a_95th[$measurement_95th];
|
|
|
|
|
|
|
|
|
|
return (round($m_95th, 2));
|
|
|
|
|
}//end get95thout()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getRates($bill_id, $datefrom, $dateto)
|
|
|
|
|
function getRates($bill_id, $datefrom, $dateto, $dir_95th)
|
|
|
|
|
{
|
|
|
|
|
$data = [];
|
|
|
|
|
|
|
|
|
@@ -168,14 +178,19 @@ function getRates($bill_id, $datefrom, $dateto)
|
|
|
|
|
$ptot = $sum_data['period'];
|
|
|
|
|
|
|
|
|
|
$data['rate_95th_in'] = get95thIn($bill_id, $datefrom, $dateto);
|
|
|
|
|
$data['rate_95th_out'] = get95thOut($bill_id, $datefrom, $dateto);
|
|
|
|
|
$data['rate_95th_out'] = get95thout($bill_id, $datefrom, $dateto);
|
|
|
|
|
|
|
|
|
|
if ($data['rate_95th_out'] > $data['rate_95th_in']) {
|
|
|
|
|
$data['rate_95th'] = $data['rate_95th_out'];
|
|
|
|
|
$data['dir_95th'] = 'out';
|
|
|
|
|
if ($dir_95th == 'agg') {
|
|
|
|
|
$data['rate_95th'] = get95thagg($bill_id, $datefrom, $dateto);
|
|
|
|
|
$data['dir_95th'] = 'agg';
|
|
|
|
|
} else {
|
|
|
|
|
$data['rate_95th'] = $data['rate_95th_in'];
|
|
|
|
|
$data['dir_95th'] = 'in';
|
|
|
|
|
if ($data['rate_95th_out'] > $data['rate_95th_in']) {
|
|
|
|
|
$data['rate_95th'] = $data['rate_95th_out'];
|
|
|
|
|
$data['dir_95th'] = 'out';
|
|
|
|
|
} else {
|
|
|
|
|
$data['rate_95th'] = $data['rate_95th_in'];
|
|
|
|
|
$data['dir_95th'] = 'in';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data['total_data'] = $mtot;
|
|
|
|
@@ -192,21 +207,21 @@ function getRates($bill_id, $datefrom, $dateto)
|
|
|
|
|
|
|
|
|
|
function getTotal($bill_id, $datefrom, $dateto)
|
|
|
|
|
{
|
|
|
|
|
$mtot = dbFetchCell("SELECT SUM(delta) FROM bill_data WHERE bill_id = '".mres($bill_id)."' AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'");
|
|
|
|
|
$mtot = dbFetchCell("SELECT SUM(delta) FROM bill_data WHERE bill_id = ? AND timestamp > ? AND timestamp <= ?", array($bill_id, $datefrom, $dateto));
|
|
|
|
|
return ($mtot);
|
|
|
|
|
}//end getTotal()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getSum($bill_id, $datefrom, $dateto)
|
|
|
|
|
{
|
|
|
|
|
$sum = dbFetchRow("SELECT SUM(period) as period, SUM(delta) as total, SUM(in_delta) as inbound, SUM(out_delta) as outbound FROM bill_data WHERE bill_id = '".mres($bill_id)."' AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'");
|
|
|
|
|
$sum = dbFetchRow("SELECT SUM(period) as period, SUM(delta) as total, SUM(in_delta) as inbound, SUM(out_delta) as outbound FROM bill_data WHERE bill_id = ? AND timestamp > ? AND timestamp <= ?", array($bill_id, $datefrom, $dateto));
|
|
|
|
|
return ($sum);
|
|
|
|
|
}//end getSum()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getPeriod($bill_id, $datefrom, $dateto)
|
|
|
|
|
{
|
|
|
|
|
$ptot = dbFetchCell("SELECT SUM(period) FROM bill_data WHERE bill_id = '".mres($bill_id)."' AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'");
|
|
|
|
|
$ptot = dbFetchCell("SELECT SUM(period) FROM bill_data WHERE bill_id = ? AND timestamp > ? AND timestamp <= ?", array($bill_id, $datefrom, $dateto));
|
|
|
|
|
return ($ptot);
|
|
|
|
|
}//end getPeriod()
|
|
|
|
|
|
|
|
|
|