-
Notifications
You must be signed in to change notification settings - Fork 814
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
Low/No Disk space caused the Agent to crash and not recover. #2223
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,11 @@ | |
from util import get_os, yLoader | ||
from utils.platform import Platform | ||
from utils.proxy import get_proxy | ||
from utils.subprocess_output import get_subprocess_output | ||
from utils.subprocess_output import ( | ||
get_subprocess_output, | ||
SubprocessOutputEmptyError, | ||
) | ||
|
||
|
||
# CONSTANTS | ||
AGENT_VERSION = "5.7.0" | ||
|
@@ -570,17 +574,16 @@ def get_system_stats(): | |
|
||
platf = sys.platform | ||
|
||
if Platform.is_linux(platf): | ||
output, _, _ = get_subprocess_output(['grep', 'model name', '/proc/cpuinfo'], log) | ||
systemStats['cpuCores'] = len(output.splitlines()) | ||
|
||
if Platform.is_darwin(platf): | ||
output, _, _ = get_subprocess_output(['sysctl', 'hw.ncpu'], log) | ||
systemStats['cpuCores'] = int(output.split(': ')[1]) | ||
|
||
if Platform.is_freebsd(platf): | ||
output, _, _ = get_subprocess_output(['sysctl', 'hw.ncpu'], log) | ||
systemStats['cpuCores'] = int(output.split(': ')[1]) | ||
try: | ||
if Platform.is_linux(platf): | ||
output, _, _ = get_subprocess_output(['grep', 'model name', '/proc/cpuinfo'], log) | ||
systemStats['cpuCores'] = len(output.splitlines()) | ||
|
||
if Platform.is_darwin(platf) or Platform.is_freebsd(platf): | ||
output, _, _ = get_subprocess_output(['sysctl', 'hw.ncpu'], log) | ||
systemStats['cpuCores'] = int(output.split(': ')[1]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not your code, but seems like this could be written as: if Platform.is_linux(platf):
...
elif Platform.is_darwin(platf) or Platform.is_freebsd(platf):
... |
||
except SubprocessOutputEmptyError as e: | ||
log.warning("unable to retrieve number of cpuCores. Failed with error %s", e) | ||
|
||
if Platform.is_linux(platf): | ||
systemStats['nixV'] = platform.dist() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should log the exception here as well, so we don't silence other important Exceptions
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.
Log or raise? Cause we're logging it with
log.exception()
.... If we raise, then we'd be unable to collect stats such as the network stats below which would be collectible due to procfs being a pseudo FS and not require calling any subcommand.Not sure what you mean here.
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.
Opps, sorry, I meant to do
except Exception as e:
and then log the Exception messagee
. If you end up doing the custom Exception class below, it'll look different obviouslyThere 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.
log.exception() already adds the exception info - type, stacktrace to the logging statement.
I have added the custom exception - for future use, but I don't think it's necessary to go over all try...catch blocks that already handle
Exception
and add yet another block that basically will do nothing other than log the exception. Sounds like overkill. But that's just me, coming from a C/C++ background.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.
yeah, it's not necessary, I just want to make sure we aren't silencing errors we don't expect. Best practice is to attempt to keep from running
except Exception:
as much as possible, for that reason.Could we do a
catch SubprocessOutputEmptyError:
here instead?