8. my $fluent_logger = Fluent::Logger->new(...);
my $hostname = `hostname`; chomp $hostname;
sub logger {
my ($level, $message) = @_;
my(undef, $file, $line) = caller(0);
my $content = "[$level] $message at $file line $line";
# ... ファイルにくI尖 ...
# fluentdに畠何誘げちゃうど
$fluent_logger->post('foo.applog', {
level => $level,
file => $file,
line => $line,
host => $hostname,
message => $message,
});
}
やること1
9. SELECT level, file, line, LAST(host) AS host, LAST
(message) AS message, COUNT(*) AS count
FROM foo_applog.win:time_batch(5 min)
WHERE level IN ('error', 'critical')
GROUP BY level, file, line
やること2
11. #!/usr/bin/env perl
use strict;
use warnings;
use Foo; # project class
use Norikra::Client;
my $IntervalMinutes = 5;
my $c = Foo->bootstrap;
my $norikra = Norikra::Client->new('norikra.server.address', 26571);
my $query_name = "foo_errors_in_${IntervalMinutes}min";
my $events = $norikra->event($query_name);
for my $event (@$events) {
my ($time, $log) = @$event;
next if $log->{count} == 0;
my $msg = "[$log->{host}][$level] $log->{message} at $log->{file} line $log->{line}";
if ($log->{count} > 1) {
my $count = $log->{count} - 1;
$msg .= " ... and $count more similar logs in this $IntervalMinutes minutes";
}
$c->ikachan($msg); # post to IRC via ikachan
}
norikra-error-notify.pl