From: Sergey Matveev Date: Tue, 6 Sep 2022 21:27:12 +0000 (+0300) Subject: Aggregate inside DTrace X-Git-Url: http://www.git.stargrave.org/?p=dmon.git;a=commitdiff_plain;h=0c43c2cb5927fe6ee5619b4726da4c247373c9c9 Aggregate inside DTrace --- diff --git a/dmon.pl b/dmon.pl index 885d9b2..1616228 100755 --- a/dmon.pl +++ b/dmon.pl @@ -39,16 +39,28 @@ if ($ARGV[0] eq "tcp") { print $dfh " $probe { - printf(\"$dir [%s]:%d [%s]:%d %d\\n\", - args[2]->ip_saddr, + @" . $dir . "[args[2]->ip_saddr, args[4]->tcp_sport, args[2]->ip_daddr, - args[4]->tcp_dport, - args[2]->ip_plength); + args[4]->tcp_dport] = sum(args[2]->ip_plength); + " . $dir . "pkts++; }\n"; }; - tcpprobe "tcp:::send", ">"; - tcpprobe "tcp:::receive", "<"; + tcpprobe "tcp:::send", "tx"; + tcpprobe "tcp:::receive", "rx"; + print $dfh ' +profile:::tick-1sec +{ + printa("< [%s]:%d [%s]:%d %@d\n", @rx); + clear(@rx); + printa("> [%s]:%d [%s]:%d %@d\n", @tx); + clear(@tx); + printf("I %d\n", rxpkts); + printf("O %d\n", txpkts); + rxpkts = 0; + txpkts = 0; + printf("T\n"); +}'; } else { sub ipprobe { my ($probe, $dir) = @_; @@ -57,15 +69,26 @@ $probe $probe /$conds/ { - printf(\"$dir %s %s %d %s\\n\", - args[2]->ip_saddr, - args[2]->ip_daddr, - args[2]->ip_plength, - args[3]->if_name); + @" . $dir . "[args[2]->ip_saddr, + args[2]->ip_daddr] = sum(args[2]->ip_plength); + " . $dir . "pkts++; }\n"; }; - ipprobe "ip:::send", ">"; - ipprobe "ip:::receive", "<"; + ipprobe "ip:::send", "tx"; + ipprobe "ip:::receive", "rx"; + print $dfh ' +profile:::tick-1sec +{ + printa("< %s %s %@d\n", @rx); + clear(@rx); + printa("> %s %s %@d\n", @tx); + clear(@tx); + printf("I %d\n", rxpkts); + printf("O %d\n", txpkts); + rxpkts = 0; + txpkts = 0; + printf("T\n"); +}'; }; my $height = (defined $ENV{DMON_HEIGHT}) ? $ENV{DMON_HEIGHT} : 40; @@ -115,7 +138,7 @@ unlink $dfn; my $xx; while (<$dexec>) { - next unless /^[<>T]/; + next unless /^[<>TIO]/; my @cols = split; if ($cols[0] eq "T") { my @res; @@ -138,6 +161,15 @@ while (<$dexec>) { write STDOUT; }; (%rx, %tx) = (), (); + ($pktsRx, $pktsTx, $bytesRx, $bytesTx) = (0, 0, 0, 0); + next; + }; + if ($cols[0] eq "I") { + $pktsRx += $cols[1]; + next; + }; + if ($cols[0] eq "O") { + $pktsTx += $cols[1]; next; }; if ($cols[0] eq "<") {