mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Billing: add peak in and out (#13006)
* feat(api): added max in/out per bill_history period * chore(Docs): updated docs to include in/out max values * chore(formatting): style-ci * chore(db): update db-schema * fix(db): reverted wrong changes in schema * fix: wrong table name in migration * feat(billing-history-frontend): added max in/out values to frontend bill-history * chore: renamed to peak instead of min/max
This commit is contained in:
@@ -42,7 +42,7 @@ foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_id`') as $bill) {
|
|||||||
// Send the current dir_95th to the getRates function so it knows to aggregate or return the max in/out value and highest direction
|
// Send the current dir_95th to the getRates function so it knows to aggregate or return the max in/out value and highest direction
|
||||||
$dir_95th = $bill['dir_95th'];
|
$dir_95th = $bill['dir_95th'];
|
||||||
|
|
||||||
if ($period > 0 && $dateto > $date_updated) {
|
if ($period['period'] > 0 && $dateto > $date_updated) {
|
||||||
$rate_data = getRates($bill['bill_id'], $datefrom, $dateto, $dir_95th);
|
$rate_data = getRates($bill['bill_id'], $datefrom, $dateto, $dir_95th);
|
||||||
$rate_95th = $rate_data['rate_95th'];
|
$rate_95th = $rate_data['rate_95th'];
|
||||||
$dir_95th = $rate_data['dir_95th'];
|
$dir_95th = $rate_data['dir_95th'];
|
||||||
@@ -102,6 +102,8 @@ foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_id`') as $bill) {
|
|||||||
'traf_total' => $rate_data['total_data'],
|
'traf_total' => $rate_data['total_data'],
|
||||||
'traf_in' => $rate_data['total_data_in'],
|
'traf_in' => $rate_data['total_data_in'],
|
||||||
'traf_out' => $rate_data['total_data_out'],
|
'traf_out' => $rate_data['total_data_out'],
|
||||||
|
'bill_peak_out' => $period['peak_out'],
|
||||||
|
'bill_peak_in' => $period['peak_in'],
|
||||||
'bill_used' => $used,
|
'bill_used' => $used,
|
||||||
'bill_overuse' => $overuse,
|
'bill_overuse' => $overuse,
|
||||||
'bill_percent' => $percent,
|
'bill_percent' => $percent,
|
||||||
@@ -133,10 +135,10 @@ foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_id`') as $bill) {
|
|||||||
];
|
];
|
||||||
dbInsert($update, 'bill_history');
|
dbInsert($update, 'bill_history');
|
||||||
echo ' Generated history! ';
|
echo ' Generated history! ';
|
||||||
}//end if
|
} //end if
|
||||||
echo "\n\n";
|
echo "\n\n";
|
||||||
}//end if
|
} //end if
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
}//end while
|
} //end while
|
||||||
}//end foreach
|
}//end foreach
|
||||||
|
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AlterBillHistoryMaxMin extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('bill_history', function (Blueprint $table) {
|
||||||
|
$table->bigInteger('bill_peak_out')->nullable()->after('traf_total');
|
||||||
|
$table->bigInteger('bill_peak_in')->nullable()->after('bill_peak_out');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('bill_history', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['bill_peak_in', 'bill_peak_out']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -260,6 +260,8 @@ Output:
|
|||||||
"traf_in": "3235123452544",
|
"traf_in": "3235123452544",
|
||||||
"traf_out": "33608406566",
|
"traf_out": "33608406566",
|
||||||
"traf_total": "3268731859110",
|
"traf_total": "3268731859110",
|
||||||
|
"bill_peak_out": "2782349290",
|
||||||
|
"bill_peak_in": "10161119",
|
||||||
"pdf": null
|
"pdf": null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@@ -216,7 +216,7 @@ function getSum($bill_id, $datefrom, $dateto)
|
|||||||
|
|
||||||
function getPeriod($bill_id, $datefrom, $dateto)
|
function getPeriod($bill_id, $datefrom, $dateto)
|
||||||
{
|
{
|
||||||
$ptot = dbFetchCell('SELECT SUM(period) FROM bill_data WHERE bill_id = ? AND timestamp > ? AND timestamp <= ?', [$bill_id, $datefrom, $dateto]);
|
$ptot = dbFetchRow('SELECT SUM(period) as `period`, MAX(in_delta) as `peak_in`, MAX(out_delta) as `peak_out` FROM bill_data WHERE bill_id = ? AND timestamp > ? AND timestamp <= ?', [$bill_id, $datefrom, $dateto]);
|
||||||
|
|
||||||
return $ptot;
|
return $ptot;
|
||||||
}//end getPeriod()
|
}//end getPeriod()
|
||||||
|
@@ -55,6 +55,8 @@ echo '<table class="table table-striped">
|
|||||||
<th>Allowed</th>
|
<th>Allowed</th>
|
||||||
<th>Inbound</th>
|
<th>Inbound</th>
|
||||||
<th>Outbound</th>
|
<th>Outbound</th>
|
||||||
|
<th>Peak Out</th>
|
||||||
|
<th>Peak In</th>
|
||||||
<th>Total</th>
|
<th>Total</th>
|
||||||
<th>95th %ile</th>
|
<th>95th %ile</th>
|
||||||
<th style="text-align: center;">Overusage</th>
|
<th style="text-align: center;">Overusage</th>
|
||||||
@@ -91,6 +93,8 @@ foreach (dbFetchRows('SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY
|
|||||||
$out = Number::formatBase($history['traf_out'], \LibreNMS\Config::get('billing.base'), 2, 3, '');
|
$out = Number::formatBase($history['traf_out'], \LibreNMS\Config::get('billing.base'), 2, 3, '');
|
||||||
$overuse = (($history['bill_overuse'] <= 0) ? '-' : '<span style="color: #' . $background['left'] . '; font-weight: bold;">' . Number::formatBase($history['bill_overuse'], \LibreNMS\Config::get('billing.base')) . '</span>');
|
$overuse = (($history['bill_overuse'] <= 0) ? '-' : '<span style="color: #' . $background['left'] . '; font-weight: bold;">' . Number::formatBase($history['bill_overuse'], \LibreNMS\Config::get('billing.base')) . '</span>');
|
||||||
}
|
}
|
||||||
|
$peakOut = Number::formatBase($history['bill_peak_out'], \LibreNMS\Config::get('billing.base'), 2, 3, '');
|
||||||
|
$peakIn = Number::formatBase($history['bill_peak_in'], \LibreNMS\Config::get('billing.base'), 2, 3, '');
|
||||||
|
|
||||||
$total_data = (($type == 'Quota') ? '<b>' . $total_data . '</b>' : $total_data);
|
$total_data = (($type == 'Quota') ? '<b>' . $total_data . '</b>' : $total_data);
|
||||||
$rate_95th = (($type == 'CDR') ? '<b>' . $rate_95th . '</b>' : $rate_95th);
|
$rate_95th = (($type == 'CDR') ? '<b>' . $rate_95th . '</b>' : $rate_95th);
|
||||||
@@ -105,6 +109,8 @@ foreach (dbFetchRows('SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY
|
|||||||
<td>$allowed</td>
|
<td>$allowed</td>
|
||||||
<td>$in</td>
|
<td>$in</td>
|
||||||
<td>$out</td>
|
<td>$out</td>
|
||||||
|
<td>$peakOut</td>
|
||||||
|
<td>$peakIn</td>
|
||||||
<td>$total_data</td>
|
<td>$total_data</td>
|
||||||
<td>$rate_95th</td>
|
<td>$rate_95th</td>
|
||||||
<td style=\"text-align: center;\">$overuse</td>
|
<td style=\"text-align: center;\">$overuse</td>
|
||||||
|
@@ -313,6 +313,8 @@ bill_history:
|
|||||||
- { Field: traf_in, Type: bigint, 'Null': false, Extra: '' }
|
- { Field: traf_in, Type: bigint, 'Null': false, Extra: '' }
|
||||||
- { Field: traf_out, Type: bigint, 'Null': false, Extra: '' }
|
- { Field: traf_out, Type: bigint, 'Null': false, Extra: '' }
|
||||||
- { Field: traf_total, Type: bigint, 'Null': false, Extra: '' }
|
- { Field: traf_total, Type: bigint, 'Null': false, Extra: '' }
|
||||||
|
- { Field: bill_peak_out, Type: bigint, 'Null': true, Extra: '' }
|
||||||
|
- { Field: bill_peak_in, Type: bigint, 'Null': true, Extra: '' }
|
||||||
- { Field: pdf, Type: longblob, 'Null': true, Extra: '' }
|
- { Field: pdf, Type: longblob, 'Null': true, Extra: '' }
|
||||||
Indexes:
|
Indexes:
|
||||||
PRIMARY: { Name: PRIMARY, Columns: [bill_hist_id], Unique: true, Type: BTREE }
|
PRIMARY: { Name: PRIMARY, Columns: [bill_hist_id], Unique: true, Type: BTREE }
|
||||||
@@ -2131,4 +2133,4 @@ wireless_sensors:
|
|||||||
wireless_sensors_sensor_class_index: { Name: wireless_sensors_sensor_class_index, Columns: [sensor_class], Unique: false, Type: BTREE }
|
wireless_sensors_sensor_class_index: { Name: wireless_sensors_sensor_class_index, Columns: [sensor_class], Unique: false, Type: BTREE }
|
||||||
wireless_sensors_sensor_type_index: { Name: wireless_sensors_sensor_type_index, Columns: [sensor_type], Unique: false, Type: BTREE }
|
wireless_sensors_sensor_type_index: { Name: wireless_sensors_sensor_type_index, Columns: [sensor_type], Unique: false, Type: BTREE }
|
||||||
Constraints:
|
Constraints:
|
||||||
wireless_sensors_device_id_foreign: { name: wireless_sensors_device_id_foreign, foreign_key: device_id, table: devices, key: device_id, extra: 'ON DELETE CASCADE' }
|
wireless_sensors_device_id_foreign: { name: wireless_sensors_device_id_foreign, foreign_key: device_id, table: devices, key: device_id, extra: 'ON DELETE CASCADE' }
|
Reference in New Issue
Block a user