diff --git a/README.md b/README.md index 8ae8008..8b6e352 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # rrdtool +RRD (Round Robin Database) is a system to store and display time-series data (i.e. network bandwidth, machine-room temperature, server load average). +It stores the data in a very compact way that will not expand over time, and it presents useful graphs by processing the data to enforce a certain data density. +It can be used either via simple wrapper scripts (from shell or Perl) or via frontends that poll network devices and put a friendly user interface on it. + diff --git a/rrdtool-log2rrd.pl b/rrdtool-log2rrd.pl new file mode 100644 index 0000000..7c238ce --- /dev/null +++ b/rrdtool-log2rrd.pl @@ -0,0 +1,231 @@ +#! /usr/bin/perl +# +# Log 2 RRD. This script translates a MRTG 2.x log file +# into a RRD archive. The original version was written by +# Wrolf Courtney and +# Russ Wright with an early test version +# of RRDTOOL (mrtg-19980526.08) and has been modified to match +# the parameters of rrdtool version 99.23 by Alan Lichty at +# Electric Lightwave, Inc. . +# +# this script optimized for being called up by another script +# that cycles through a list of routers and invokes this for each +# interface. It can be run just as easily from a command line for +# small numbers of logfiles. +# +# The RRD we create looks like the following: Note +# that we have to use type GAUGE in order to have RRDTOOL +# populate the new rr archive correctly. Otherwise RRDTOOL will try +# to interpet the data as new octet counts instead of existing +# data rate averages. +# +# DS:GAUGE:86400:U:U # in counter +# DS:GAUGE:86400:U:U # out counter +# RRA:AVERAGE:0.5:1:600 # 5 minute samples +# RRA:MAX:0.5:1:600 # 5 minute samples +# RRA:AVERAGE:0.5:6:600 # 30 minute samples +# RRA:MAX:0.5:6:600 # 30 minute samples +# RRA:AVERAGE:0.5:24:600 # 2 hour samples +# RRA:MAX:0.5:24:600 # 2 hour samples +# RRA:AVERAGE:0.5:288:732 # 1 day samples +# RRA:MAX:0.5:288:732 # 1 day samples +# +# + +use English; +use strict; + +require "ctime.pl"; + +use RRDs; + +my $DEBUG=0; + +&main; + +sub main { + + my($inBytes, $outBytes); + my($lastRunDate, $firstRunDate); + my($i, $dataFile, $firstRun); + my($oldestRun, $lastRun); + my($curTime, $oldestTime, $totRec); + my($avgIn, $avgOut, $maxIn, $maxOut); + my(@lines, @finalRecs); + my($RRD, $START, $destDir, $dsType); + +# +# get the logfile name to process +# the default is to strip out the .log extension and create +# a new file with the extension .rrd +# + + $dataFile=$ARGV[0]; + + $destDir = $ARGV[1]; + +# +# strip off .log from file name - complain and die if no .log +# in the filename +# + + if ($dataFile =~ /(.*)\.log$/) { + $RRD = "$1"; + } + + if ($RRD eq "") { + printf("Usage: log2rrd [log file] [destination dir]\n"); + exit; + } + +# +# strip out path info (if present) to get at just the filename +# + + if ($RRD =~ /(.*)\/(.*)$/){ + $RRD = "$2"; + } + +# +# add the destination path (if present) and .rrd suffix +# + + if ($destDir){ + $RRD = "$destDir/$RRD.rrd"; + + }else{ + $RRD = "$RRD.rrd"; + } + + open(IN,"$dataFile") || die ("Couldn't open $dataFile"); + +# +# Get first line - has most current sample +# + + $_ = ; + chop; + ($lastRun, $inBytes, $outBytes) = split; + $lastRunDate = &ctime($lastRun); + chop $lastRunDate; + + $firstRun = $lastRun; + $i=2; + +# +# start w/line 2 and read them into the lines array +# (2nd line is in position 2) +# + while () { + chop; + $lines[$i++] = $_; + ($curTime) = split; + if ($curTime < $firstRun) { + $firstRun = $curTime; + } + } + close(IN); + +# +# Let's say source start time is 5 minutes before 1st sample +# + + $START=$firstRun - 300; + print STDERR "\$START = $START\n" if $DEBUG>1; + + $firstRunDate = &ctime($firstRun); + chop $firstRunDate; + + printf("Data from $firstRunDate\n to $lastRunDate\n") if $DEBUG>0; + + $oldestTime=$lastRun; +# +# OK- sort through the data and put it in a new array. +# This gives us a chance to find errors in the log files and +# handles any overlap of data (there shouldn't be any) +# +# NOTE: We start w/ record # 3, not #2 since #2 could be partial +# + + for ($i=3; $i <= 2533; $i++) { + + ($curTime, $avgIn, $avgOut, $maxIn, $maxOut) = split(/\s+/, $lines[$i]); + + if ($curTime < $oldestTime) { + +# +# only add data if older than anything already in array +# this should always be true, just checking +# + + $oldestTime = $curTime; + $finalRecs[$totRec++]=$lines[$i]; + } + } + + + PopulateRRD($totRec, $RRD, $START, \@finalRecs); + +# +# if you know that most of your MRTG logfiles are using +# counter data, uncomment the following lines to automatically +# run rrdtune and change the data type. +# +# my(@tuneparams) = ("$RRD", "-d", "ds0:COUNTER", "-d", "ds1:COUNTER"); +# RRDs::tune(@tuneparams); + + +} + +sub PopulateRRD { + + my($totRec, $RRD, $START, $finalRecs) = @_; + my($i, $curTime, $avgIn, $avgOut, $maxIn, $maxOut); + my($saveReal, $line); + my($createret, $updret); + + print "* Creating RRD $RRD\n\n" if $DEBUG>0; + +# +# We'll create RRAs for both AVG and MAX. MAX isn't currently filled but +# may be later +# + + RRDs::create ("$RRD", "-b", $START, "-s", 300, + "DS:ds0:GAUGE:86400:U:U", + "DS:ds1:GAUGE:86400:U:U", + "RRA:AVERAGE:0.5:1:600", + "RRA:MAX:0.5:1:600", + "RRA:AVERAGE:0.5:6:600", + "RRA:MAX:0.5:6:600", + "RRA:AVERAGE:0.5:24:600", + "RRA:MAX:0.5:24:600", + "RRA:AVERAGE:0.5:288:600", + "RRA:MAX:0.5:288:600"); + + if (my $error = RRDs::error()) { + print "Cannot create $RRD: $error\n"; + } + + + print "* Adding entries to $RRD\n\n" if $DEBUG>0; + + for ($i=$totRec - 1; $i >= 0; $i--) { + + ($curTime, $avgIn, $avgOut, $maxIn, $maxOut) = split(/\s+/, @$finalRecs[$i]); + + RRDs::update ("$RRD", "$curTime:$avgIn:$avgOut"); + + if (my $error = RRDs::error()) { + print "Cannot update $RRD: $error\n"; + } + + +# NOTE: Need to add checking on RRDread and include the Max values +# print status every now and then +# print $i if $i % 25 && $DEBUG>0; +# print "$i\n"; + + } + +} diff --git a/rrdtool.spec b/rrdtool.spec new file mode 100644 index 0000000..e4e8ffd --- /dev/null +++ b/rrdtool.spec @@ -0,0 +1,248 @@ +%define rrddocdir %{_datadir}/doc/%{name}-%{version} + +Name: rrdtool +Version: 1.4.7 +Release: 2mamba +Summary: Round Robin Database Tool to store and display time-series data +Group: Applications/Databases +Vendor: openmamba +Distribution: openmamba +Packager: Silvan Calarco +URL: http://oss.oetiker.ch/rrdtool/ +Source0: http://oss.oetiker.ch/rrdtool/pub/rrdtool-%{version}.tar.gz +Source1: rrdtool-log2rrd.pl +License: GPL +## AUTOBUILDREQ-BEGIN +BuildRequires: glibc-devel +BuildRequires: libbzip2-devel +BuildRequires: libcairo-devel +BuildRequires: libdbi-devel +BuildRequires: libexpat-devel +BuildRequires: libffi-devel +BuildRequires: libfontconfig-devel +BuildRequires: libfreetype-devel +BuildRequires: libglib-devel +BuildRequires: libgraphite2-devel +BuildRequires: libharfbuzz-devel +BuildRequires: liblzma-devel +BuildRequires: libpango-devel +BuildRequires: libpng-devel +BuildRequires: libpython-devel +BuildRequires: libpython27-devel +BuildRequires: libwrap-devel +BuildRequires: libxml2-devel +BuildRequires: libz-devel +BuildRequires: perl-devel +BuildRequires: ruby-devel +## AUTOBUILDREQ-END +BuildRequires: libcgi-devel >= 0.5 +BuildRequires: pkgconfig >= 0.10 +BuildRequires: python +BuildRequires: groff +BuildRequires: libtcl >= 8.4.11 +BuildRoot: %{_tmppath}/%{name}-%{version}-root + +%description +RRD (Round Robin Database) is a system to store and display time-series data (i.e. network bandwidth, machine-room temperature, server load average). +It stores the data in a very compact way that will not expand over time, and it presents useful graphs by processing the data to enforce a certain data density. +It can be used either via simple wrapper scripts (from shell or Perl) or via frontends that poll network devices and put a friendly user interface on it. + +%package lua +Summary: LUA RRDtool bindings +Group: Development/Bindings +Requires: %{name} = %{version}-%{release} + +%description lua +RRD (Round Robin Database) is a system to store and display time-series data (i.e. network bandwidth, machine-room temperature, server load average). +It stores the data in a very compact way that will not expand over time, and it presents useful graphs by processing the data to enforce a certain data density. +It can be used either via simple wrapper scripts (from shell or Perl) or via frontends that poll network devices and put a friendly user interface on it. + +This package contains the LUA RRDtool bindings. + +%package perl +Summary: Perl RRDtool bindings +Group: Development/Libraries/Perl +Requires: %{name} = %{version}-%{release} + +%description perl +RRD (Round Robin Database) is a system to store and display time-series data (i.e. network bandwidth, machine-room temperature, server load average). +It stores the data in a very compact way that will not expand over time, and it presents useful graphs by processing the data to enforce a certain data density. +It can be used either via simple wrapper scripts (from shell or Perl) or via frontends that poll network devices and put a friendly user interface on it. + +This package contains the perl RRDtool bindings. + +%package python +Summary: Python RRDtool bindings +Group: Development/Bindings +Requires: %{name} = %{version}-%{release} + +%description python +RRD (Round Robin Database) is a system to store and display time-series data (i.e. network bandwidth, machine-room temperature, server load average). +It stores the data in a very compact way that will not expand over time, and it presents useful graphs by processing the data to enforce a certain data density. +It can be used either via simple wrapper scripts (from shell or Perl) or via frontends that poll network devices and put a friendly user interface on it. + +This package contains the python RRDtool bindings. + +%package ruby +Summary: Ruby RRDtool bindings +Group: Development/Bindings +Requires: %{name} = %{version}-%{release} + +%description ruby +RRD (Round Robin Database) is a system to store and display time-series data (i.e. network bandwidth, machine-room temperature, server load average). +It stores the data in a very compact way that will not expand over time, and it presents useful graphs by processing the data to enforce a certain data density. +It can be used either via simple wrapper scripts (from shell or Perl) or via frontends that poll network devices and put a friendly user interface on it. + +This package contains the ruby RRDtool bindings. + +%package devel +Summary: RRDtool static libraries and headers +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} +Requires: %{name}-lua = %{version}-%{release} + +%description devel +RRD (Round Robin Database) is a system to store and display time-series data (i.e. network bandwidth, machine-room temperature, server load average). +It stores the data in a very compact way that will not expand over time, and it presents useful graphs by processing the data to enforce a certain data density. +It can be used either via simple wrapper scripts (from shell or Perl) or via frontends that poll network devices and put a friendly user interface on it. + +This package allow you to use directly this library. + +%prep +%setup -q + +%build +%configure \ + --enable-shared \ + --enable-perl-site-install \ + --with-perl-options='INSTALLDIRS="vendor"' \ + --with-ruby-options='sitedir="%{_libdir}/ruby/site_ruby"' +# --with-tcllib=%{_libdir} + +%make -j1 + +#cd examples +#find . -name "*.pl" -exec perl -e 's;\015;;gi' -p -i \{\} \; + +%install +[ "%{buildroot}" != / ] && rm -rf "%{buildroot}" +%makeinstall RRDDOCDIR=%{rrddocdir} + +install -D -m755 %{SOURCE1} %{buildroot}%{_bindir}/log2rrd.pl + +install -m644 {C*,README,TODO} %{buildroot}%{rrddocdir} + +# remove unpackaged files +find %{buildroot}%{_prefix}/lib -name perllocal.pod -exec rm -f {} \; +find %{buildroot}%{_prefix}/lib -name .packlist -exec rm -f {} \; + +# log2rrd.pl requires perl(ctime.pl) missing in perl 5.16 +rm -f %{buildroot}%{_bindir}/log2rrd.pl + +%clean +[ "%{buildroot}" != / ] && rm -rf "%{buildroot}" +rm -f %{name}-%{version}-file + +%post -p /sbin/ldconfig +%postun -p /sbin/ldconfig + +%files +%defattr(-,root,root) +%{_bindir}/* +%{_libdir}/*.so.* +%{_libdir}/rrdtool/ifOctets.tcl +%{_libdir}/rrdtool/pkgIndex.tcl +%dir %{_datadir}/rrdtool +%dir %{_datadir}/rrdtool/examples +%{_datadir}/rrdtool/examples/* +#%dir %{_datadir}/rrdtool/fonts +#%{_datadir}/rrdtool/fonts/DejaVuSansMono-Roman.ttf +%dir %{rrddocdir} +%{_defaultdocdir}/%{name}-%{version}/C* +%{_defaultdocdir}/%{name}-%{version}/README +%{_defaultdocdir}/%{name}-%{version}/TODO +%{rrddocdir}/html/* +%{rrddocdir}/txt/* +%{_mandir}/man1/* +%{_mandir}/man3/librrd.3.* + +%files lua +%defattr(-,root,root) +# FIXME: doesn't build with lua 5.2 +#%{_libdir}/lua/*/rrd.so.* + +%files perl +%defattr(-,root,root) +%{_mandir}/man3/RRDp.3pm.* +%{_mandir}/man3/RRDs.3pm.* +%{perl_vendorlib}/* + +%files python +%defattr(-,root,root) +%{python_sitearch}/py_rrdtool-*-py%{python_version}.egg-info +%{python_sitearch}/rrdtoolmodule.so + +%files ruby +%defattr(-,root,root) +%{ruby_sitearch}/RRD.so + +%files devel +%defattr(-,root,root) +%{_libdir}/*.a +%{_libdir}/*.la +%{_libdir}/*.so +#%{_libdir}/ruby/*/i586-linux/RRD.so +%{_libdir}/pkgconfig/librrd.pc +%{_includedir}/*.h +#%{_libdir}/lua/*/rrd.a +#%{_libdir}/lua/*/rrd.la +#%{_libdir}/lua/*/rrd.so + +%changelog +* Mon Nov 12 2012 Silvan Calarco 1.4.7-2mamba +- perl 5.16 rebuild + +* Wed Aug 08 2012 Automatic Build System 1.4.7-1mamba +- automatic version update by autodist + +* Fri Jan 20 2012 Automatic Build System 1.4.6-1mamba +- automatic version update by autodist + +* Mon Jan 03 2011 Automatic Build System 1.4.5-1mamba +- automatic update by autodist + +* Mon Jul 12 2010 Automatic Build System 1.4.4-1mamba +- automatic update by autodist + +* Sat Apr 17 2010 Automatic Build System 1.4.3-1mamba +- automatic update by autodist + +* Mon Jan 18 2010 Automatic Build System 1.4.2-1mamba +- automatic update by autodist + +* Tue Jun 09 2009 Automatic Build System 1.3.8-1mamba +- automatic update by autodist + +* Thu Apr 16 2009 Silvan Calarco 1.3.7-1mamba +- automatic update by autodist + +* Sun Mar 08 2009 Silvan Calarco 1.3.6-1mamba +- automatic update by autodist + +* Fri Jan 02 2009 Silvan Calarco 1.3.5-1mamba +- automatic update by autodist + +* Thu Nov 06 2008 Silvan Calarco 1.3.4-1mamba +- automatic update by autodist + +* Wed Sep 06 2006 Davide Madrisan 1.2.15-1qilnx +- update to version 1.2.15 by autospec + +* Wed Oct 05 2005 Davide Madrisan 1.2.11-1qilnx +- update to version 1.2.11 by autospec +- run ldconfig to update library db +- specfiles updates and fixes +- new packages rrdtool-perl, rrdtool-python + +* Thu Jul 14 2004 Davide Madrisan 1.0.48-1qilnx +- first build