# # Platon::Log::Accounting::Process.pm # # Developed by Lubomir Host 'rajo' # Copyright (c) 2004 Platon SDG, http://platon.sk/ # Licensed under terms of GNU General Public License. # All rights reserved. # # Changelog: # 2005-02-20 - created # # $Platon: perl-modules/Platon/Log/Mail/Postfix.pm,v 1.10 2004/12/09 18:09:53 rajo Exp $ package Platon::Log::Accounting::Process; use strict; use vars qw($VERSION $DEBUG); use base qw( Platon::Log ); use Carp; use Platon::DBI; use Date::Parse; use Date::Format; $VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/); $DEBUG = 0 unless defined $DEBUG; # # this saves postfix error message into MySQL # sub savelog($$;) { # {{{ my ($self, $line) = @_; my $xx = { }; my $created; ($xx->{command}, $xx->{user_time}, $xx->{system_time}, $xx->{effective_time}, $xx->{uid}, $xx->{gid}, $xx->{memory}, $xx->{io}, $created) = split(/\|/, $line); $xx->{created} = time2str('%Y-%m-%dT%X%z', str2time($created)); return 0 unless defined($xx->{created}); foreach my $key (qw( command user_time system_time effective_time uid gid memory io )) { $xx->{$key} =~ s/\s//go; } $self->{dbh}->check(); $self->{sql_insert}->execute( $xx->{created}, $xx->{command}, $xx->{user_time}, $xx->{system_time}, $xx->{effective_time}, $xx->{uid}, $xx->{gid}, $xx->{memory}, $xx->{io} ) or warn $self->{sql_insert}->errstr; } # }}} # this method must be defined in your own Platon::Log::ServiceType::YourService module sub _init($$;) { # {{{ my ($self, $conf) = @_; # DEBUG code: remove all rows from db for testing purposes #$self->prepare_keyword('sql_delete', "DELETE FROM " . $conf->table); #$self->{sql_delete}->execute(); $self->prepare_keyword('sql_insert', " INSERT INTO " . $conf->table . " (created, command, user_time, system_time, effective_time, uid, gid, memory, io ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) "); } # }}} 1; __END__ =head1 NAME Platon::Log::Accounting::Process - Process accounting infromation parser =head1 SYNOPSIS use Platon::Log::Accounting::Process; my $xxx = new Platon::Log::Accounting::Process; =head1 DESCRIPTION The Platon::Log::Accounting::Process module stores process accounting information into MySQL database. Pipe output from dump-acct into pacct-savelog-mysql.pl script: dump-acct [pacct-log] | pacct-savelog-mysql.pl =head2 EXPORT =head1 SEE ALSO =head1 AUTHORS Lubomir Host 'rajo', =cut # vim: ts=4 # vim600: fdm=marker fdl=0 fdc=3