-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[Monit] Unmonitor the processes in containers which are disabled. #5153
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
Merged
jleveque
merged 13 commits into
sonic-net:master
from
yozhao101:unmonitor_disabled_containers
Sep 25, 2020
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ad64dc6
[monit] Unmonitor the processes in containers which are disabled.
yozhao101 b1cb0ba
[monit] Update the process snmp command line.
yozhao101 55237ee
[Monit] Change the format of process checking in Monit configuration
yozhao101 a671f45
[Monit] Add copying the Monit configuration file of teamd container to
yozhao101 9ecb61d
[Monit] Fix the typo.
yozhao101 e4c0824
[Monit] Use the string '/usr/bin/syncd' in Monit configuration files …
yozhao101 fe167c4
[Monit] Container name will not be as a parameter to the script
yozhao101 b576e19
[Monit] Install the psutil module.
yozhao101 b0c86e8
[Monit] Use process command line to signify the process is not running
yozhao101 1a4e481
[Monit] Delete a blank line.
yozhao101 5558796
Merge branch 'master' into unmonitor_disabled_containers
yozhao101 875a2a5
[Monit] Add a comment for the `print(...)` statement in the script
yozhao101 4fd77cc
[Monit] Fix a typo.
yozhao101 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| ############################################################################### | ||
| ## Monit configuration for teamd container | ||
| ## process list: | ||
| ## teamsyncd | ||
| ## teammgrd | ||
| ############################################################################### | ||
| check program teamd|teamsyncd with path "/usr/bin/process_checker teamd /usr/bin/teamsyncd" | ||
| if status != 0 for 5 times within 5 cycles then alert | ||
|
|
||
| check program teamd|teammgrd with path "/usr/bin/process_checker teamd /usr/bin/teammgrd" | ||
| if status != 0 for 5 times within 5 cycles then alert |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #!/usr/bin/python | ||
| import argparse | ||
| import sys | ||
| import syslog | ||
|
|
||
| import psutil | ||
| import swsssdk | ||
|
|
||
|
|
||
| def check_process_existence(container_name, process_cmdline): | ||
| """ | ||
| @summary: Check whether the process in the specified container is running or not and | ||
| an alerting message will written into syslog if it failed to run. | ||
| """ | ||
| config_db = swsssdk.ConfigDBConnector() | ||
| config_db.connect() | ||
| feature_table = config_db.get_table("FEATURE") | ||
|
|
||
| if container_name in feature_table.keys(): | ||
| # We look into the 'FEATURE' table to verify whether the container is disabled or not. | ||
| # If the container is diabled, we exit. | ||
| if ("state" in feature_table[container_name].keys() | ||
| and feature_table[container_name]["state"] == "disabled"): | ||
| sys.exit(0) | ||
| else: | ||
| # We leveraged the psutil library to help us check whether the process is running or not. | ||
| # If the process entity is found in process tree and it is also in the 'running' or 'sleeping' | ||
| # state, then it will be marked as 'running'. | ||
| is_running = False | ||
| for process in psutil.process_iter(["cmdline", "status"]): | ||
| if ((' '.join(process.cmdline())).startswith(process_cmdline) and process.status() in ["running", "sleeping"]): | ||
| is_running = True | ||
| break | ||
|
|
||
| if not is_running: | ||
| # If this script is run by Monit, then the following output will be appended to | ||
| # Monit's syslog message. | ||
| print("'{}' is not running.".format(process_cmdline)) | ||
jleveque marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| sys.exit(1) | ||
| else: | ||
| syslog.syslog(syslog.LOG_ERR, "container '{}' is not included in SONiC image or the given container name is invalid!" | ||
| .format(container_name)) | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description="Check whether the process in the specified \ | ||
| container is running and an alerting message will be written into syslog if it \ | ||
| failed to run.", usage="/usr/bin/process_checker <container_name> <process_cmdline>") | ||
| parser.add_argument("container_name", help="container name") | ||
| parser.add_argument("process_cmdline", nargs=argparse.REMAINDER, help="process command line") | ||
| args = parser.parse_args() | ||
|
|
||
| check_process_existence(args.container_name, ' '.join(args.process_cmdline)) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.