Skip to content

Commit

Permalink
[Monit] Use process command line to signify the process is not running
Browse files Browse the repository at this point in the history
instead of process name in syslog.

Signed-off-by: Yong Zhao <[email protected]>
  • Loading branch information
yozhao101 committed Sep 21, 2020
1 parent b576e19 commit b0c86e8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions files/image_config/monit/process_checker
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import psutil
import swsssdk


def check_process_existence(container_name, process_name, process_cmdline):
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.
Expand All @@ -27,13 +27,13 @@ def check_process_existence(container_name, process_name, process_cmdline):
# 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"]):
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:
print("'{}' is not running.".format(process_name))
print("'{}' is not running.".format(process_cmdline))
sys.exit(1)
else:
syslog.syslog(syslog.LOG_ERR, "container '{}' is not included in SONiC image or the given container name is invalid!"
Expand All @@ -45,7 +45,7 @@ def main():
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 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))
Expand Down

0 comments on commit b0c86e8

Please sign in to comment.