• zabbix3.2监控mongodb


    模板地址:https://share.zabbix.com/databases/mongodb/mongodb-for-zabbix-3-2
    
    1.安装jq依赖
    # yum install jq -y
    
    2.添加监控用户
    # 使用admin登录mongo
    [root@eus_pe_web02:/usr/local/zabbix_agents_3.2.0/scripts]# mongo
    MongoDB shell version v3.4.6
    connecting to: mongodb://127.0.0.1:27017
    MongoDB server version: 3.4.6
    > use admin
    > db.auth('admin','admin')
    
    # 在admin高权限用户下授权monitor用户,改用户专门用来给zabbix提供监控数据
    >db.createUser(
    {
    user: "zabbix",
    pwd: "zabbix",
    roles: [
    { role: "clusterMonitor", db: "admin" }
    ]
    }
    )
    
    3.修改脚本
    [root@eus_pe_web02:/usr/local/zabbix_agents_3.2.0/scripts]# cat /usr/local/zabbix_agents_3.2.0/scripts/mongodb.sh 
    #!/bin/bash
    ##################################################
    # Description: zabbix mongodb monitor
    # Note: Zabbix 3.2
    # Date: Fri Apr 21 2017
    # Verion: 1.0
    # Requirments: mongo, jq, sudo access to mongo_conf.sh
    #
    # Based on Noe <netkiller@msn.com> script
    #
    # Change log:
    # Mon Apr 24, 2017
    #  - Added checks for mongo and jq
    #  - User --eval to fectch data
    #  - fixed json output to comform
    #  - Use jq to parse json https://stedolan.github.io/jq/
    #  - upated index to handle space or comma betwee values
    # 
    ##################################################
    source /etc/profile
    DB_HOST=127.0.0.1
    DB_PORT=27017
    DB_USERNAME=zabbix
    DB_PASSWORD=zabbix
    MONGO=`which mongo`
    JQ=`which jq`
    EXIT_ERROR=1
    EXIT_OK=0
    
    if [ ! -x "$MONGO" ] ; then
      echo "mongo not found"
      exit $EXIT_ERROR
    elif [ ! -x "$JQ" ] ; then
      echo "jq not found"
      exit $EXIT_ERROR
    elif [ $# -eq 0 ] ; then
      echo "No values pass"
      exit $EXIT_ERROR
    fi
    index=.$(echo $@ | sed 's/[ ,]/./g')
    MONGO_CMD="$MONGO --host ${DB_HOST:-localhost} --port ${DB_PORT:-27017} --authenticationDatabase admin --quiet"
    [[ "$DB_USERNAME" ]] && MONGO_CMD="${MONGO_CMD} --username ${DB_USERNAME}"
    [[ "$DB_PASSWORD" ]] && MONGO_CMD="${MONGO_CMD} --password ${DB_PASSWORD}"
    
    output=$(
        $MONGO_CMD <<< "db.runCommand( { serverStatus: 1} )" |
        sed -e 's/NumberLong((.*))/1/ 
          s/ISODate((.*))/1/
          s/ObjectId((.*))/1/
          s/Timestamp(.*)/"&"/
          s/(BinData(.*)"(.*)")/"12)"/
          s/"([0-9]*)"/1/' 
         
    )
    
    mongo_status=${PIPESTATUS[0]}
    if [ $mongo_status -ne $EXIT_OK ] ; then
      echo "mongo exec error"
      exit $EXIT_ERROR
    fi
    value=$(echo $output | jq $index)
    jq_status=$?
    echo $value
    
    
    4.添加配置文件
    # vim /usr/local/zabbix_agents_3.2.0/conf/zabbix_agentd/userparameter_mongodb.conf
    # Return MongoDB statistics
    UserParameter=mongodb.status[*],/usr/local/zabbix_agents_3.2.0/scripts/mongodb.sh  $1 $2 $3 $4 $5
    
    5.导入模板
    
    测试
    
    [root@aliyun-american-guigu-zabbix:~]# zabbix_get -s 1.1.1.1 -k 'mongodb.status[opcounters,query]'
    14
    [root@aliyun-american-guigu-zabbix:~]# zabbix_get -s 1.1.1.1 -k 'mongodb.status[mem,virtual]'
    933
  • 相关阅读:
    JDBC在getConnection之前为什么要调用Class.forName(转)
    ThreadPoolExecutor的一点理解 专题
    java.lang.NoSuchMethodError
    POJ 3380 最大流
    Spring3.0 AOP 具体解释
    深入浅出 RPC
    JUnit入门
    Linux makefile 教程 很具体,且易懂
    怎样修复“Windows/System32/Config/System中文件丢失或损坏”故障
    MessageDigest简单介绍
  • 原文地址:https://www.cnblogs.com/reblue520/p/9860261.html
Copyright © 2020-2023  润新知