Python writes JSON script monitoring port

Source: Internet
Author: User

#json脚本#!/usr/bin/env pythonimport osimport jsondata = []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 pythonimport osimport sysservice_name = sys.argv[1]process_command = "ps aux | grep %s | grep -v grep | awk ‘{print $2}‘ | wc -l" % service_nameos.system(process_command)
#!/usr/bin/env pythonimport osmongo_port=os.popen(‘netstat -tlnp | grep mongod‘).readlines()if mongo_port == []:    print 1else:    print 0

Python writes JSON script monitoring port

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.