def getSmartdStatus(self): ## 检查smartd状态, smartd_stat, 1 正常, 0异常 smartPID = getProcessID("smartd") smartCfgLine = 0 fObj = open(DIRs['SMART_CFG_FILE']) fCon = fObj.readlines() for el in fCon: if el.split(): if not el.startswith("#"): smartCfgLine += 1 fObj.close() if smartPID and smartCfgLine > 0: smartd_stat = 1 else: smartd_stat = 0 self.data_for_post += "smartd_stat=%s&" % smartd_stat
def getAppStatus(self): ## 检查游戏程序运行状态, 0, 关闭; 1, 正常; 2, 异常 srvFlag = str(self.srvFlag) srvStatus, srvPidStatus, mUser = {'Success': [], 'Error': []}, {}, "*****@*****.**" ## srvNeedStart = ['DbCacheApp','LogDbApp','MailApp','SnapshotApp','CopyApp','CellMgrApp','CellApp','InterApp','GateMgrApp','GateApp','LoginApp'] for srv in gameApps: try: srv += "_" + srvFlag # App名_区服标识 srvPid = getProcessID(srv) # 调用shell pidof 获取pid if "GateApp" in srv: if srvPid: GateAppCount = len(srvPid.split()) # GateApp个数 else: GateAppCount = 0 if srvPid: srvStatus['Success'].append(srv) srvPidStatus[srv] = {srv+"_status": 1, srv+"_pid": srvPid} else: srvStatus['Error'].append(srv) srvPidStatus[srv] = {srv+"_status": 0, srv+"_pid": None} except Exception, err: saveLog.warning("getAppStatus() error occured while get proce pid, %s" % str(err))
def getNginxStatus(self): try: if os.path.exists("/usr/local/nginx/logs/nginx.pid"): fObj = open("/usr/local/nginx/logs/nginx.pid") ngxMainPid = fObj.read().strip() fObj.close() else: ngxMainPid = 0 pids = getProcessID("nginx") if ngxMainPid: if not pids or len(pids) < 8: wp = "" res = os.popen("ps -C nginx -o pid,cmd").readlines() for l in res: wp += "\n" + l.strip() if self.sDb.read(telIP, "ngxAlarm") == "ON": ## 状态为"NO"且开关为"ON"时,报故障 sub = "DBTX Nginx Alarm: %s" % ps1 msg = "Datetime: %s\nNginx主进程PID:%s\nWorker_processes:%s\n少于10个!!" % (getTimeNow(), ngxMainPid, wp) saveLog.warning(msg) sendMail(sub, msg) self.sDb.update(telIP, "ngxAlarm", "OFF") else: if self.sDb.read(telIP, "ngxAlarm") == "OFF": ## 状态OK且开关为"OFF"时,报恢复 sub = "DBTX Nginx is OK: %s" % ps1 msg = "Datetime: %s\nNginx主进程恢复开启状态." % (getTimeNow()) saveLog.info(msg) sendMail(sub, msg) self.sDb.update(telIP, "ngxAlarm", "ON") else: if self.sDb.read(telIP, "ngxAlarm") == "ON": ## 状态为"NO"且开关为"ON"时,报故障 sub = "DBTX Nginx Alarm: %s" % ps1 msg = "Datetime: %s\nNginx主进程挂了!!" % (getTimeNow()) saveLog.warning(msg) sendMail(sub, msg) self.sDb.update(telIP, "ngxAlarm", "OFF") except Exception,err: saveLog.warning("getNginxStatus, %s" % str(err))
def getCrondStatus(self): ## 检查crond状态, 1 正常, 0 异常 cronPID = getProcessID("crond") crond_status = 1 if cronPID else 0 self.data_for_post += "crond_status=%s&" % crond_status
def getNtpdStatus(self): ## 检查ntpd状态, 1 正常, 0 异常 ntpdPID = getProcessID("ntpd") ntpd_status = 1 if ntpdPID else 0 self.data_for_post += "ntpd_status=%s&" % ntpd_status