Percentage calculation helper (#14235)
* Percentage calculation helper Helper function to prevent divide by zero mistakes Replace all percent calculations * style
This commit is contained in:
parent
1dbab5ac7e
commit
34163703fb
|
@ -26,6 +26,7 @@
|
|||
namespace LibreNMS\Device;
|
||||
|
||||
use App\Models\DeviceOutage;
|
||||
use LibreNMS\Util\Number;
|
||||
|
||||
class Availability
|
||||
{
|
||||
|
@ -126,6 +127,6 @@ class Availability
|
|||
|
||||
$outage_summary = self::outageSummary($found_outages, $duration, $now);
|
||||
|
||||
return round(100 * ($duration - $outage_summary) / $duration, $precision);
|
||||
return Number::calculatePercent($duration - $outage_summary, $duration, $precision);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ use LibreNMS\Enum\Alert;
|
|||
use LibreNMS\Interfaces\Module;
|
||||
use LibreNMS\OS;
|
||||
use LibreNMS\RRD\RrdDefinition;
|
||||
use LibreNMS\Util\Number;
|
||||
use Log;
|
||||
|
||||
class PrinterSupplies implements Module
|
||||
|
@ -276,7 +277,7 @@ class PrinterSupplies implements Module
|
|||
}
|
||||
}
|
||||
|
||||
return round($raw_value / $capacity * 100);
|
||||
return Number::calculatePercent($raw_value, $capacity, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,6 +34,7 @@ use LibreNMS\Interfaces\Discovery\Sensors\WirelessSnrDiscovery;
|
|||
use LibreNMS\Interfaces\Polling\OSPolling;
|
||||
use LibreNMS\OS;
|
||||
use LibreNMS\RRD\RrdDefinition;
|
||||
use LibreNMS\Util\Number;
|
||||
|
||||
class Epmp extends OS implements
|
||||
OSPolling,
|
||||
|
@ -121,8 +122,8 @@ class Epmp extends OS implements
|
|||
$dlWLanTotalUsedFrameTimePerSecond = $multi_get_array[0]['CAMBIUM-PMP80211-MIB::dlWLanTotalUsedFrameTimePerSecond'] ?? null;
|
||||
|
||||
if (is_numeric($ulWLanTotalAvailableFrameTimePerSecond) && is_numeric($ulWLanTotalUsedFrameTimePerSecond) && $ulWLanTotalAvailableFrameTimePerSecond && $ulWLanTotalUsedFrameTimePerSecond) {
|
||||
$ulWlanFrameUtilization = round(($ulWLanTotalUsedFrameTimePerSecond / $ulWLanTotalAvailableFrameTimePerSecond) * 100, 2);
|
||||
$dlWlanFrameUtilization = round(($dlWLanTotalUsedFrameTimePerSecond / $dlWLanTotalAvailableFrameTimePerSecond) * 100, 2);
|
||||
$ulWlanFrameUtilization = Number::calculatePercent($ulWLanTotalUsedFrameTimePerSecond, $ulWLanTotalAvailableFrameTimePerSecond);
|
||||
$dlWlanFrameUtilization = Number::calculatePercent($dlWLanTotalUsedFrameTimePerSecond, $dlWLanTotalAvailableFrameTimePerSecond);
|
||||
d_echo($dlWlanFrameUtilization);
|
||||
d_echo($ulWlanFrameUtilization);
|
||||
$rrd_def = RrdDefinition::make()
|
||||
|
|
|
@ -108,4 +108,21 @@ class Number
|
|||
|
||||
return $float == $int ? $int : $float;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate a percent, but make sure to not divide by zero. In that case, return 0.
|
||||
*
|
||||
* @param int|float $part
|
||||
* @param int|float $total
|
||||
* @param int $precision
|
||||
* @return float
|
||||
*/
|
||||
public static function calculatePercent($part, $total, int $precision = 2): float
|
||||
{
|
||||
if ($total == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return round($part / $total * 100, $precision);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_id`') as $bill) {
|
|||
$used_text = Number::formatSi($used, 2, 3, 'bps');
|
||||
$overuse = ($used - $allowed);
|
||||
$overuse = (($overuse <= 0) ? '0' : $overuse);
|
||||
$percent = round((($rate_data['rate_95th'] / $bill['bill_cdr']) * 100), 2);
|
||||
$percent = Number::calculatePercent($rate_data['rate_95th'], $bill['bill_cdr']);
|
||||
} elseif ($bill['bill_type'] == 'quota') {
|
||||
$type = 'Quota';
|
||||
$allowed = $bill['bill_quota'];
|
||||
|
@ -66,7 +66,7 @@ foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_id`') as $bill) {
|
|||
$used_text = format_bytes_billing($used);
|
||||
$overuse = ($used - $allowed);
|
||||
$overuse = (($overuse <= 0) ? '0' : $overuse);
|
||||
$percent = round((($rate_data['total_data'] / $bill['bill_quota']) * 100), 2);
|
||||
$percent = Number::calculatePercent($rate_data['total_data'], $bill['bill_quota']);
|
||||
}
|
||||
|
||||
echo strftime('%x @ %X', strtotime($datefrom)) . ' to ' . strftime('%x @ %X', strtotime($dateto)) . ' ' . str_pad($type, 8) . ' ' . str_pad($allowed_text, 10) . ' ' . str_pad($used_text, 10) . ' ' . $percent . '%';
|
||||
|
|
|
@ -37,6 +37,7 @@ use LibreNMS\Data\Store\Datastore;
|
|||
use LibreNMS\Exceptions\InvalidIpException;
|
||||
use LibreNMS\Util\IP;
|
||||
use LibreNMS\Util\IPv4;
|
||||
use LibreNMS\Util\Number;
|
||||
use LibreNMS\Util\Rewrite;
|
||||
|
||||
function api_success($result, $result_name, $message = null, $code = 200, $count = null, $extra = null)
|
||||
|
@ -191,12 +192,12 @@ function get_port_stats_by_port_hostname(Illuminate\Http\Request $request)
|
|||
return check_port_permission($port['port_id'], $device_id, function () use ($request, $port) {
|
||||
$in_rate = $port['ifInOctets_rate'] * 8;
|
||||
$out_rate = $port['ifOutOctets_rate'] * 8;
|
||||
$port['in_rate'] = \LibreNMS\Util\Number::formatSi($in_rate, 2, 3, 'bps');
|
||||
$port['out_rate'] = \LibreNMS\Util\Number::formatSi($out_rate, 2, 3, 'bps');
|
||||
$port['in_rate'] = Number::formatSi($in_rate, 2, 3, 'bps');
|
||||
$port['out_rate'] = Number::formatSi($out_rate, 2, 3, 'bps');
|
||||
$port['in_perc'] = number_format($in_rate / $port['ifSpeed'] * 100, 2, '.', '');
|
||||
$port['out_perc'] = number_format($out_rate / $port['ifSpeed'] * 100, 2, '.', '');
|
||||
$port['in_pps'] = \LibreNMS\Util\Number::formatBi($port['ifInUcastPkts_rate'], 2, 3, '');
|
||||
$port['out_pps'] = \LibreNMS\Util\Number::formatBi($port['ifOutUcastPkts_rate'], 2, 3, '');
|
||||
$port['in_pps'] = Number::formatBi($port['ifInUcastPkts_rate'], 2, 3, '');
|
||||
$port['out_pps'] = Number::formatBi($port['ifOutUcastPkts_rate'], 2, 3, '');
|
||||
|
||||
//only return requested columns
|
||||
if ($request->has('columns')) {
|
||||
|
@ -1583,20 +1584,20 @@ function list_bills(Illuminate\Http\Request $request)
|
|||
$overuse = '';
|
||||
|
||||
if (strtolower($bill['bill_type']) == 'cdr') {
|
||||
$allowed = \LibreNMS\Util\Number::formatSi($bill['bill_cdr'], 2, 3, '') . 'bps';
|
||||
$used = \LibreNMS\Util\Number::formatSi($rate_data['rate_95th'], 2, 3, '') . 'bps';
|
||||
$allowed = Number::formatSi($bill['bill_cdr'], 2, 3, '') . 'bps';
|
||||
$used = Number::formatSi($rate_data['rate_95th'], 2, 3, '') . 'bps';
|
||||
if ($bill['bill_cdr'] > 0) {
|
||||
$percent = round(($rate_data['rate_95th'] / $bill['bill_cdr']) * 100, 2);
|
||||
$percent = Number::calculatePercent($rate_data['rate_95th'], $bill['bill_cdr']);
|
||||
} else {
|
||||
$percent = '-';
|
||||
}
|
||||
$overuse = $rate_data['rate_95th'] - $bill['bill_cdr'];
|
||||
$overuse = (($overuse <= 0) ? '-' : \LibreNMS\Util\Number::formatSi($overuse, 2, 3, ''));
|
||||
$overuse = (($overuse <= 0) ? '-' : Number::formatSi($overuse, 2, 3, ''));
|
||||
} elseif (strtolower($bill['bill_type']) == 'quota') {
|
||||
$allowed = format_bytes_billing($bill['bill_quota']);
|
||||
$used = format_bytes_billing($rate_data['total_data']);
|
||||
if ($bill['bill_quota'] > 0) {
|
||||
$percent = round(($rate_data['total_data'] / ($bill['bill_quota'])) * 100, 2);
|
||||
$percent = Number::calculatePercent($rate_data['total_data'], $bill['bill_quota']);
|
||||
} else {
|
||||
$percent = '-';
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use LibreNMS\Util\Number;
|
||||
|
||||
$bill_id = $vars['bill_id'];
|
||||
|
||||
if (Auth::user()->hasGlobalAdmin()) {
|
||||
|
@ -158,14 +160,14 @@ if (bill_permitted($bill_id)) {
|
|||
<tr>
|
||||
<?php if ($bill_data['bill_type'] == 'quota') {
|
||||
// The Customer is billed based on a pre-paid quota with overage in xB
|
||||
$percent = round((($total_data) / $bill_data['bill_quota'] * 100), 2);
|
||||
$percent = Number::calculatePercent($total_data, $bill_data['bill_quota']);
|
||||
$unit = 'MB';
|
||||
$total_data = round($total_data, 2);
|
||||
$background = \LibreNMS\Util\Color::percentage($percent, null);
|
||||
$type = '&ave=yes'; ?>
|
||||
<td>
|
||||
<?php echo format_bytes_billing($total_data) ?> of <?php echo format_bytes_billing($bill_data['bill_quota']) . ' (' . $percent . '%)' ?>
|
||||
- Average rate <?php echo \LibreNMS\Util\Number::formatSi($rate_average, 2, 3, 'bps') ?>
|
||||
- Average rate <?php echo Number::formatSi($rate_average, 2, 3, 'bps') ?>
|
||||
</td>
|
||||
<td style="width: 210px;"><?php echo print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']) ?></td>
|
||||
</tr>
|
||||
|
@ -180,11 +182,11 @@ if (bill_permitted($bill_id)) {
|
|||
$unit = 'kbps';
|
||||
$cdr = $bill_data['bill_cdr'];
|
||||
$rate_95th = round($rate_95th, 2);
|
||||
$percent = round((($rate_95th) / $cdr * 100), 2);
|
||||
$percent = Number::calculatePercent($rate_95th, $cdr);
|
||||
$background = \LibreNMS\Util\Color::percentage($percent, null);
|
||||
$type = '&95th=yes'; ?>
|
||||
<td>
|
||||
<?php echo \LibreNMS\Util\Number::formatSi($rate_95th, 2, 3, '') . 'bps' ?> of <?php echo \LibreNMS\Util\Number::formatSi($cdr, 2, 3, '') . 'bps (' . $percent . '%)' ?> (95th%ile)
|
||||
<?php echo Number::formatSi($rate_95th, 2, 3, '') . 'bps' ?> of <?php echo Number::formatSi($cdr, 2, 3, '') . 'bps (' . $percent . '%)' ?> (95th%ile)
|
||||
</td>
|
||||
<td style="width: 210px;">
|
||||
<?php echo print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']) ?>
|
||||
|
@ -193,7 +195,7 @@ if (bill_permitted($bill_id)) {
|
|||
<tr>
|
||||
<td colspan="2">
|
||||
<?php
|
||||
echo 'Predicted usage: ' . \LibreNMS\Util\Number::formatSi(getPredictedUsage($bill_data['bill_day'], $bill_data['rate_95th']), 2, 3, '') . 'bps'; ?>
|
||||
echo 'Predicted usage: ' . Number::formatSi(getPredictedUsage($bill_data['bill_day'], $bill_data['rate_95th']), 2, 3, '') . 'bps'; ?>
|
||||
</td>
|
||||
|
||||
<?php
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use LibreNMS\Util\Number;
|
||||
|
||||
$pagetitle[] = 'Bandwidth Graphs';
|
||||
|
||||
// $bill_data = dbFetchRow("SELECT * FROM bills WHERE bill_id = ?", array($bill_id));
|
||||
|
@ -43,9 +45,9 @@ if ($bill_data['bill_type'] == 'quota') {
|
|||
$total['ave'] = format_bytes_billing(($bill_data['total_data'] / $cur_days));
|
||||
$total['est'] = format_bytes_billing(($bill_data['total_data'] / $cur_days * $total_days));
|
||||
if ($bill_data['bill_type'] == 'quota') {
|
||||
$total['per'] = round(($bill_data['total_data'] / $bill_data['bill_quota'] * 100), 2);
|
||||
$total['per'] = Number::calculatePercent($bill_data['total_data'], $bill_data['bill_quota']);
|
||||
} else {
|
||||
$total['per'] = round(($bill_data['total_data'] / ($bill_data['total_data'] / $cur_days * $total_days) * 100), 2);
|
||||
$total['per'] = Number::calculatePercent($bill_data['total_data'], $bill_data['total_data'] / $cur_days * $total_days);
|
||||
}
|
||||
$total['bg'] = \LibreNMS\Util\Color::percentage($total['per'], null);
|
||||
|
||||
|
@ -53,14 +55,14 @@ $in['data'] = format_bytes_billing($bill_data['total_data_in']);
|
|||
$in['allow'] = $total['allow'];
|
||||
$in['ave'] = format_bytes_billing(($bill_data['total_data_in'] / $cur_days));
|
||||
$in['est'] = format_bytes_billing(($bill_data['total_data_in'] / $cur_days * $total_days));
|
||||
$in['per'] = ! empty($bill_data['total_data']) ? round(($bill_data['total_data_in'] / $bill_data['total_data'] * 100), 2) : 0;
|
||||
$in['per'] = Number::calculatePercent($bill_data['total_data_in'], $bill_data['total_data']);
|
||||
$in['bg'] = \LibreNMS\Util\Color::percentage($in['per'], null);
|
||||
|
||||
$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));
|
||||
$out['per'] = ! empty($bill_data['total_data']) ? round(($bill_data['total_data_out'] / $bill_data['total_data'] * 100), 2) : 0;
|
||||
$out['per'] = Number::calculatePercent($bill_data['total_data_out'], $bill_data['total_data']);
|
||||
$out['bg'] = \LibreNMS\Util\Color::percentage($out['per'], null);
|
||||
|
||||
$ousage['over'] = ($bill_data['total_data'] - ($bill_data['bill_quota']));
|
||||
|
@ -69,7 +71,7 @@ $ousage['data'] = \LibreNMS\Util\Number::formatBase($ousage['over'], \LibreNMS\C
|
|||
$ousage['allow'] = $total['allow'];
|
||||
$ousage['ave'] = format_bytes_billing(($ousage['over'] / $cur_days));
|
||||
$ousage['est'] = format_bytes_billing(($ousage['over'] / $cur_days * $total_days));
|
||||
$ousage['per'] = round((($bill_data['total_data'] / $bill_data['bill_quota'] * 100) - 100), 2);
|
||||
$ousage['per'] = Number::calculatePercent($bill_data['total_data'], $bill_data['bill_quota']) - 100;
|
||||
$ousage['per'] = (($ousage['per'] < 0) ? '0' : $ousage['per']);
|
||||
$ousage['bg'] = \LibreNMS\Util\Color::percentage($ousage['per'], null);
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ if ($mempools->isNotEmpty()) {
|
|||
$buffers = $mempools->firstWhere('mempool_class', '=', 'buffers');
|
||||
$cached = $mempools->firstWhere('mempool_class', '=', 'cached');
|
||||
|
||||
$available_used_all = $mempool->mempool_total ? round(($mempool->mempool_used + $buffers->mempool_used + $cached->mempool_used) / $mempool->mempool_total * 100) : 0;
|
||||
$available_used_all = Number::calculatePercent($mempool->mempool_used + $buffers->mempool_used + $cached->mempool_used, $mempool->mempool_total, 0);
|
||||
}
|
||||
|
||||
$total = Number::formatBi($mempool->mempool_total);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use LibreNMS\Util\Number;
|
||||
|
||||
print_optionbar_start();
|
||||
|
||||
$link_array = [
|
||||
|
@ -125,7 +127,7 @@ if ($vars['view'] == 'lsp') {
|
|||
$path_status_color = 'warning';
|
||||
}
|
||||
|
||||
$avail = round($lsp['mplsLspPrimaryTimeUp'] / $lsp['mplsLspAge'] * 100, 5);
|
||||
$avail = Number::calculatePercent($lsp['mplsLspPrimaryTimeUp'], $lsp['mplsLspAge'], 5);
|
||||
|
||||
$host = @dbFetchRow('SELECT * FROM `ipv4_addresses` AS A, `ports` AS I, `devices` AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id', [$lsp['mplsLspToAddr']]);
|
||||
$destination = $lsp['mplsLspToAddr'];
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use LibreNMS\Util\Number;
|
||||
|
||||
print_optionbar_start();
|
||||
|
||||
$link_array = [
|
||||
|
@ -126,7 +128,7 @@ if ($vars['view'] == 'lsp') {
|
|||
$path_status_color = 'warning';
|
||||
}
|
||||
|
||||
$avail = round($lsp['mplsLspPrimaryTimeUp'] / $lsp['mplsLspAge'] * 100, 5);
|
||||
$avail = Number::calculatePercent($lsp['mplsLspPrimaryTimeUp'], $lsp['mplsLspAge'], 5);
|
||||
|
||||
$host = @dbFetchRow('SELECT * FROM `ipv4_addresses` AS A, `ports` AS I, `devices` AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id', [$lsp['mplsLspToAddr']]);
|
||||
$destination = $lsp['mplsLspToAddr'];
|
||||
|
|
|
@ -94,8 +94,8 @@ echo "</td><td width=120 onclick=\"location.href='" . generate_port_url($port) .
|
|||
if ($port['ifOperStatus'] == 'up') {
|
||||
$port['in_rate'] = ($port['ifInOctets_rate'] * 8);
|
||||
$port['out_rate'] = ($port['ifOutOctets_rate'] * 8);
|
||||
$in_perc = empty($port['ifSpeed']) ? 0 : round(($port['in_rate'] / $port['ifSpeed'] * 100));
|
||||
$out_perc = empty($port['ifSpeed']) ? 0 : round(($port['in_rate'] / $port['ifSpeed'] * 100));
|
||||
$in_perc = Number::calculatePercent($port['in_rate'], $port['ifSpeed'], 0);
|
||||
$out_perc = Number::calculatePercent($port['in_rate'], $port['ifSpeed'], 0);
|
||||
echo "<i class='fa fa-long-arrow-left fa-lg' style='color:green' aria-hidden='true'></i> <span style='color: " . percent_colour($in_perc) . "'>" . Number::formatSi($port['in_rate'], 2, 3, 'bps') . "<br />
|
||||
<i class='fa fa-long-arrow-right fa-lg' style='color:blue' aria-hidden='true'></i> <span style='color: " . percent_colour($out_perc) . "'>" . Number::formatSi($port['out_rate'], 2, 3, 'bps') . "<br />
|
||||
<i class='fa fa-long-arrow-left fa-lg' style='color:purple' aria-hidden='true'></i> " . Number::formatBi($port['ifInUcastPkts_rate'], 2, 3, 'pps') . "</span><br />
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
// Calculate filters
|
||||
use LibreNMS\Util\Number;
|
||||
|
||||
$prev = ! empty($vars['period']) && ($vars['period'] == 'prev');
|
||||
$wheres = [];
|
||||
$param = [];
|
||||
|
@ -86,12 +88,12 @@ foreach (dbFetchRows($sql, $param) as $bill) {
|
|||
$datefrom = $day_data['0'];
|
||||
$dateto = $day_data['1'];
|
||||
}
|
||||
$rate_95th = \LibreNMS\Util\Number::formatSi($bill['rate_95th'], 2, 3, '') . 'bps';
|
||||
$rate_95th = Number::formatSi($bill['rate_95th'], 2, 3, '') . 'bps';
|
||||
$dir_95th = $bill['dir_95th'];
|
||||
$total_data = format_bytes_billing($bill['total_data']);
|
||||
$rate_average = $bill['rate_average'];
|
||||
$url = \LibreNMS\Util\Url::generate(['page' => 'bill', 'bill_id' => $bill['bill_id']]);
|
||||
$used95th = \LibreNMS\Util\Number::formatSi($bill['rate_95th'], 2, 3, '') . 'bps';
|
||||
$used95th = Number::formatSi($bill['rate_95th'], 2, 3, '') . 'bps';
|
||||
$notes = $bill['bill_notes'];
|
||||
|
||||
if ($prev) {
|
||||
|
@ -102,15 +104,15 @@ foreach (dbFetchRows($sql, $param) as $bill) {
|
|||
|
||||
if (strtolower($bill['bill_type']) == 'cdr') {
|
||||
$type = 'CDR';
|
||||
$allowed = \LibreNMS\Util\Number::formatSi($bill['bill_allowed'], 2, 3, '') . 'bps';
|
||||
$in = \LibreNMS\Util\Number::formatSi($bill['rate_95th_in'], 2, 3, '') . 'bps';
|
||||
$out = \LibreNMS\Util\Number::formatSi($bill['rate_95th_out'], 2, 3, '') . 'bps';
|
||||
$allowed = Number::formatSi($bill['bill_allowed'], 2, 3, '') . 'bps';
|
||||
$in = Number::formatSi($bill['rate_95th_in'], 2, 3, '') . 'bps';
|
||||
$out = Number::formatSi($bill['rate_95th_out'], 2, 3, '') . 'bps';
|
||||
if (! $prev) {
|
||||
$percent = round((($bill['rate_95th'] / $bill['bill_allowed']) * 100), 2);
|
||||
$percent = Number::calculatePercent($bill['rate_95th'], $bill['bill_allowed']);
|
||||
$overuse = ($bill['rate_95th'] - $bill['bill_allowed']);
|
||||
}
|
||||
|
||||
$overuse_formatted = \LibreNMS\Util\Number::formatSi($overuse, 2, 3, '') . 'bps';
|
||||
$overuse_formatted = Number::formatSi($overuse, 2, 3, '') . 'bps';
|
||||
$used = $rate_95th;
|
||||
$tmp_used = $bill['rate_95th'];
|
||||
$rate_95th = "<b>$rate_95th</b>";
|
||||
|
@ -125,7 +127,7 @@ foreach (dbFetchRows($sql, $param) as $bill) {
|
|||
$out = format_bytes_billing($bill['total_data_out']);
|
||||
}
|
||||
if (! $prev) {
|
||||
$percent = round((($bill['total_data'] / ($bill['bill_allowed'])) * 100), 2);
|
||||
$percent = Number::calculatePercent($bill['total_data'], $bill['bill_allowed']);
|
||||
$overuse = ($bill['total_data'] - $bill['bill_allowed']);
|
||||
}
|
||||
|
||||
|
@ -150,7 +152,7 @@ foreach (dbFetchRows($sql, $param) as $bill) {
|
|||
"'><i class='fa fa-pencil fa-lg icon-theme' title='Edit' aria-hidden='true'></i> Edit</a> ";
|
||||
}
|
||||
if (strtolower($bill['bill_type']) == 'cdr') {
|
||||
$predicted = \LibreNMS\Util\Number::formatSi(getPredictedUsage($bill['bill_day'], $tmp_used), 2, 3, '') . 'bps';
|
||||
$predicted = Number::formatSi(getPredictedUsage($bill['bill_day'], $tmp_used), 2, 3, '') . 'bps';
|
||||
} elseif (strtolower($bill['bill_type']) == 'quota') {
|
||||
$predicted = format_bytes_billing(getPredictedUsage($bill['bill_day'], $tmp_used));
|
||||
}
|
||||
|
|
|
@ -821,8 +821,8 @@ foreach ($ports as $port) {
|
|||
|
||||
// If we have a valid ifSpeed we should populate the stats for checking
|
||||
if (is_numeric($this_port['ifSpeed']) && $this_port['ifSpeed'] > 0) {
|
||||
$port['stats']['ifInBits_perc'] = round(($port['stats']['ifInBits_rate'] / $this_port['ifSpeed'] * 100));
|
||||
$port['stats']['ifOutBits_perc'] = round(($port['stats']['ifOutBits_rate'] / $this_port['ifSpeed'] * 100));
|
||||
$port['stats']['ifInBits_perc'] = Number::calculatePercent($port['stats']['ifInBits_rate'], $this_port['ifSpeed'], 0);
|
||||
$port['stats']['ifOutBits_perc'] = Number::calculatePercent($port['stats']['ifOutBits_rate'], $this_port['ifSpeed'], 0);
|
||||
}
|
||||
|
||||
echo 'bps(' . Number::formatSi($port['stats']['ifInBits_rate'], 2, 3, 'bps') . '/' . Number::formatSi($port['stats']['ifOutBits_rate'], 2, 3, 'bps') . ')';
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use LibreNMS\RRD\RrdDefinition;
|
||||
use LibreNMS\Util\Number;
|
||||
|
||||
foreach (dbFetchRows('SELECT * FROM storage WHERE device_id = ?', [$device['device_id']]) as $storage) {
|
||||
$descr = $storage['storage_descr'];
|
||||
|
@ -20,12 +21,7 @@ foreach (dbFetchRows('SELECT * FROM storage WHERE device_id = ?', [$device['devi
|
|||
|
||||
d_echo($storage);
|
||||
|
||||
if ($storage['size']) {
|
||||
$percent = round(($storage['used'] / $storage['size'] * 100));
|
||||
} else {
|
||||
$percent = 0;
|
||||
}
|
||||
|
||||
$percent = Number::calculatePercent($storage['used'], $storage['size'], 0);
|
||||
echo $percent . '% ';
|
||||
|
||||
$fields = [
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
use LibreNMS\RRD\RrdDefinition;
|
||||
use LibreNMS\Util\Number;
|
||||
|
||||
// $cambiumSTADLRSSI = snmp_get($device, "cambiumSTADLRSSI.0", "-Ovqn", "CAMBIUM-PMP80211-MIB");
|
||||
// $cambiumSTADLSNR = snmp_get($device, "cambiumSTADLSNR.0", "-Ovqn", "CAMBIUM-PMP80211-MIB");
|
||||
|
@ -112,8 +114,8 @@ $dlWLanTotalAvailableFrameTimePerSecond = $multi_get_array[0]['CAMBIUM-PMP80211-
|
|||
$dlWLanTotalUsedFrameTimePerSecond = $multi_get_array[0]['CAMBIUM-PMP80211-MIB::dlWLanTotalUsedFrameTimePerSecond'];
|
||||
|
||||
if (is_numeric($ulWLanTotalAvailableFrameTimePerSecond) && is_numeric($ulWLanTotalUsedFrameTimePerSecond) && is_numeric($ulWLanTotalAvailableFrameTimePerSecond) && is_numeric($ulWLanTotalUsedFrameTimePerSecond)) {
|
||||
$ulWlanFrameUtilization = round((($ulWLanTotalUsedFrameTimePerSecond / $ulWLanTotalAvailableFrameTimePerSecond) * 100), 2);
|
||||
$dlWlanFrameUtilization = round((($dlWLanTotalUsedFrameTimePerSecond / $dlWLanTotalAvailableFrameTimePerSecond) * 100), 2);
|
||||
$ulWlanFrameUtilization = Number::calculatePercent($ulWLanTotalUsedFrameTimePerSecond, $ulWLanTotalAvailableFrameTimePerSecond);
|
||||
$dlWlanFrameUtilization = Number::calculatePercent($dlWLanTotalUsedFrameTimePerSecond, $dlWLanTotalAvailableFrameTimePerSecond);
|
||||
d_echo($dlWlanFrameUtilization);
|
||||
d_echo($ulWlanFrameUtilization);
|
||||
$rrd_def = RrdDefinition::make()
|
||||
|
|
Loading…
Reference in New Issue