Commit 38c82737 authored by Mike Hibler's avatar Mike Hibler

Break out send and receive for packets/bytes.

parent 00f5daaa
#!/usr/bin/perl -w #!/usr/bin/perl -w
# #
# Copyright (c) 2017 University of Utah and the Flux Group. # Copyright (c) 2017-2018 University of Utah and the Flux Group.
# #
# {{{EMULAB-LICENSE # {{{EMULAB-LICENSE
# #
...@@ -133,6 +133,7 @@ my $rateivs = 1; ...@@ -133,6 +133,7 @@ my $rateivs = 1;
my $maillast = 0; my $maillast = 0;
my $mailsent = 0; my $mailsent = 0;
my @mailbody = (); my @mailbody = ();
my @maildetails = ();
# Set this to turn off tblog in libraries. # Set this to turn off tblog in libraries.
$ENV{'TBLOG_OFF'} = "yep"; $ENV{'TBLOG_OFF'} = "yep";
...@@ -212,6 +213,9 @@ $svar = "cnetwatch/mail_interval"; ...@@ -212,6 +213,9 @@ $svar = "cnetwatch/mail_interval";
if (TBGetSiteVar($svar, \$tmp)) { if (TBGetSiteVar($svar, \$tmp)) {
if ($tmp >= 0) { if ($tmp >= 0) {
$MAIL_IV = $tmp; $MAIL_IV = $tmp;
if ($MAIL_IV > 0) {
$sendmail = 1;
}
} else { } else {
print STDERR "WARNING: invalid value for $svar sitevar, ignored.\n"; print STDERR "WARNING: invalid value for $svar sitevar, ignored.\n";
} }
...@@ -452,6 +456,8 @@ sub sortem($$) ...@@ -452,6 +456,8 @@ sub sortem($$)
# #
# Check for prolonged high traffic volumes from nodes. # Check for prolonged high traffic volumes from nodes.
# Counts: 0==s-bytes, 1==s-uni, 2==s-multi, 3==s-broad
# 4==r-bytes, 5==r-uni, 6==r-multi, 7==r-broad
# #
sub reportevents($) sub reportevents($)
{ {
...@@ -468,13 +474,20 @@ sub reportevents($) ...@@ -468,13 +474,20 @@ sub reportevents($)
} }
my $secs = $ref->{'tstamp'}; my $secs = $ref->{'tstamp'};
my @counts = @{$ref->{$node}{'counts'}}; my @counts = @{$ref->{$node}{'counts'}};
my $pps = $counts[1] + $counts[2] + $counts[3] +
$counts[5] + $counts[6] + $counts[7]; my $spkts = $counts[1] + $counts[2] + $counts[3];
my $bps = $counts[0] + $counts[4]; my $rpkts = $counts[5] + $counts[6] + $counts[7];
my $sbytes = $counts[0];
my $rbytes = $counts[4];
$secs += $rates{$node}{'elapsed'}; $secs += $rates{$node}{'elapsed'};
$pps += $rates{$node}{'pkts'}; $spkts += $rates{$node}{'spkts'};
$bps += $rates{$node}{'bytes'}; $rpkts += $rates{$node}{'rpkts'};
$sbytes += $rates{$node}{'sbytes'};
$rbytes += $rates{$node}{'rbytes'};
my $pkts = $spkts + $rpkts;
my $bytes = $sbytes + $rbytes;
# #
# XXX right now we do discrete intervals, we could do a sliding # XXX right now we do discrete intervals, we could do a sliding
...@@ -487,11 +500,18 @@ sub reportevents($) ...@@ -487,11 +500,18 @@ sub reportevents($)
my $ideal = ($rateivs * $interval); my $ideal = ($rateivs * $interval);
logit("elapsed: actual=$sec, ideal=$ideal"); logit("elapsed: actual=$sec, ideal=$ideal");
} }
$pps = int($pps / $sec); my $pps = int($pkts / $sec);
$bps = int($bps * 8 / $sec); my $bps = int($bytes * 8 / $sec);
if (($MAX_PPS && $pps > $MAX_PPS) || if (($MAX_PPS && $pps > $MAX_PPS) ||
($MAX_BPS && $bps > $MAX_BPS)) { ($MAX_BPS && $bps > $MAX_BPS)) {
logit("$node: WARNING: pkts/sec=$pps, bits/sec=$bps over $sec seconds"); my $spps = int($spkts / $sec);
my $sbps = int($sbytes * 8 / $sec);
my $rpps = int($rpkts / $sec);
my $rbps = int($rbytes * 8 / $sec);
logit("$node: WARNING: pkts/sec=$pps (send=$spps, recv=$rpps)".
", bits/sec=$bps (send=$sbps, recv=$rbps)".
" over $sec seconds");
if ($sendmail) { if ($sendmail) {
if (@mailbody == 0) { if (@mailbody == 0) {
my $pth = $bth = "no limit on"; my $pth = $bth = "no limit on";
...@@ -508,21 +528,37 @@ sub reportevents($) ...@@ -508,21 +528,37 @@ sub reportevents($)
sprintf("%20s %30s %8s %8s %s", sprintf("%20s %30s %8s %8s %s",
"Node:port", "Expt", "Pkts/sec", "Mb/sec", "When")); "Node:port", "Expt", "Pkts/sec", "Mb/sec", "When"));
} }
if (@maildetails == 0) {
push(@maildetails,
"\nDetails:");
push(@maildetails,
sprintf("%20s %17s %17s %s",
"Node:port", "Send/Recv pps", "Send/Recv Mbs", "Duration"));
}
my $stamp = POSIX::strftime("20%y-%m-%d %H:%M:%S", my $stamp = POSIX::strftime("20%y-%m-%d %H:%M:%S",
localtime($ref->{'start'})); localtime($ref->{'start'}));
push(@mailbody, push(@mailbody,
sprintf("%20s %30s %8d %8d %s for %d sec", sprintf("%20s %30s %8d %8d %s for %d sec",
$node, $pcs{$node}{'exp'}, $pps, $node, $pcs{$node}{'exp'}, $pps,
int($bps/1000000), $stamp, $secs)); int($bps/1000000), $stamp, $secs));
push(@maildetails,
sprintf("%20s %8d/%-8d %8d/%-8d %d sec",
$node, $spps, $rpps,
int($sbps/1000000), int($rbps/1000000),
$secs));
} }
} }
$rates{$node}{'pkts'} = 0; $rates{$node}{'spkts'} = 0;
$rates{$node}{'bytes'} = 0; $rates{$node}{'rpkts'} = 0;
$rates{$node}{'sbytes'} = 0;
$rates{$node}{'rbytes'} = 0;
$rates{$node}{'iv'} = 0; $rates{$node}{'iv'} = 0;
$rates{$node}{'elapsed'} = 0; $rates{$node}{'elapsed'} = 0;
} else { } else {
$rates{$node}{'pkts'} = $pps; $rates{$node}{'spkts'} = $spkts;
$rates{$node}{'bytes'} = $bps; $rates{$node}{'rpkts'} = $rpkts;
$rates{$node}{'sbytes'} = $sbytes;
$rates{$node}{'rbytes'} = $rbytes;
$rates{$node}{'iv'} = $iv; $rates{$node}{'iv'} = $iv;
$rates{$node}{'elapsed'} = $secs; $rates{$node}{'elapsed'} = $secs;
} }
...@@ -538,17 +574,24 @@ sub reportevents($) ...@@ -538,17 +574,24 @@ sub reportevents($)
} }
SENDMAIL($MAILTO, SENDMAIL($MAILTO,
"Excessive traffic on control network", "Excessive traffic on control network",
join("\n", @mailbody), join("\n", @mailbody, @maildetails),
$TBOPS); $TBOPS);
$maillast = time(); $maillast = time();
@mailbody = (); @mailbody = ();
@maildetails = ();
} }
} }
#
# Make a periodic report.
# Counts: 0==s-bytes, 1==s-uni, 2==s-multi, 3==s-broad
# 4==r-bytes, 5==r-uni, 6==r-multi, 7==r-broad
#
sub report($) sub report($)
{ {
my ($ref) = @_; my ($ref) = @_;
# XXX allow for differentiation down the road
my $send = 1; my $send = 1;
my $recv = 1; my $recv = 1;
...@@ -575,7 +618,7 @@ sub report($) ...@@ -575,7 +618,7 @@ sub report($)
$bpkts += $counts[7]; $bpkts += $counts[7];
} }
$ref->{$node}{'totals'} = $ref->{$node}{'totals'} =
[ $oct, $upkts, $mpkts, $upkts + $mpkts + $bpkts]; [ $oct, $upkts, $mpkts, $upkts + $mpkts + $bpkts ];
$pcs{$node}{'total'} = $upkts + $mpkts + $bpkts; $pcs{$node}{'total'} = $upkts + $mpkts + $bpkts;
push(@list, $node); push(@list, $node);
} }
...@@ -676,8 +719,10 @@ sub getnodeinfo($) ...@@ -676,8 +719,10 @@ sub getnodeinfo($)
$newpcs{$cnet}{'name'} = $pc; $newpcs{$cnet}{'name'} = $pc;
if (!exists($pcs{$cnet})) { if (!exists($pcs{$cnet})) {
$rates{$cnet}{'pkts'} = 0; $rates{$cnet}{'spkts'} = 0;
$rates{$cnet}{'bytes'} = 0; $rates{$cnet}{'rpkts'} = 0;
$rates{$cnet}{'sbytes'} = 0;
$rates{$cnet}{'rbytes'} = 0;
$rates{$cnet}{'iv'} = 0; $rates{$cnet}{'iv'} = 0;
$rates{$cnet}{'elapsed'} = 0; $rates{$cnet}{'elapsed'} = 0;
if ($whine) { if ($whine) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment