Results 11 to 20 of 42
-
2008-06-19, 06:58 #11Senior Member
- Join Date
- Dec 2007
- Posts
- 279
-
2008-06-19, 17:01 #12Junior Member
- Join Date
- Jun 2008
- Location
- Miami, FL
- Posts
- 20
-
2010-12-21, 12:15 #13Junior Member
- Join Date
- May 2009
- Posts
- 6
Tweak's to syburgh's handy sc-idle script
Sorry for the old-thread revival, but I wanted to share a few updates I made to the sc-idle.py script to make it more useful - maybe other sc-idle users will benefit too.
The changes are:
1) added a condition to keep the server awake if any SMB clients are active.
2) fixed an apparent logic bug in recognizing multiple active players
Here are the changed areas of code:
Many thanks to syburgh for sharing the information about getting the MSI Wind PC setup running - it's been working quite well for my server.Code:# Change to original main() to add smb_shares_active condition: def main(): # Determine whether system is considered "idle" # (i.e. eligible for suspend/hibernate) system_is_idle = lambda: not (keepawake_file(path=opt.nosleep_path) \ or tty_active() \ or smb_shares_active() \ or player_active(opt.cli_host, opt.cli_port)) # New function for detecting active SMB clients: def smb_shares_active(): active_smbusers_list = os.popen('smbstatus -b | sed -e "1,4d"').readlines() if len(active_smbusers_list): log.debug("Detected active smb user sessions, preventing idle.") return True # Revised original player_active function to fix problem handling multiple players. def player_active(host, port): 'Returns True when players are active in SqueezeCenter' sc = sc_cli(host, port) is_off_fn = lambda cli, id: cli.query("%s power ?" % (id,)) == '0' \ or cli.query("%s mode ?" % (id,)) in ['stop', 'pause'] if False in [is_off_fn(sc, id) for id in sc.player_id()]: log.debug("At least one SqueezeCenter player is active.") del sc return True else: log.debug("No SqueezeCenter player found to be active.") del sc return False
Thanks,
MJP
-
2010-12-22, 13:05 #14Senior Member
- Join Date
- Apr 2008
- Location
- Paris, France
- Posts
- 1,466
Most excellent thread revival, thanks.
Hats off to Syburgh who figured out all this before anyone and to Gharris999 for developing the user-friendly Server Power Control plugin.
To anyone who might doubt, I say there is a lot of value in this community.4 SB 3 • iPeng (iPhone + iPad) • SqueezeLite • Squeezebox Server 7.6.2 (Debian 6.0) with plugins: CD Player, WaveInput by bpa • IRBlaster by Gwendesign (Felix) • Server Power Control by Gordon Harris • Smart Mix by Michael Herger • PowerSave by Jason Holtzapple • Song Info, Song Lyrics by Erland Isaksson • Just Covers by Tom Kalmijn • WeatherTime by Martin Rehfeld • Local Player, BBC iPlayer, SwitchPlayer by Triode • Auto Dim Display, SaverSwitcher, ContextMenu by Peter Watkins.
-
2011-01-04, 16:03 #15
Here's a question:
Now that I've woken up to the fact that it's pretty easy to stream video via a DLNA service to my iPad, I'm thinking of adding mediatomb or ushare to my SBS box. Since power management on my SBS box is handled by SrvrPowerCtrl, I guess that I ought to add an optional 'can-suspend.sh' script that SrvrPowerCtrl would execute prior to shutting down, hibernating or suspending and, if returning anything other than 0, will have the effect of inhibiting SrvrPowerCtrl's pending action.
Presumably, can-suspend.sh should check for smb activity like MJP does in his python script mods. And presumably, it ought to check to see if ushare is actively streaming content. (No idea how to do that, yet.)
Other than SBS related activity, are there any other checks that can-suspend.sh ought to carry out?
-
2011-01-04, 19:44 #16Senior Member
- Join Date
- Apr 2008
- Location
- Paris, France
- Posts
- 1,466
I don't know DLNA, but the following may be useful:
- checking for a known path with lsof to detect opened files
- looking at the amount of packets coming in/out of the network card (a weak hint, and the counter rolls over at 4GB in a 32bit OS)
- using a firewall rule (or opening a raw/divert socket) on a known port on the local host to get hit when traffic occurs on the port (the idea is to transparently mirror traffic, the way to do this is OS dependent AFAIK)
Also I am using FIFO pipes to keep a window of a few recent activity hints and only vote for idle when the pipe is totally empty. This allows giving more or less slack time according to the item being measured and also compensating for temporary glitches in the detection. Hence it potentially improves comfort and/or reliability compared to a single measure leading to a vote.
In the logs I use a representation such as this, I think it will carry the idea:
"SMB server: [ 0 0 1 1 0 1 ] -> 1 (active)"
(when all ones have shifted to the right and the pipe is only filled with zeros, the vote is 0 idle).4 SB 3 • iPeng (iPhone + iPad) • SqueezeLite • Squeezebox Server 7.6.2 (Debian 6.0) with plugins: CD Player, WaveInput by bpa • IRBlaster by Gwendesign (Felix) • Server Power Control by Gordon Harris • Smart Mix by Michael Herger • PowerSave by Jason Holtzapple • Song Info, Song Lyrics by Erland Isaksson • Just Covers by Tom Kalmijn • WeatherTime by Martin Rehfeld • Local Player, BBC iPlayer, SwitchPlayer by Triode • Auto Dim Display, SaverSwitcher, ContextMenu by Peter Watkins.
-
2011-01-16, 12:07 #17
OK, this seems to be unreliable:
The DLNA server that I'm using, mediatomb, only opens a file momentarily to read the portion that it's currently streaming. So the above is only occasionally clued into the fact that mediatomb is actively streaming a file.Code:#!/bin/sh SHAREPATH='/mnt/media/Videos' # Check for an file open anywhere in SHAREPATH.. OPENFILE=`/usr/bin/lsof +D "$SHAREPATH"` if [ -n "$OPENFILE" ]; then echo "File $OPENFILEis open.." exit 1 fi exit 0
Bandwidth monitoring of the network interface seems to be more promising. The following seems to correctly detect current network bandwidth usage above a certain threshold:
Having to call bwm-ng, sed, awk and bc all seems a little heavy handed. Can anyone think of a simpler way to do this?Code:#!/bin/sh #Threshold for bytes transmitted over a 10 second interval.. THRESHOLD="10000.00" # Check for current network bandwith usage above our THRESHOLD.. # from bwm-ng README: #csv output format: #Type svg, sum, max: #unix timestamp;iface_name;bytes_out;bytes_in;bytes_total;packets_out;packets_in;packets_total;errors_out;errors_in\n #monitor bandwith usage on eth0 for 10 seconds | sed output just last (total) line | awk extract the 3rd csv field TXSUM=`bwm-ng --interfaces eth0 --allif 0 --type rate --count 10 --output csv --ansiout --type sum --unit bytes | sed '$!d' | awk -F ";" '{ print $3 }'` #use bc to do a floating point comparison.. ABOVETHRESHOLD=`echo "$TXSUM > $THRESHOLD" | bc` if [ $ABOVETHRESHOLD -gt 0 ] then echo "System is busy! TXSUM == $TXSUM" exit 1 else echo "System is not busy! TXSUM == $TXSUM" fi exit 0Last edited by gharris999; 2011-01-16 at 12:09.
-
2011-01-17, 12:14 #18
Here is the above script, fleshed out a bit:
Code:#!/bin/bash # # spc-checkidle.sh -- bash script to check bandwidth usage on an interface to detect an idle condition. # # Checking bandwidh usage on INTERFACE for CHECKDUR duration, spc-checkidle.sh returns: # # 0 == below THRESHOLD; 1 == above THRESHOLD. # # Optional args: --interface=name # use an interface other than the default eth0.. # --threshold=number # use a threshold other than the default 10000 bytes.. # --duration=number # use a bandwidth check duration other than the default 10 seconds.. # --verbose=1 # show more output.. # # Defaults.. # Network Interface to use.. INTERFACE='eth0' # Bandwidth threshold to check for.. THRESHOLD="10000.00" # Duration of bandwidth check.. CHECKDUR="10" # How chatty.. VERBOSE=0 for ARG in $* do OPTNAME=`echo $ARG | sed -e 's/^--\(.*\)=.*$/\1/g'` OPT=`echo $ARG | sed -e 's/^--.*=//g'` case ${OPTNAME} in interface) INTERFACE=$OPT ;; threshold) THRESHOLD=$OPT ;; duration) CHECKDUR=$OPT ;; verbose) VERBOSE=1 ;; *) echo "Usage: $0 [--interface=ethN] [--threshold=NNNNN.NN] [--duration=NN] [--verbose=N]" >&2 exit 1 esac done [ $VERBOSE -gt 0 ] && echo "Checking for bandwidth usage above ${THRESHOLD} on ${INTERFACE} for ${CHECKDUR} seconds.." ; # from wgm-ng README: csv output format, Type svg, sum, max: #unix timestamp;iface_name;bytes_out;bytes_in;bytes_total;packets_out;packets_in;packets_total;errors_out;errors_in\n # Monitor bandwith usage on INTERFACE for CHECKDUR seconds | sed output just last (total) line | awk extract the in_out_bytes_total (5th csv field) TXSUM=`bwm-ng --interfaces ${INTERFACE} --allif 0 --type sum --unit bytes --count ${CHECKDUR} --output csv --ansiout | sed '$!d' | awk -F ";" '{ print $5 }'` # Check for current network bandwith usage above our THRESHOLD using bc to do a floating point comparison.. ABOVETHRESHOLD=`echo "$TXSUM > $THRESHOLD" | bc` if [ $ABOVETHRESHOLD -gt 0 ] then [ $VERBOSE -gt 0 ] && echo "System is busy! Bandwith usage on ${INTERFACE} over ${CHECKDUR} seconds == ${TXSUM}" ; exit 1 else [ $VERBOSE -gt 0 ] && echo "System is not busy! Bandwith usage on ${INTERFACE} over ${CHECKDUR} seconds == ${TXSUM}" ; fi exit 0
-
2011-01-17, 13:38 #19Senior Member
- Join Date
- Apr 2008
- Location
- Paris, France
- Posts
- 1,466
I used to go with a simple cat /proc/net/dev followed with the usual perl matching expression to extract bytes in and bytes out.
I don't know this bwm-ng tool you're using; I guess it takes care of byte counters rollover ?
There must be a DNLA related port opened somewhere on the server, perhaps lsof can show an "ESTABLISHED" state to disambiguate on network usage, if using TCP ?
When using a relatively low threshold of around 30kB of in+out traffic per minute, something like an NTP sync or a few RSS feed syncs can show system activity when in fact you could well shutdown the server as it is not working for you. Using a higher threshold, like 100kB, might not detect a player in pause mode.4 SB 3 • iPeng (iPhone + iPad) • SqueezeLite • Squeezebox Server 7.6.2 (Debian 6.0) with plugins: CD Player, WaveInput by bpa • IRBlaster by Gwendesign (Felix) • Server Power Control by Gordon Harris • Smart Mix by Michael Herger • PowerSave by Jason Holtzapple • Song Info, Song Lyrics by Erland Isaksson • Just Covers by Tom Kalmijn • WeatherTime by Martin Rehfeld • Local Player, BBC iPlayer, SwitchPlayer by Triode • Auto Dim Display, SaverSwitcher, ContextMenu by Peter Watkins.
-
2011-01-17, 14:37 #20
bwm-ng: http://www.gropp.org/?id=projects&sub=bwm-ng
It's ubiquitous enough that it's in Ubuntu's standard repositories.


Reply With Quote
