feature: Added rrd step conversion script (#6081)

* feature: Added rrd step conversion script

* updated to support all for hostname

* update docs + code

* small updates as per murrant
This commit is contained in:
Neil Lathwood
2017-03-11 13:32:43 +00:00
committed by Tony Murray
parent fa29839d36
commit 8ca1f169b3
2 changed files with 101 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
source: Support/1-Minute-Polling.md
### Information
We now have support for polling data at intervals to fit your needs.
> Please be aware of the following:
@@ -13,3 +14,18 @@ To make the changes, please navigate to `/settings/sub=external/` within your We
- Step is how often you want to insert data, so if you change to 1 minute polling then this should be 60.
- Heartbeat is how long to wait for data before registering a null value, i.e 120 seconds.
### Converting existing RRD files
We provide a basic script to convert the default rrd files we generate to utilise your configured step and heartbeat
values. Please do ensure that you backup your RRD files before running this just in case. The script runs on a per
device basis or all devices at once.
> The rrd files must be accessible from the server you run this script from.
`./scripts/rrdstep.php`
This will provide the help information. To run it for localhost just run:
`./scripts/rrdstep.php -h localhost`

85
scripts/rrdstep.php Executable file
View File

@@ -0,0 +1,85 @@
#!/usr/bin/env php
<?php
/**
* rrdstep.php
*
* LibreNMS Script to convert rrd files from default 300 step to user defined
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2017 Neil Lathwood
* @author Neil Lathwood <neil@lathwood.co.uk>
*/
$init_modules = array();
require realpath(__DIR__ . '/..') . '/includes/init.php';
$options = getopt('h:');
$hostname = $options['h'] ?: '';
if (empty($hostname)) {
echo "*********************************************************************\n";
echo "We highly suggest that you back up your rrd files before running this\n";
echo "*********************************************************************\n";
echo "-h <hostname or device id or all> Device to process the rrd file for\n";
echo "\n";
exit;
}
if ($hostname !== 'all') {
$hostname = !ctype_digit($hostname) ? $hostname : gethostbyid($hostname);
}
if (empty($hostname)) {
echo "Invalid hostname or device id specified\n";
exit;
}
$step = $config['rrd']['step'];
$heartbeat = $config['rrd']['heartbeat'];
$rrd_path = $config['rrd_dir'];
$rrdtool = $config['rrdtool'];
$tmp_path = $config['temp_dir'];
if ($hostname === 'all') {
$hostname = '*';
}
$files = glob($rrd_path . '/' . $hostname . '/*.rrd');
$run = readline("Are you sure you want to run this command [N/y]: ");
if (!($run == 'y' || $run == 'Y')) {
echo "Exiting....." . PHP_EOL;
exit;
}
foreach ($files as $file) {
$random = $tmp_path.'/'.mt_rand() . '.xml';
$tmp = explode('/', $file);
$rrd_file = array_pop($tmp);
echo "Converting $file: ";
$command = "$rrdtool dump $file > $random &&
sed -i 's/<step>300/<step>$step/' $random &&
sed -i 's/<minimal_heartbeat>600/<minimal_heartbeat>$heartbeat/' $random &&
$rrdtool restore -f $random $file &&
rm -f $random";
exec($command, $output, $code);
if ($code === 0) {
echo "[OK]\n";
} else {
echo "\033[FAIL]\n";
}
}