1################################################## 2package Log::Log4perl::Appender::RRDs; 3################################################## 4our @ISA = qw(Log::Log4perl::Appender); 5 6use warnings; 7use strict; 8use RRDs; 9 10################################################## 11sub new { 12################################################## 13 my($class, @options) = @_; 14 15 my $self = { 16 name => "unknown name", 17 dbname => undef, 18 rrdupd_params => [], 19 @options, 20 }; 21 22 die "Mandatory parameter 'dbname' missing" unless 23 defined $self->{dbname}; 24 25 bless $self, $class; 26 27 return $self; 28} 29 30################################################## 31sub log { 32################################################## 33 my($self, %params) = @_; 34 35 #print "UPDATE: '$self->{dbname}' - '$params{message}'\n"; 36 37 RRDs::update($self->{dbname}, 38 @{$params{rrdupd_params}}, 39 $params{message}) or 40 die "Cannot update rrd $self->{dbname} ", 41 "with $params{message} ($!)"; 42} 43 441; 45 46__END__ 47 48=head1 NAME 49 50Log::Log4perl::Appender::RRDs - Log to a RRDtool Archive 51 52=head1 SYNOPSIS 53 54 use Log::Log4perl qw(get_logger); 55 use RRDs; 56 57 my $DB = "myrrddb.dat"; 58 59 RRDs::create( 60 $DB, "--step=1", 61 "DS:myvalue:GAUGE:2:U:U", 62 "RRA:MAX:0.5:1:120"); 63 64 print time(), "\n"; 65 66 Log::Log4perl->init(\qq{ 67 log4perl.category = INFO, RRDapp 68 log4perl.appender.RRDapp = Log::Log4perl::Appender::RRDs 69 log4perl.appender.RRDapp.dbname = $DB 70 log4perl.appender.RRDapp.layout = Log::Log4perl::Layout::PatternLayout 71 log4perl.appender.RRDapp.layout.ConversionPattern = N:%m 72 }); 73 74 my $logger = get_logger(); 75 76 for(10, 15, 20, 25) { 77 $logger->info($_); 78 sleep 1; 79 } 80 81=head1 DESCRIPTION 82 83C<Log::Log4perl::Appender::RRDs> appenders facilitate writing data 84to RRDtool round-robin archives via Log4perl. For documentation 85on RRD and its Perl interface C<RRDs> (which comes with the distribution), 86check out L<http://rrdtool.org>. 87 88Messages sent to Log4perl's RRDs appender are expected to be numerical values 89(ints or floats), which then are used to run a C<rrdtool update> command 90on an existing round-robin database. The name of this database needs to 91be set in the appender's C<dbname> configuration parameter. 92 93If there's more parameters you wish to pass to the C<update> method, 94use the C<rrdupd_params> configuration parameter: 95 96 log4perl.appender.RRDapp.rrdupd_params = --template=in:out 97 98To read out the round robin database later on, use C<rrdtool fetch> 99or C<rrdtool graph> for graphic displays. 100 101=head1 LICENSE 102 103Copyright 2002-2012 by Mike Schilli E<lt>m@perlmeister.comE<gt> 104and Kevin Goess E<lt>cpan@goess.orgE<gt>. 105 106This library is free software; you can redistribute it and/or modify 107it under the same terms as Perl itself. 108 109=head1 AUTHOR 110 111Please contribute patches to the project on Github: 112 113 http://github.com/mschilli/log4perl 114 115Send bug reports or requests for enhancements to the authors via our 116 117MAILING LIST (questions, bug reports, suggestions/patches): 118log4perl-devel@lists.sourceforge.net 119 120Authors (please contact them via the list above, not directly): 121Mike Schilli <m@perlmeister.com>, 122Kevin Goess <cpan@goess.org> 123 124Contributors (in alphabetical order): 125Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, Hutton 126Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony 127Foiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, Andy 128Grundman, Paul Harrington, David Hull, Robert Jacobson, Jason Kohles, 129Jeff Macdonald, Markus Peter, Brett Rann, Peter Rabbitson, Erik 130Selberg, Aaron Straup Cope, Lars Thegler, David Viner, Mac Yang. 131 132