在网上找的抱歉忘了原链接了额 #!/usr/bin/env python##import osimport commandsimport reimport sys(status1, result1) = commands.getstatusoutput("/bin/ps -ef|grep /data/program/payment/payment-channel/|/bin/grep -v grep|/bin/awk '{print $2}'")channel_pid = result1(status2, result2) = commands.getstatusoutput("sudo /data/program/jdk/bin/jstat -gcutil %s 1s 1|/bin/awk '{print $3,$4,$5,$6,$7,$8,$9}'|/bin/sed -n '2'p" %(channel_pid))(status3, result3) = commands.getstatusoutput("sudo /data/program/jdk/bin/jstat -gccapacity %s 1s 1|/bin/awk '{print $1,$2,$7,$8,$11,$12}'|/bin/sed -n '2'p" %(channel_pid))#格式化为列表result4 = result2.split(' ')result5 = result3.split(' ')if result5[4] == result5[5]: channel_jvm_P = result4[2]else: channel_jvm_P = ((float(result5[5])*float(result4[2])/100) / float(result5[5]))*100if result5[2] == result5[3]: channel_jvm_O = result4[1]else: channel_jvm_O = ((float(result5[2])*float(result4[1])/100) / float(result5[3]))*100if result5[0] == result5[1]: channel_jvm_E = result4[0]else: channel_jvm_E = ((float(result5[1])*float(result4[0])/100) / float(result5[1]))*100channel_jvm_YGC = result4[3]channel_jvm_YGCT = result4[4]channel_jvm_FGC = result4[5]channel_jvm_FGCT = result4[6]channel_jvm_P = channel_jvm_P channel_jvm_E = channel_jvm_Ochannel_jvm_O = channel_jvm_E#channel_jvm_YGC+channel_jvm_YGCT+channel_jvm_FGC+channel_jvm_FGCTchannel_jvm_info = channel_jvm_YGC + ' ' + channel_jvm_YGCT + ' ' + channel_jvm_FGC + ' ' + channel_jvm_FGCT + '\n'(status6, result6) = commands.getstatusoutput("/usr/bin/tail -1 /tmp/channel_jvm_info_test.txt|/bin/awk '{print $1,$2,$3,$4}'")result7 = result6.split(' ')channel_jvm_old_YGC = result7[0]channel_jvm_old_YGCT = result7[1]channel_jvm_old_FGC = result7[2]channel_jvm_old_FGCT = result7[3]files = open('/tmp/channel_jvm_info_test.txt','w+')files.writelines(channel_jvm_info)files.close()channel_jvm_YGC_value = float(channel_jvm_YGC)-float(channel_jvm_old_YGC)channel_jvm_YGCT_value = float(channel_jvm_YGCT)-float(channel_jvm_old_YGCT)channel_jvm_FGC_value = float(channel_jvm_FGC)-float(channel_jvm_old_FGC)channel_jvm_FGCT_value = float(channel_jvm_FGCT)-float(channel_jvm_old_FGCT)channel_jvm_P_value = float(channel_jvm_P)channel_jvm_E_value = float(channel_jvm_E)channel_jvm_O_value = float(channel_jvm_O)result = 'channel_jvm_info is channel_jvm_YGC=%s channel_jvm_YGCT=%0.3f channel_jvm_FGC=%s channel_jvm_FGCT=%0.3f channel_jvm_P=%0.3f channel_jvm_E=%0.3f channel_jvm_O=%0.3f| channel_jvm_YGC=%s;5;10;0 channel_jvm_YGCT=%0.3f;0.2;0.5;0 channel_jvm_FGC=%s;1;2;0 channel_jvm_FGCT=%0.3f;0.5;1;0 channel_jvm_P=%0.3f;80;90;0 channel_jvm_E=%0.3f;80;90;0 channel_jvm_O=%0.3f;80;90;0' %(int(channel_jvm_YGC_value),float(channel_jvm_YGCT_value),int(channel_jvm_FGC_value),float(channel_jvm_FGCT_value),float(channel_jvm_P_value),float(channel_jvm_E_value),float(channel_jvm_O_value),int(channel_jvm_YGC_value),float(channel_jvm_YGCT_value),int(channel_jvm_FGC_value),float(channel_jvm_FGCT_value),float(channel_jvm_P_value),float(channel_jvm_E_value),float(channel_jvm_O_value))if (channel_jvm_YGC_value > 10 and channel_jvm_E_value > 90) or channel_jvm_YGC_value > 10 or channel_jvm_YGCT_value > 0.5 or channel_jvm_FGC_value > 2 or (channel_jvm_FGC_value > 2 and channel_jvm_O_value > 90) or channel_jvm_FGCT_value > 0.5 or channel_jvm_P_value > 90: print result sys.exit(2)elif (channel_jvm_YGC_value > 5 and channel_jvm_E_value > 80) or channel_jvm_YGC_value > 5 or channel_jvm_YGCT_value > 0.2 or channel_jvm_FGC_value > 1 or (channel_jvm_FGC_value > 1 and channel_jvm_O_value > 80) or channel_jvm_FGCT_value > 0.2 or channel_jvm_P_value > 80: print result sys.exit(1)elif (channel_jvm_YGC_value < 5 and channel_jvm_E_value < 80) or channel_jvm_YGC_value < 5 or channel_jvm_YGCT_value < 0.2 or channel_jvm_FGC_value < 1 or (channel_jvm_FGC_value < 1 and channel_jvm_O_value < 80) or channel_jvm_FGCT_value < 0.2 or channel_jvm_P_value < 80: print result sys.exit(0)