-sub shutdown_mail {
- my $hostname = hostname();
- my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdat)
- = localtime(time);
- my $date = sprintf("%4d-%02d-%02d %02d:%02d:%02d",
- $year+1900, $mon+1, $mday, $hour, $min, $sec);
- my $to = "To: $alias_addr\n";
+sub bandwidth_monitor {
+ while (1) {
+ # See if a new day has started for bandwidth monitoring
+ chomp($now = `date -u +%D`);
+ if (-e $daily_stamp) {
+ chomp($stamp = `cat $daily_stamp`);
+ }
+ if (! defined($stamp) || !($stamp =~ $now)) {
+ open (STAMP, ">$daily_stamp") ||
+ die "Can't open file $daily_stamp for writing: $!\n";
+ print STAMP "$now\n";
+ close STAMP;
+ unlink ($daily_log);
+
+ # Could save the list of capped slices in a file in order to
+ # avoid re-sending mails if the daemon restarts.
+ # Also may want a list of slices that are exempt from capping.
+ if (defined(%Cap)) {
+ undef %Cap;
+ }
+
+ # Need to reset bandwidth limits here
+
+ syslog("info", "pl_mom: Beginning bandwidth monitoring for $now");
+ }
+
+ # Get baseline counts
+ `touch $daily_log`;
+ open (BASE, "+<$daily_log") ||
+ print "Cannot open $daily_log; $!\n";
+ while (<BASE>) {
+ my ($sliceid, $bytecount) = split(/ /);
+ $Start{$sliceid} = $bytecount;
+ }
+
+ $status = `tc -s -d qdisc show`;
+ @lines = split(/\n/, $status);
+ for ($i = 0; $i < @lines; $i++) {
+ if ($lines[$i] =~ /qdisc pfifo/) {
+ $lines[$i] =~ s/^ +//;
+ @fields = split(/ /, $lines[$i]);
+ $slice = $fields[2];
+ $slice =~ s/://;
+
+ if ($slice != 9999) {
+ $lines[$i+1] =~ s/^ +//;
+ @fields = split(/ /, $lines[$i+1]);
+ $bytes = $fields[1];
+ #if ($bytes) {print "Slice $slice sent $bytes bytes\n";}
+
+ if (! defined($Start{$slice})) {
+ print BASE "$slice $bytes\n";
+ $Start{$slice} = $bytes;
+ }
+ $Now{$slice} = $bytes;
+ }
+ }
+ }
+ close (BASE);
+
+ foreach $slice ( sort (keys %Start) ) {
+ if (defined $Now{$slice}) {
+ $today = $Now{$slice} - $Start{$slice};
+ if ($today >= $byte_cutoff && ! defined($Cap{$slice})) {
+ $Cap{$slice} = "sent";
+ $slicename = get_slice_name($slice);
+ if ($slicename) {
+ bw_cap_mail($slicename);
+ } else {
+ syslog("warning", "pl_mom: Could not find slice name".
+ " for slice ID $slice");
+ }
+ # Add bandwidth cap here
+ }
+ } else {
+ # The /proc/virtual/<id> directory is gone...
+ }
+ }
+
+ sleep($bwmon_sleep);
+ }
+}
+
+sub send_mail {
+ # Arg 0: recipient addresses, comma-separated string
+ # Arg 1: subject line
+ # Arg 2: body of message
+ my $to = "To: $_[0]\n";