Can this be modified to monitor upload traffic?

Asked by Paul

-Linux Mint 18 Cinnamon 64bit Clean install.
-Running an Apahce2 server for Nextcloud

While running this script it will suspend the server even while its being accessed. For example, I want to synchronize a music album to my phone, in the middle of downloading the files to my phone it will suspend the server as its upload traffic. It logs anything I send to the server as download traffic, although with the OS suspend set at 15 minutes of inactivity, the server will suspend in the middle of a download at 15 minutes, script or not. Turning it off in the OS led to it never going to sleep even though the script was saying it tried to suspend.

How can I mod it to monitor upload traffic as well, and what should I do with the server OS suspend settings?

Follow up question, I tried adding it to startup applications by clicking browse next to the command line, navigated to the script and adding -r at the end so it looks like this: /home/user/Desktop/keepawake/keepawake.py -r . Now it created a Desktop file and seems to work as the log shows its running, But I wanted to be sure this is how its intended to be run.

Thanks for this incredible code thus far, it is exactly what I need to keep power consumption down with this cloud server.

-Ackevor

Question information

Language:
English Edit question
Status:
Solved
For:
Keep.Awake Edit question
Assignee:
DanglingPointer Edit question
Last query:
Last reply:
Whiteboard:
Requesting information on how the program was executed.
Revision history for this message
Paul (ackevor) said :
#1

After some more testing, while remotely connected to the Server, the script sees and properly logs download traffic from files I send to it from my phone. Once I disconnect from my remote session however, no matter the size or number of uploads to the server from my phone, the script suspends the system in the time its set with no thresholds breached. Looking at the logs it shows 0 b/s even though there is obvious download activity.

During these tests I am running the script in terminal and let it continue, getting real time logs in Detail mode.

Suggestions?

Thanks!

Revision history for this message
DanglingPointer (ferncasado) said :
#2

Hi Paul, apologies for the delay in any response. I've been away on holiday for several weeks.

I have tested keepawake.py on Ubuntu 14.04 and 16.04. I understand you are using Mint, I have only done limited testing on that distribution.
hmmm... I'm trying to understand your use-case. On Ubuntu it should work the way you are trying to use it if I understand your use-case correctly.

All network traffic on the detected network interface will be monitored (upload and download).

Add "-v Verbose" to your command and tail the log file. It should give you a better understanding of what is being detected on each interval.

What parameters are you running on the command line?

keepawake.py was designed and developed to run under a user and not as a OS service. It natively interacts with Ubuntu's gnome gsettings to set or remove suspend times.

Revision history for this message
Paul (ackevor) said :
#3

No worries. I don't have any free time to test it further right now. I remember when I last worked on it I did see it monitor upload traffic via verbose logs, but for some reason it would still send a suspend command in the middle of a transfer. After a few changes It seemed to work enough to leave it running, but the command parameters in startup applications leave me a bit confused. Sometimes the script starts upon restart, other times it doesn't. The command is I entered in the startup application command box is "python3 /path/to/keepawake.py -r". Perhaps the network traffic from my mobile is intermittent and not triggering the threshold.

In any case I appreciate the response. As it is now I think its just getting the startup command right and tinkering with the timeouts in the script, something I may do after I get a new router.

Revision history for this message
DanglingPointer (ferncasado) said :
#4

No problem I'll leave this thread open for now.
Let me know how you go with the different parameters.

Here's an example command with parameters that I use for my backup server. I run it from a terminal. The server is on 24/7

~$ nohup /...path.../keep.awake/v4/keepawake.py -s 5120 -w 5400 -u 600 -l /var/log/Keep.Awake/ -v Verbose -r > /dev/null 2>&1 &

Explanation:
- "nohup" in combination with '&' at the end runs the program in the background so you can close the terminal.
- "> /dev/null 2>&1" discards the output that it is trying to spit out to screen. Literally it is sending the output to linux's null path (oblivion).
- '-r' I supoose you already know, it skips the interactive start of the program
- "-v Verbose" as you already know is the most verbose logging setting.
- "-l /var/log/Keep.Awake/" changes the path to where the log file will be written. Bare in mind you have to be aware of permissions to wherever you decide to write the logs. Make sure they are configured correctly before trying to write your log file to the path, else the program will error out.
- "-u 600" is the maximum amount of desktop idle time in seconds after which keepawake will determine the computer as idle. So for "600" which is 5 minutes, if the computer has not had any keyboard or mouse interactivity on the active user x-desktop session, then it will consider the computer as idle, so long as network speedlimit is below threshold AND cpu activity is below thresholds as well.
- "-w 5400" seconds equals an hour and half or 90 minutes. If keepawake determines the computer as idle (which means, cpu, network traffic, and x-session user activity via mouse or keyboard) then it will attempt to configure the OS's gnome settings to set 90 minutes as the count-down time before suspending.
- "-s 5120" bytes is approximately 5KB. If network traffic falls below this then keepawake will determine the computer as idle so long as cpu activity is below thresholds AND x-desktop session (mouse and keyboard) is below threshold as well.

I hope the above sheds some light on usage. On a further note the default setting for cpu activity is 6.25% (that's cumulative of all cores)

Regards,
DanglingPointer

Revision history for this message
DanglingPointer (ferncasado) said :
#5

Closing this thread as I haven't heard back thus assuming all is well now.

Revision history for this message
DanglingPointer (ferncasado) said :
#6

use-case query solved