-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[monit] Unmonitor the processes in containers which are disabled.
Signed-off-by: Yong Zhao <[email protected]>
- Loading branch information
Showing
19 changed files
with
139 additions
and
72 deletions.
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/python | ||
import argparse | ||
import sys | ||
import syslog | ||
|
||
import psutil | ||
import swsssdk | ||
|
||
|
||
def check_process_existence(container_name, process_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(["name", "cmdline", "status"]): | ||
# The script process_checker has the command line format '/usr/bin/process_checker <container_name> | ||
# <process_name> <process_cmdline>' such as '/usr/bin/process_checker bgp fpmsyncd fpmsyncd'. So | ||
# when using psutil to search process 'fpmsyncd', we should skip the process which ran process_checker | ||
# since it is not 'fpmsyncd' process although 'fpmsyncd' is a sustring of its cmdline. | ||
if process.name() == "process_checker": | ||
continue | ||
|
||
if ((process_name == process.name() or process_cmdline in ' '.join(process.cmdline())) | ||
and process.status() in ["running", "sleeping"]): | ||
is_running = True | ||
break | ||
|
||
if not is_running: | ||
print("'{}' is not running.".format(process_name)) | ||
sys.exit(1) | ||
else: | ||
syslog.syslog(syslog.LOG_ERR, "contianer '{}' 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_name> <process_cmdline>") | ||
parser.add_argument("container_name", help="container name") | ||
parser.add_argument("process_name", help="process name") | ||
parser.add_argument("process_cmdline", nargs=argparse.REMAINDER, help="process name") | ||
args = parser.parse_args() | ||
|
||
check_process_existence(args.container_name, args.process_name, ' '.join(args.process_cmdline)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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
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
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
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
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