mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Add optional cleanup task for old bill_data
This commit is contained in:
21
daily.php
21
daily.php
@@ -115,6 +115,27 @@ if ($options['f'] === 'notifications') {
|
|||||||
include_once 'includes/notifications.php';
|
include_once 'includes/notifications.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($options['f'] === 'bill_data') {
|
||||||
|
if (is_numeric($config['billing_data_purge']) && $config['billing_data_purge'] > 0) {
|
||||||
|
# Deletes data older than XX months before the start of the last complete billing period
|
||||||
|
$months = $config['billing_data_purge'];
|
||||||
|
echo "Deleting billing data more than $months month before the last completed billing cycle\n";
|
||||||
|
$sql = "DELETE bill_data
|
||||||
|
FROM bill_data
|
||||||
|
INNER JOIN (SELECT bill_id,
|
||||||
|
SUBDATE(
|
||||||
|
SUBDATE(
|
||||||
|
ADDDATE(
|
||||||
|
subdate(curdate(), (day(curdate())-1)), # Start of this month
|
||||||
|
bill_day - 1), # Billing anniversary
|
||||||
|
INTERVAL IF(bill_day > DAY(curdate()), 1, 0) MONTH), # Deal with anniversary not yet happened this month
|
||||||
|
INTERVAL ? MONTH) AS threshold # Adjust based on config threshold
|
||||||
|
FROM bills) q
|
||||||
|
ON bill_data.bill_id = q.bill_id AND bill_data.timestamp < q.threshold;";
|
||||||
|
dbQuery($sql, array($months));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($options['f'] === 'purgeusers') {
|
if ($options['f'] === 'purgeusers') {
|
||||||
$purge = 0;
|
$purge = 0;
|
||||||
if (is_numeric($config['radius']['users_purge']) && $config['auth_mechanism'] === 'radius') {
|
if (is_numeric($config['radius']['users_purge']) && $config['auth_mechanism'] === 'radius') {
|
||||||
|
|||||||
1
daily.sh
1
daily.sh
@@ -74,6 +74,7 @@ else
|
|||||||
php daily.php -f callback
|
php daily.php -f callback
|
||||||
php daily.php -f device_perf
|
php daily.php -f device_perf
|
||||||
php daily.php -f purgeusers
|
php daily.php -f purgeusers
|
||||||
|
php daily.php -f bill_data
|
||||||
;;
|
;;
|
||||||
submodules)
|
submodules)
|
||||||
# Init+Update our submodules
|
# Init+Update our submodules
|
||||||
|
|||||||
@@ -16,3 +16,17 @@ Edit `/etc/cron.d/librenms` and add the following:
|
|||||||
```
|
```
|
||||||
|
|
||||||
Create billing graphs as required.
|
Create billing graphs as required.
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
Billing data is stored in the MySQL database, and you may wish to purge the detailed
|
||||||
|
stats for old data (per-month totals will always be kept). To enable this, add the
|
||||||
|
following to `config.php`:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$config['billing_data_purge'] = 12; // Number of months to retain
|
||||||
|
```
|
||||||
|
|
||||||
|
Data for the last complete billing cycle will always be retained - only data older than
|
||||||
|
this by the configured number of months will be removed. This task is performed in the
|
||||||
|
daily cleanup tasks.
|
||||||
Reference in New Issue
Block a user