mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Move Billing/Bandwidth Graphs to common format, extract data generation to central function * Add API functions to access billing graphs and graph data * Scrutinizer fixes * Fix transfer graphs with from/to * Scrutinizer Fix * Fix docs, transfer page and missing from API param * Document and fix reducefactor, Add Graph Stats to Graph Data * Standardise times in graphdata * Fixed renamed function for History GraphData
136 lines
5.6 KiB
PHP
136 lines
5.6 KiB
PHP
<?php
|
|
|
|
$pagetitle[] = 'Historical Usage';
|
|
// $detail = (isset($vars['detail']) ? $vars['detail'] : "");
|
|
// $url = $PHP_SELF."/bill/".$bill_id."/history/";
|
|
$i = 0;
|
|
|
|
$img['his'] = '<img src="graph.php?id='.$bill_id;
|
|
$img['his'] .= '&type=bill_historicmonthly';
|
|
$img['his'] .= '&width=1190&height=250';
|
|
$img['his'] .= '" style="margin: 15px 5px 25px 5px;" />';
|
|
?>
|
|
|
|
<h3>Historical Usage</h3>
|
|
|
|
<div class="panel panel-default">
|
|
<div class="panel-heading">
|
|
<h3 class="panel-title">Monthly Usage</h3>
|
|
</div>
|
|
<?php echo $img['his'] ?>
|
|
</div>
|
|
|
|
<?php
|
|
|
|
function showDetails($bill_id, $imgtype, $bill_hist_id)
|
|
{
|
|
$res = '<img src="graph.php?id='.$bill_id;
|
|
|
|
if ($imgtype == 'bitrate') {
|
|
$res .= '&type=bill_historicbits';
|
|
} else {
|
|
$res .= '&type=bill_historictransfer';
|
|
$res .= '&imgtype='.$imgtype;
|
|
}
|
|
$res .= '&width=1190&height=250';
|
|
if (is_numeric($bill_hist_id)) {
|
|
$res .= '&bill_hist_id='.$bill_hist_id;
|
|
}
|
|
$res .= '" style="margin: 15px 5px 25px 5px;" />';
|
|
return $res;
|
|
}//end showDetails()
|
|
|
|
|
|
// $url = generate_url($vars, array('detail' => 'yes'));
|
|
$url = $PHP_SELF.'/bill/'.$bill_id.'/history/detail=all/';
|
|
|
|
echo '<table class="table table-striped">
|
|
<thead>
|
|
<tr style="font-weight: bold; ">
|
|
<th width="7"></th>
|
|
<th width="250">Period</th>
|
|
<th>Type</th>
|
|
<th>Allowed</th>
|
|
<th>Inbound</th>
|
|
<th>Outbound</th>
|
|
<th>Total</th>
|
|
<th>95th %ile</th>
|
|
<th style="text-align: center;">Overusage</th>
|
|
<th colspan="2" style="text-align: right;"><a href="'.generate_url($vars, array('detail' => 'all')).'">
|
|
<i class="fa fa-bar-chart fa-lg icon-theme" aria-hidden="true" title="Show details"></i> Show details</a>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>';
|
|
|
|
foreach (dbFetchRows('SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` DESC LIMIT 24', array($bill_id)) as $history) {
|
|
if (bill_permitted($history['bill_id'])) {
|
|
unset($class);
|
|
$datefrom = $history['bill_datefrom'];
|
|
$dateto = $history['bill_dateto'];
|
|
$type = $history['bill_type'];
|
|
$percent = $history['bill_percent'];
|
|
$dir_95th = $history['dir_95th'];
|
|
$rate_95th = formatRates($history['rate_95th']);
|
|
$total_data = format_number($history['traf_total'], $config['billing']['base']);
|
|
|
|
$background = get_percentage_colours($percent);
|
|
|
|
if ($type == 'CDR') {
|
|
$allowed = formatRates($history['bill_allowed']);
|
|
$used = formatRates($history['rate_95th']);
|
|
$in = formatRates($history['rate_95th_in']);
|
|
$out = formatRates($history['rate_95th_out']);
|
|
$overuse = (($history['bill_overuse'] <= 0) ? '-' : '<span style="color: #'.$background['left'].'; font-weight: bold;">'.formatRates($history['bill_overuse']).'</span>');
|
|
} elseif ($type == 'Quota') {
|
|
$allowed = format_number($history['bill_allowed'], $config['billing']['base']);
|
|
$used = format_number($history['total_data'], $config['billing']['base']);
|
|
$in = format_number($history['traf_in'], $config['billing']['base']);
|
|
$out = format_number($history['traf_out'], $config['billing']['base']);
|
|
$overuse = (($history['bill_overuse'] <= 0) ? '-' : '<span style="color: #'.$background['left'].'; font-weight: bold;">'.format_number($history['bill_overuse'], $config['billing']['base']).'B</span>');
|
|
}
|
|
|
|
$total_data = (($type == 'Quota') ? '<b>'.$total_data.'</b>' : $total_data);
|
|
$rate_95th = (($type == 'CDR') ? '<b>'.$rate_95th.'</b>' : $rate_95th);
|
|
|
|
$url = generate_url($vars, array('detail' => $history['bill_hist_id']));
|
|
|
|
echo '
|
|
<tr>
|
|
<td></td>
|
|
<td><span style="font-weight: bold;" class="interface">'.strftime('%Y-%m-%d', strtotime($datefrom)).' to '.strftime('%Y-%m-%d', strtotime($dateto))."</span></td>
|
|
<td>$type</td>
|
|
<td>$allowed</td>
|
|
<td>$in</td>
|
|
<td>$out</td>
|
|
<td>$total_data</td>
|
|
<td>$rate_95th</td>
|
|
<td style=\"text-align: center;\">$overuse</td>
|
|
<td width=\"250\">".print_percentage_bar(250, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']).'</td>
|
|
<td>
|
|
<a href="'.$url.'"><i class="fa fa-bar-chart fa-lg icon-theme" aria-hidden="true" title="Show details"></i></a>
|
|
</td>
|
|
</tr>';
|
|
|
|
if ($vars['detail'] == $history['bill_hist_id'] || $vars['detail'] == 'all') {
|
|
$img['bitrate'] = showDetails($bill_id, 'bitrate', $history['bill_hist_id']);
|
|
$img['bw_day'] = showDetails($bill_id, 'day', $history['bill_hist_id']);
|
|
$img['bw_hour'] = showDetails($bill_id, 'hour', $history['bill_hist_id']);
|
|
echo '
|
|
<tr style="background: #fff; border-top: 1px solid '.$row_colour.'; border-bottom: 1px solid #ccc;">
|
|
<td colspan="11">
|
|
<!-- <b>Accuate Graph</b><br /> //-->
|
|
'.$img['bitrate'].'<br />
|
|
<!-- <b>Bandwidth Graph per day</b><br /> //-->
|
|
'.$img['bw_day'].'<br />
|
|
<!-- <b>Bandwidth Graph per hour</b><br /> //-->
|
|
'.$img['bw_hour'].'
|
|
</td>
|
|
</tr>';
|
|
}
|
|
} //end if
|
|
}//end foreach
|
|
|
|
echo '</tbody>
|
|
</table>';
|