#!/usr/bin/perl # dsaddtor.pl, Program to add datasources to an existing RRD # # Copyright (C) 2010 R. Sandevoir remi.sandevoir(at)gmail.com # # 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 use strict; use warnings; use RRD::Simple (); my $rrdfile = shift || &Usage; if ($rrdfile eq '-h') { &Usage; exit 0; } my $name = shift || &Usage; my $type = shift || 'COUNTER'; my $heartbeat = shift || '600'; my $min = shift || 'NaN'; my $max = shift || 'NaN'; my $rrd = RRD::Simple->new( file => $rrdfile, rrdtool => "/usr/bin/rrdtool", ); print "Adding DS $name on $rrdfile\n"; $rrd->add_source($rrdfile, $name => $type); print "Heartbeat : $heartbeat\nMinimum value : $min\nMaximum value : $max\n"; RRDs::tune ($rrdfile, "-h","$name:$heartbeat"); RRDs::tune ($rrdfile, "-i","$name:$min"); RRDs::tune ($rrdfile, "-a","$name:$max"); sub Usage { print "dsaddtor.pl [type] [heartbeat] [rrdmin] [rrdmax]\n"; print "\t\tSource RRD file\n"; print "\t\tDatasource name to add\n"; print "\t[type]\t\tType of datasource (i.e. COUNTER, GAUGE...). Default : COUNTER\n"; print "\t[heartbeat]\tLength of time in seconds before RRD thinks your DS is dead. Default : 600\n"; print "\t[rrdmin]\tMinimum value allowed for each datasource. Default : NaN\n"; print "\t[rrdmax]\tMax value allowed for each datasource. Default : NaN\n"; exit 0 }