ambari监测进程脚本:check_process_status.py

本文介绍了一个用于检测Ambari中进程运行状态的Python脚本check_process_status.py。该脚本通过读取PID文件并尝试发送信号给指定PID来判断进程是否正在运行,若进程未运行则会抛出异常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于工作时使用到监控,因此看了一下监控进程实现逻辑

更新进度

  1. 2019.08.02 初次添加

记录ambari监测进程脚本:check_process_status.py

#!/usr/bin/env python

from resource_management.core.exceptions import ComponentIsNotRunning
from resource_management.core.logger import Logger
__all__ = ["check_process_status"]

import os

def check_process_status(pid_file):
  """
  功能是检测进程是否正在运行
  如果进程没有运行,将会抛出ComponentIsNotRunning异常
  参数:pid_file  (保存pid的文件)
  """
  if not pid_file or not os.path.isfile(pid_file):
    raise ComponentIsNotRunning()
  with open(pid_file, "r") as f:
    try:
      pid = int(f.read())
    except:
      Logger.debug("Pid file {0} does not exist".format(pid_file))
      raise ComponentIsNotRunning()
    try:
      os.kill(pid, 0)
    except OSError:
      Logger.debug("Process with pid {0} is not running. Stale pid file"
                " at {1}".format(pid, pid_file))
      raise ComponentIsNotRunning()
  pass

?|1. ambari之check_process_status.py

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值