]> Sergey Matveev's repositories - dmon.git/commitdiff
Aggregate inside DTrace
authorSergey Matveev <stargrave@stargrave.org>
Tue, 6 Sep 2022 21:27:12 +0000 (00:27 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 6 Sep 2022 21:27:12 +0000 (00:27 +0300)
dmon.pl

diff --git a/dmon.pl b/dmon.pl
index 885d9b2af6367487944fee0f6138e8a18d1ea3d8..161622894982b2709caeb6ca178a6b6b81f52933 100755 (executable)
--- a/dmon.pl
+++ b/dmon.pl
@@ -39,16 +39,28 @@ if ($ARGV[0] eq "tcp") {
         print $dfh "
 $probe
 {
         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_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";
     };
 }\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) = @_;
 } else {
     sub ipprobe {
         my ($probe, $dir) = @_;
@@ -57,15 +69,26 @@ $probe
 $probe
 /$conds/
 {
 $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";
     };
 }\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;
 };
 
 my $height = (defined $ENV{DMON_HEIGHT}) ? $ENV{DMON_HEIGHT} : 40;
@@ -115,7 +138,7 @@ unlink $dfn;
 
 my $xx;
 while (<$dexec>) {
 
 my $xx;
 while (<$dexec>) {
-    next unless /^[<>T]/;
+    next unless /^[<>TIO]/;
     my @cols = split;
     if ($cols[0] eq "T") {
         my @res;
     my @cols = split;
     if ($cols[0] eq "T") {
         my @res;
@@ -138,6 +161,15 @@ while (<$dexec>) {
             write STDOUT;
         };
         (%rx, %tx) = (), ();
             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 "<") {
         next;
     };
     if ($cols[0] eq "<") {