Zabbix automatically detects and monitors remote MongoDB instances based on host and port lists

Source: Internet
Author: User
In some cases, you can only use a remote MongoDB instance instead of logging on to the server where the MongoDB instance is located. In this case, you can maintain the host and port list of a remote MongoDB instance on one server, then use z

In some cases, you can only use a remote MongoDB instance instead of logging on to the server where the MongoDB instance is located. In this case, you can maintain the host and port list of a remote MongoDB instance on one server, then use z

In some cases, you can only use a remote MongoDB instance instead of logging on to the server where the MongoDB instance is located. In this case, you can maintain the host and port list of a remote MongoDB instance on one server ,, then, the corresponding monitoring is automatically added based on the host and port through the low-level Discovery Function of zabbix.


  • MongoDB host and port discovery steps mongodb_discovery.py

    The host and port information of each instance is stored in the mongodb_servers.txt file.


  • 10.4.9.112: 28018: root: xxxx10.4.9.2: 27017: root10.4.9.3: 28018 #/usr/bin/python # This script is used to discovery disk on the serverimport subprocessimport jsonargs = '''awk-F': ''{print $1 ": "$2} '/usr/local/zabbix/bin/mongodb_servers.txt ''' t = subprocess. popen (args, shell = True, stdout = subprocess. PIPE ). communicate () [0] mongodbs = [] for mongo in t. split ('\ n'): if len (mongo )! = 0: Invalid DBS. append ({'{# MONGO_HOST}': mongo}) print json. dumps ({'data': mongodbs}, indent = 4, separators = (',',':'))


    Display result:

    {"Data": [{"{# MONGO_HOST}": "192.168.5.7: 30000" },{ "{# MONGO_HOST}": "192.168.5.7: 30001 "}, {"{# cmd_host}": "192.168.5.23: 30002" },{ "{# cmd_host}": "192.168.5.23: 30003"}]}



    2. script for obtaining MongoDB port status information discovery_mongodb_status.sh

    Here, we will find the corresponding row in the mongodb_servers.txt file and use the colon ":" to determine the length of the entire row, and then use different mongodb connection methods.

    # This script is used to get discovered mongodb servers status # echo "db. serverStatus (). uptime "| mongo 192.168.5.23: 30002/admin-uroot-pxxxx # echo" db. serverStatus (). mem. mapped "| mongo 192.168.5.23: 30002/admin-uroot-pxxx # echo" db. serverStatus (). globalLock. activeClients. total "| mongo 192.168.5.23: 30002/admin-uroot-pxxx # Macro {# cmd_info}" HOSTNAME: PORT: USERNAME: PASSWORD "# sh discovery_mongodb_status. Sh uptime {# cmd_host} # sh cmdmem mapped {# cmd_host} # sh cmdgloballock activeClients total {# cmd_host} # one more parameter1__info = "" command_line = "" function check_cmd_info () {num = $ (echo $ cmd_info | awk-F ":" '{print NF}') host = $ (echo $ cmd_info | awk-F ": "'{print $1}') port = $ (echo $ pai_info | awk-F": "'{print $2}') username = $ (echo $ mong O_info | awk-F ":" '{print $3}') password = $ (echo $ response _info | awk-F ":" '{print $4 }') case $ num in 2) command_line = "/data/app_platform/mongodb/bin/mongo $ host: $ port/admin"; 3) command_line = "/data/app_platform/mongodb/bin/mongo $ host: $ port/admin-u $ username-p'' "; 4) command_line = "/data/app_platform/mongodb/bin/mongo $ host: $ port/admin-u $ username-p $ password"; esac} case $ # in 2) performance_info = $ (gr Ep $2/usr/local/zabbix/bin/mongodb_servers.txt) check_mongo_info output = $ (/bin/echo "db. serverStatus (). $1 "| $ command_line | sed-n '3'); 3) mongo_info = $ (grep $3/usr/local/zabbix/bin/mongodb_servers.txt) check_mongo_info output = $ (/bin/echo "db. serverStatus (). $1. $2 "| $ command_line | sed-n '3'); 4) mongo_info = $ (grep $4/usr/local/zabbix/bin/mongodb_servers.txt) check_cmd_info output = $ (/bin/ech O "db. serverStatus (). $1. $2. $3 "| $ command_line | sed-n '3'); esac # check if the output contains" NumberLong "if [[" $ output "= ~ "NumberLong"]; then echo $ output | sed-n's/NumberLong (// P' | sed-n's/) // P' else echo $ outputfi

    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.