The server is set to go to sleep and suspend to RAM to save power after 5 minutes of idling. It works great as all of the apps so far have been usage aware and prevent sleep while they are being used.
Recently I installed an application that downloaded and uploaded files that was not usage aware. This meant that in the middle of a download or upload if everything else was idle but that app the server would go to sleep.
The logical solution, in my mind, was to get an application that disabled sleep while network card traffic was above a certain threshold.
I spent an hour googling around and found nothing that suited my needs even remotely, and once I got over my disappointment I decided to create a solution using my novice PowerShell skills.
The script that sets sleep based on network ability is below. It's not as good as it could be but it works for me.
You will need Powershell 2.0 to run it.
Checks NIC activity, if it is less than 50KB/s, sets sleep timeout to 5 min, if more than 50KB/s disables sleep. Checks again 140 seconds later. That's it.
Do a get-counter in powershell and replace my NIC "counter" name with yours or it wont work.
##############################
##### nicsleep.ps1
##############################
function checknicactivity
{
$counter = 1
do
{
$niccounter = Get-Counter -counter "\network interface(realtek rtl8102e_rtl8103e family pci-e fast ethernet nic [ndis 6.20])\bytes total/sec"
$c = $niccounter.countersamples | where {$_.path -match "ndis 6.20"}
$d = $c.cookedvalue
if ($d -gt 51200){powercfg -change -standby-timeout-ac 0}
elseif ($d -lt 51200){powercfg -change -standby-timeout-ac 5}
Start-Sleep -s 140
}
while ($counter -gt 0)
}
checknicactivity
#####################
If you want to run this with no Powershell visible shell one way is to call it through vbscript. This assumes both files are located in C:\Scripts
''''''''''''''''''''''''''''''
Dim objShell
Set objShell=CreateObject("WScript.Shell")
'enter the PowerShell expression
'you need to use short filenames and paths
strExpression="C:\Scripts\nicsleep.ps1"
strCMD="powershell -nologo " & strExpression
'Uncomment next line for debugging
'WScript.Echo strCMD
'use 0 to hide window
objShell.Run strCMD,0
'''''''''''''''''''''''''''''''''''''''''''
One thing I struggled with was deciding if I wanted to run the script one off as a scheduled task every x seconds or just run it once and have the loop keep it open forever (it autostarts with windows for me).
To me it seemed more logical to keep the PS process open rather than keep launching a new one every 2 minutes.
It's quick and dirty and it works for me, there is probably better ways to do it. If you have a suggestion let me know.