def monitorDisk(monitorSystemObject,saveDbMsgDict): """ @monitorSystemObject {'cpu_idle_limit':cpu_idle_limit,'memory_avi_limit':memory_avi_limit,'hardspace_name':hardspace_name,'hardspace_limit':hardspace_limit} hardspace_name:有可能是用||分隔的多行参数.hardspace_limit:有可能是ongoing||分隔的多行. windows 版本的磁盘空间检查,monitorDiskOjectList [{'hardspace_name':hardspace_name,'hardspace_limit':hardspace_limit}] """ warnToPersonList=[] monitorDiskObjectList=[] saveToDBList=[]#[(文件系统,总计大小,已用空间,可用空间,已用%,挂载点)] if monitorSystemObject.has_key('hardspace_name')==False or monitorSystemObject.has_key('hardspace_limit')==False: return warnToPersonList elif len(monitorSystemObject['hardspace_name'].split('||'))<>len(monitorSystemObject['hardspace_limit'].split('||')): log.info('磁盘监控:monitor_pt_system_info表的hardspace_name值与hardspace_limit值配置的不完全匹配') return warnToPersonList for i in range(len(monitorSystemObject['hardspace_name'].split('||'))): monitorDiskObjectList.append({'hardspace_name':monitorSystemObject['hardspace_name'].split('||')[i],'hardspace_limit':monitorSystemObject['hardspace_limit'].split('||')[i]}) saveDbMsgDict['hardSpace']=saveToDBList for monitorDiskObject in monitorDiskObjectList: try: log.info('磁盘告警配置:%s',str(monitorDiskObject)) if monitorDiskObject['hardspace_name'].strip()=='': break #if monitorDiskObject['hardspace_limit'].isdigit(): try: total,used,free,usedPecent=SystemInfo.getdiskByPath(monitorDiskObject['hardspace_name']) saveToDBList.append((monitorDiskObject['hardspace_name'],str(total/1024),str(used/1024),str(free/1024),str(usedPecent),'')) limitPercent=float(monitorDiskObject['hardspace_limit']) if usedPecent>=limitPercent: log.info("磁盘空间告警: hardspace_name:%s,limit_used_percent:%s,real_used_percent:%s",monitorDiskObject['hardspace_name'],monitorDiskObject['hardspace_limit'],str(round(usedPecent,2))) warnStr=MONITOR_NAME+' 磁盘空间告警:hardspace_name:'+monitorDiskObject['hardspace_name']+' limit_used_percent:'+monitorDiskObject['hardspace_limit']+' real_used_percent:'+str(round(usedPecent,2)) warnToPersonList.append(warnStr) except ValueError: log.info('磁盘告警配置,磁盘空间%s的阀值非数值=%s',monitorDiskObject['hardspace_name'],monitorDiskObject['hardspace_limit']) except Exception: log.exception('获取磁盘空间报错。磁盘为:'+monitorDiskObject['hardspace_name']) return warnToPersonList