-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic logging functionality & log all connection metrics #24
Conversation
commit 3c1b750 Author: Andrew Pardoe <[email protected]> Date: Fri Dec 24 09:13:15 2021 -0800 Add basic logging and connection logging Add new logging options: - tmo_logfile: specify logfile - tmo_log_all: log all connection statistics Also move some error output to logfile commit fd85144 Author: Andrew Pardoe <[email protected]> Date: Tue Dec 21 16:23:51 2021 -0500 Add default operational logging 1. Move error messages from print to logging.error 2. Add operational logging 3. Add log_all option to log all connection characteristics commit cb5eefd Author: Andrew Pardoe <[email protected]> Date: Mon Dec 20 22:25:43 2021 -0500 Added logging for basic cases
Example log file, collected on both Windows and WSL/Ubuntu:
This logfile is for a normal, no-event run. If there had been an event (failed ping, reboot, etc.) that also gets logged. Next step is to just log deltas. I'd like to read the log, check for changes, then log only if there are changes. Then I think I'm done with my changes :) Example with timestamps replaced by line numbers for illustration:
1: Baseline |
Sigh. After a record uptime of over 8 days, my modem decided to give you a good demonstration of a logfile with an actual reboot. Note the -1 ms ping: I changed the ping detection logic to return -1 ms for a failed series of pings and the actual average ping time for success.
|
Delta logging as described above is in the delta branch. I'm testing it out on my system for a while. |
Looks great, thanks for your continued contributions, @AndrewPardoe - let me know when you feel you've tested this enough to merge! |
commit 4cc7fa6 Author: Andrew Pardoe <[email protected]> Date: Tue Dec 28 07:56:53 2021 -0800 Cleanup small delta logging items commit 22d1c60 Author: Andrew Pardoe <[email protected]> Date: Mon Dec 27 07:58:36 2021 -0800 Add option to force log write from command line This option's nice when you're watching your log like a boiling pot commit 83bc382 Author: Andrew Pardoe <[email protected]> Date: Sun Dec 26 08:58:36 2021 -0800 Correct indentation error: `data` out of scope commit c05700d Author: Andrew Pardoe <[email protected]> Date: Sun Dec 26 08:47:04 2021 -0800 Update requirements for tailer & parse commit e31d079 Author: Andrew Pardoe <[email protected]> Date: Sun Dec 26 08:42:41 2021 -0800 Add delta logging
OK, I'm done. I've got all the edits I need for my usage. The script's been running a few days on my server. Note that the delta logging pulls in two more requirements: tail and parse. I can do these things in straight Python if you prefer. Feel free to merge. Thanks! |
Example log for delta logging. I used the command-line parameter
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably want to update the README, add command line flags for any missing options like the log file location, and refactor the repetitive msg printing and logging code with a helper function, but this looks solid. Thanks for contributing upstream!
if ping_index > 0: | ||
time.sleep(ping_interval) | ||
ping_exec = subprocess.run(ping_cmd, capture_output=True) | ||
print(ping_exec.stdout.decode('utf-8')) | ||
if is_win and 'Destination host unreachable' in str(ping_exec.stdout): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://stackoverflow.com/questions/2953462/pinging-servers-in-python#comment69975395_32684938
On Windows, ping
has a clean exit status when "Destination host unreachable" is encountered and needs to specifically be called out to return -1 here for ping_time
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the ping logic significantly. It ignores the return code on Windows in favor of searching for the ping time, but it's easy enough to put that check back in.
if ping_exec.returncode != 0:
return -1
pattern = b'[rtt|round-trip] min/avg/max/mdev = \d+.\d+/(\d+.\d+)/\d+.\d+/\d+.\d+ ms'
if is_win:
pattern = b'Minimum = \d+ms, Maximum = \d+ms, Average = (\d+)ms'
ping_ms = re.search(pattern, ping_exec.stdout)
sys.exit(2) | ||
if self.skip_reboot: | ||
for var in {'ping', '4G_band', '5G_band', 'enbid'}: | ||
self.reboot[var] = False | ||
# if not self.login['username']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do want to eventually be sure to log this error when there is not a TTY attached, so I'll want to create an issue to track this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll ignore this for now.
@AndrewPardoe feel free to implement the few things I just noted (e.g. README), but I can get around to this if not! |
Squashed commit of the following: commit b1a388c4364ddf5998c93d431c8bd77c367680d9 Author: Andrew Pardoe <[email protected]> Date: Fri Dec 31 09:50:27 2021 -0800 Add print_and_log function commit fe673487bde3ca3768a67ef633bc09595b95f6d3 Author: Andrew Pardoe <[email protected]> Date: Fri Dec 31 09:21:29 2021 -0800 Add logging options to command line & README Also add back early ping success check for Windows.
Address the feedback from #24
commit 3c1b750
Author: Andrew Pardoe [email protected]
Date: Fri Dec 24 09:13:15 2021 -0800
commit fd85144
Author: Andrew Pardoe [email protected]
Date: Tue Dec 21 16:23:51 2021 -0500
commit cb5eefd
Author: Andrew Pardoe [email protected]
Date: Mon Dec 20 22:25:43 2021 -0500