From 318c9cd2b08498ab4a7307993913977505c8a496 Mon Sep 17 00:00:00 2001 From: laf Date: Sat, 30 Jul 2016 16:57:09 +0100 Subject: [PATCH 1/6] Added cleanup for old RRD files --- config.php.default | 2 ++ daily.php | 8 ++++++++ daily.sh | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config.php.default b/config.php.default index 2da0514e0d..85c5de25b0 100755 --- a/config.php.default +++ b/config.php.default @@ -46,6 +46,8 @@ $config['auth_mechanism'] = "mysql"; # default, other options: ldap, http-auth $config['poller-wrapper']['alerter'] = FALSE; # Uncomment the next line to disable daily updates #$config['update'] = 0; +$config['rrd_purge'] = 90; +// Number in days of how long to keep old rrd files. # Uncomment to submit callback stats via proxy #$config['callback_proxy'] = "hostname:port"; diff --git a/daily.php b/daily.php index 4184b20cff..d8579761f7 100644 --- a/daily.php +++ b/daily.php @@ -31,6 +31,14 @@ if ($options['f'] === 'update') { exit(0); } +if ($options['f'] === 'rrd_purge') { + if (is_numeric($config['rrd_purge'])) { + $cmd = "find ".$config['rrd_dir']." -mtime +".$config['rrd_purge']." -exec rm -Rf {} \;"; + $purge = `$cmd`; + echo 'purged old rrd files'; + } +} + if ($options['f'] === 'syslog') { if (is_numeric($config['syslog_purge'])) { $rows = dbFetchRow('SELECT MIN(seq) FROM syslog'); diff --git a/daily.sh b/daily.sh index de298c7b9c..a3bb7f0185 100755 --- a/daily.sh +++ b/daily.sh @@ -76,7 +76,7 @@ else status_run 'Fetching notifications' "$0 notifications" ;; cleanup) - # DB-Cleanups + # Cleanups php daily.php -f syslog php daily.php -f eventlog php daily.php -f authlog @@ -86,6 +86,7 @@ else php daily.php -f purgeusers php daily.php -f bill_data php daily.php -f alert_log + php daily.php -f rrd_purge ;; submodules) # Init+Update our submodules From 1741231ebcdff2a8535e4f41d0900411e0a2e682 Mon Sep 17 00:00:00 2001 From: laf Date: Sat, 30 Jul 2016 16:58:18 +0100 Subject: [PATCH 2/6] Updated docs for rrd_purge option --- doc/Support/Configuration.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/Support/Configuration.md b/doc/Support/Configuration.md index a2699620b4..283242a287 100644 --- a/doc/Support/Configuration.md +++ b/doc/Support/Configuration.md @@ -496,8 +496,9 @@ $config['eventlog_purge'] = 30; $config['authlog_purge'] = 30; $config['perf_times_purge'] = 30; $config['device_perf_purge'] = 30; +$config['rrd_purge'] = 90;// Not set by default ``` -This option will ensure data within LibreNMS over 1 month old is automatically purged. You can alter these individually, +This option will ensure data within LibreNMS over X days old is automatically purged. You can alter these individually, values are in days. #### Syslog options From 5a7a606abd6ab3ecf497eb7c6560d0f60496f17e Mon Sep 17 00:00:00 2001 From: laf Date: Sun, 31 Jul 2016 23:39:45 +0100 Subject: [PATCH 3/6] Updated as per pr comments --- config.php.default | 5 +++-- daily.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/config.php.default b/config.php.default index 85c5de25b0..c8ac44a2bf 100755 --- a/config.php.default +++ b/config.php.default @@ -46,8 +46,9 @@ $config['auth_mechanism'] = "mysql"; # default, other options: ldap, http-auth $config['poller-wrapper']['alerter'] = FALSE; # Uncomment the next line to disable daily updates #$config['update'] = 0; -$config['rrd_purge'] = 90; -// Number in days of how long to keep old rrd files. + +# Number in days of how long to keep old rrd files. 0 disables this feature +$config['rrd_purge'] = 0; # Uncomment to submit callback stats via proxy #$config['callback_proxy'] = "hostname:port"; diff --git a/daily.php b/daily.php index d8579761f7..c4e207e4e6 100644 --- a/daily.php +++ b/daily.php @@ -32,7 +32,7 @@ if ($options['f'] === 'update') { } if ($options['f'] === 'rrd_purge') { - if (is_numeric($config['rrd_purge'])) { + if (is_numeric($config['rrd_purge']) && $config['rrd_purge'] > 0) { $cmd = "find ".$config['rrd_dir']." -mtime +".$config['rrd_purge']." -exec rm -Rf {} \;"; $purge = `$cmd`; echo 'purged old rrd files'; From f73385999eb1c4223c46c9183ede5ddd6ab69990 Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 1 Aug 2016 15:08:57 +0100 Subject: [PATCH 4/6] Updated rrd_purge to echo removed files/folders --- daily.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/daily.php b/daily.php index c4e207e4e6..8b60154dfc 100644 --- a/daily.php +++ b/daily.php @@ -35,7 +35,9 @@ if ($options['f'] === 'rrd_purge') { if (is_numeric($config['rrd_purge']) && $config['rrd_purge'] > 0) { $cmd = "find ".$config['rrd_dir']." -mtime +".$config['rrd_purge']." -exec rm -Rf {} \;"; $purge = `$cmd`; - echo 'purged old rrd files'; + if (!empty($purge)) { + echo $purge; + } } } From b0d05ad1491b454d1cef2bf0f90aa10e1d6f58e8 Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 1 Aug 2016 18:31:19 +0100 Subject: [PATCH 5/6] Added -print to find + description of why we have deleted files --- daily.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/daily.php b/daily.php index 8b60154dfc..2e6ae27597 100644 --- a/daily.php +++ b/daily.php @@ -33,9 +33,10 @@ if ($options['f'] === 'update') { if ($options['f'] === 'rrd_purge') { if (is_numeric($config['rrd_purge']) && $config['rrd_purge'] > 0) { - $cmd = "find ".$config['rrd_dir']." -mtime +".$config['rrd_purge']." -exec rm -Rf {} \;"; + $cmd = "find ".$config['rrd_dir']." -mtime +".$config['rrd_purge']." -print -exec rm -Rf {} \;"; $purge = `$cmd`; if (!empty($purge)) { + echo "Purged the following RRD files due to old age (over ".$config['rrd_purge']." days old)"; echo $purge; } } From 1d2c8f5d48b6fbbe98cd4b1e281867e6836bc99c Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 1 Aug 2016 18:56:50 +0100 Subject: [PATCH 6/6] Updated docs to be clearer --- doc/Support/Configuration.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/Support/Configuration.md b/doc/Support/Configuration.md index 283242a287..323aa319cb 100644 --- a/doc/Support/Configuration.md +++ b/doc/Support/Configuration.md @@ -498,9 +498,12 @@ $config['perf_times_purge'] = 30; $config['device_perf_purge'] = 30; $config['rrd_purge'] = 90;// Not set by default ``` -This option will ensure data within LibreNMS over X days old is automatically purged. You can alter these individually, +These options will ensure data within LibreNMS over X days old is automatically purged. You can alter these individually, values are in days. +> NOTE: Please be aware that `$config['rrd_purge']` is _NOT_ set by default. This option will remove any old data within +the rrd directory automatically - only enable this if you are comfortable with that happening. + #### Syslog options ```php