summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2013-11-09 23:12:23 +0000
committerGabor X Toth <*@tg-x.net>2013-11-09 23:12:23 +0000
commitd10808d7f17c5f6f1356c22ef0992965cbaf5ce1 (patch)
tree2aa315f5a56ee9fa5853201658390a41f38669ce /contrib
parent383a9603f7310b3156331a1ed9cc97cc6ed4d3a9 (diff)
logread: ipc message monitoring
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/logread-ipc-sdedit.pl59
-rwxr-xr-xcontrib/logread-ipc.sh5
-rwxr-xr-xcontrib/logread.pl56
3 files changed, 120 insertions, 0 deletions
diff --git a/contrib/logread-ipc-sdedit.pl b/contrib/logread-ipc-sdedit.pl
new file mode 100755
index 000000000..e482eee30
--- /dev/null
+++ b/contrib/logread-ipc-sdedit.pl
@@ -0,0 +1,59 @@
+#!/usr/bin/env perl
+
+# 1. Start sdedit and enable 'RT diagram server' in 'Global preferences'.
+#
+# 2. Start this tool (see defaults below):
+# gnunet-logread-ipc-sdedit -n buffer-name -i /path/to/ipc.sock -h <sdedit-host> -p <sdedit-port>
+#
+# 3. Start a gnunet-logread instance for each component with the -n <component_name> option
+
+use strict;
+use warnings;
+
+use Getopt::Std;
+use IO::Socket::INET;
+use POSIX qw(mkfifo);
+
+my %opts;
+getopts ('i:n:h:p:', \%opts);
+
+my $ipc = $opts{i} || '/tmp/gnunet-logread-ipc.sock';
+my $name = $opts{n} || 'gnunet';
+my $host = $opts{h} || 'localhost';
+my $port = $opts{p} || 16001;
+my %svcs = map { $_ => 1 } @ARGV;
+
+my $sdedit = IO::Socket::INET->new(PeerAddr => $host,
+ PeerPort => $port,
+ Proto => 'tcp')
+ or die "Cannot connect to $host:$port: $!\n";
+
+print $sdedit "$name\n";
+print $sdedit "_t:time[e]\n";
+print $sdedit "$_:$_\[ap\] \"$_\"\n" for @ARGV;
+print $sdedit "_e:ext[e]\n";
+print $sdedit "\n";
+
+mkfifo $ipc, 0600 or die "$ipc: $!\n" unless -e $ipc;
+open IPC, '<', $ipc or die "$ipc: $!\n";
+while (<IPC>)
+{
+ print;
+ my ($time, $from, $to, $msg, $svc);
+ if (my ($time, $from, $to, $msg) =
+ /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\s+
+ (\S+)\s+ -> \s+(\S+)\s+ (\S+\s+ \(\d+\))/x)
+ {
+ $from = '_e' unless exists $svcs{$from};
+ $to = '_e' unless exists $svcs{$to};
+ print $sdedit "*0 _t\n$time\n*0\n", "$from:$to.$msg\n"
+ }
+ elsif (($time, $svc, $msg) =
+ /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\s+
+ (\S+)\s+(.+)/x)
+ {
+ print $sdedit "*0 _t\n$time\n*0\n", "*0 $svc\n$msg\n*0\n"
+ }
+}
+
+close IPC;
diff --git a/contrib/logread-ipc.sh b/contrib/logread-ipc.sh
new file mode 100755
index 000000000..a986c629f
--- /dev/null
+++ b/contrib/logread-ipc.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+ipc=${1:-/tmp/gnunet-logread-ipc.sock}
+test -e "$ipc" || mkfifo "$ipc"
+cat "$ipc"
diff --git a/contrib/logread.pl b/contrib/logread.pl
index a72f7232d..c6f82a68d 100755
--- a/contrib/logread.pl
+++ b/contrib/logread.pl
@@ -3,13 +3,25 @@
# Usage:
# gnunet-service |& gnunet-logread
# gnunet-logread service.log
+#
+# Options:
+# -n <component_name> Name of this component to use for IPC logging.
+# -i </path/to/ipc.sock> Path to IPC logging socket.
+# Passing on log messages to IPC socket:
+# -L <LOGLEVEL> Minimum level of messages to pass on.
+# Log levels: NONE, ERROR, WARNING, INFO, DEBUG.
+# -m <regex> Only pass on messages matching a regular expression.
use strict;
use warnings;
+use Getopt::Std;
use Term::ANSIColor qw(:constants :pushpop);
$Term::ANSIColor::AUTOLOCAL = 1;
+my (%opts, $name, $ipc, $msg_level, $msg_regex);
+getopts ('n:i:L:m:', \%opts);
+
# Message type numbers to names
my %msgtypes;
my $prefix = $ENV{GNUNET_PREFIX} || '/usr';
@@ -28,8 +40,50 @@ else
warn "$filename: $!, try setting \$GNUNET_PREFIX";
}
+my %levels = ( NONE => 0, ERROR => 1, WARNING => 2, INFO => 4, DEBUG => 8 );
+if (exists $opts{n})
+{
+ $name = $opts{n};
+ $ipc = $opts{i} || '/tmp/gnunet-logread-ipc.sock';
+ $msg_level = exists $levels{$opts{L}} ? $levels{$opts{L}} : 0;
+ $msg_regex = $opts{m};
+ print STDERR "RE: /$msg_regex/\n";
+ open IPC, '>', $ipc or die "$ipc: $!\n";
+}
+
while (<>)
{
+ if (fileno IPC) {
+ my ($time, $type, $size, $from, $to, $level, $msg);
+ if (($time, $type, $size, $from, $to) =
+ /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\ util-.*\b
+ (?: Received | Transmitting )\ message \b.*?\b
+ type \s+ (\d+) \b.*?\b
+ size \s+ (\d+) \b.*?\b
+ (?: from \s+ (\S+)
+ | to \s+ (\S+) ) /x)
+ {
+ $from ||= $name;
+ $to ||= $name;
+ my ($time, $type, $size, $from, $to) = ($1, $2, $3,
+ $4 || $name, $5 || $name);
+ my $msg = exists $msgtypes{$type} ? $msgtypes{$type} : $type;
+ my $ofh = select IPC;
+ print IPC "$time\t$from -> $to\t$msg ($size)\n";
+ $|++;
+ select $ofh;
+ }
+ if (($time, $level, $msg) =
+ /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)
+ \s+\S+\s+(\S+)\s+(.+)/x
+ and (exists $levels{$level}
+ && $levels{$level} <= $msg_level
+ && (!defined $msg_regex || $msg =~ /$msg_regex/i)))
+ {
+ print IPC "$time\t$name\t$level: $msg\n";
+ }
+ }
+
# Timestamp (e.g. Nov 01 19:36:11-384136)
s/^([A-Z][a-z]{2} .[0-9] [0-9:]{8}(?:-[0-9]{6})?)/YELLOW $1/e;
@@ -50,3 +104,5 @@ while (<>)
print;
}
+
+fileno IPC and close IPC;