gharris999;603168 Wrote:
> idle = (!active within the last 45 minutes)
>
> ..during idle_grace, I'd like to poll the network bandwidth usage once
> per minute ...
Do you mean "idle = (!active && !net_use) for 45 minutes", rather ?
My way of doing things would be to test both SB states and net
bandwidth every minute, and to XOR the logical states of both tests.
Push the result in a pipe with 45 slots, and shutdown when that buffer
is empty. Last state pushing out the oldest, if it is a "1" for active,
no need to reset anything: the buffer is not empty as it doesn't sum to
0.
I think it is simpler, but maybe that doesn't exactly work as you want
it ? (I'd also use a buffer much shorter than 45 minutes, this net
threshold thing is too volatile, especially on a multi-purpose machine.
My mac desktop runs its TimeMachine thinggy in direction of a server
every 30 minutes…).
This is my sub measuring net activity, FWIW. The pipe I use is an
array, I guess I should be using "pack" to store bits but never got
around to coding it. :
Code:
--------------------
sub detect_net {
my $clue_net=1; # 1=active, 0=inactive
# Activity threshold in kilobytes (in + out)
my $threshold=$CONF{pwmgt}->{thresh_net} || 30;
open(PROC,"<$CONF{'run'}->{'netproc'}") or die "Cannot open
$CONF{'run'}->{'netproc'}: $!\n";
my @proc = <PROC>;
close(PROC);
my ($in,$out) = ( map( /^.*?\w+\d{1}: # like | en3: ...
\s*(\d*) # bytes in - A real large value
collapses with "en3:" above => \s*, not \s+
\s+(\d*) # packets in
\s+(\d*) # errs
\s+(\d*) # drop
\s+(\d*) # ...
\s+(\d*)
\s+(\d*)
\s+(\d*) # ...
\s+(\d*) # bytes out
\s+(\d*) # packets out
/x,@proc) )[0,9];
my $kbytes = ( $in + $out ) / 1024;
# Scrap this run in case the byte counter rolled over
if ( $o_kbytes > $kbytes ) {
logger(" NET counter rollover: prev %d kBytes > last %d kBytes\n", $o_kbytes,
$kbytes);
$o_kbytes = 0;
}
my $eval = ( ($kbytes - $o_kbytes) > $threshold ) ? 1 : 0;
push(@net,$eval);
shift(@net);
$eval=0;
map( $eval += $_ , @net); #Sum activity pipe
# No activity = 0
$clue_net = ($eval == 0 ) ? 0 : 1;
logger(" NET latest: +%d kBytes, %s threshold (%d kB)\n",($kbytes -
$o_kbytes), (($kbytes - $o_kbytes) > $threshold ) ? "above" : "below"
,$threshold) if ($logging);
logger(" NET pipe (old..cur): [%s] -> %s (%d)\n","@net",($eval == 0 ) ?
"idle" : "active",$clue_net) if ($logging);
$o_kbytes = $kbytes;
return $clue_net;
}
--------------------
--
epoch1970
Daily dose delivered by: 2 SB Classic (fw 130), 1 SB Boom (fw 50)
SqueezeCenter 7.3.4 (Debian 5.0) with plugins: ContextMenu,
SaverSwitcher by Peter Watkins Server Power Control by Gordon Harris
WeatherTime by Martin Rehfeld IRBlaster by Gwendesign (Felix)
FindArt, CDplayer by bpa BBC iPlayer, SwitchPlayer by Triode
PowerSave by Jason Holtzapple TrackStat by Erland Isaksson.
------------------------------------------------------------------------
epoch1970's Profile: http://forums.slimdevices.com/member.php?userid=16711
View this thread: http://forums.slimdevices.com/showthread.php?t=49028
_______________________________________________
unix mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/unix