#json脚本
#!/usr/bin/env python
import os
import json
data = []
command="ps aux | grep bz-tw-and-s | awk '{print $11}' | awk -F'/' '{print $2}'| grep -v '^$'"
service = os.popen('%s' % command ,'r').readlines()
for service in service:
service_name = ''.join(service).strip()
data += [{'{#SITENAME}': service_name}]
print json.dumps({'data':data},sort_keys=True,indent=7,separators=(',',':'))
#监控端口
#!/usr/bin/env python
import os
import sys
service_name = sys.argv[1]
process_command = "ps aux | grep %s | grep -v grep | awk '{print $2}' | wc -l" % service_name
os.system(process_command)
#!/usr/bin/env python
import os
mongo_port=os.popen('netstat -tlnp | grep mongod').readlines()
if mongo_port == []:
print 1
else:
print 0
新闻标题:python编写json脚本监控端口
本文链接:
http://kswsj.cn/article/ieghss.html