#!/bin/sh
#!/bin/bash
#IT_BEGIN
#IT_TYPE=1
#原型指标
#IT DATABASE_MONGODB_ip|ip
#IT DATABASE_MONGODB_MONGODBPATH|MONGODBPATH
#IT DATABASE_MONGODB_version|version
#IT DATABASE_MONGODB_port|port
#IT DATABASE_MONGODB_logpath|logpath
#IT DATABASE_MONGODB_fork|fork
#IT DATABASE_MONGODB_maxConns|maxConns
#IT DATABASE_MONGODB_storageEngine|storageEngine
#IT DATABASE_MONGODB_bindIp|bindIp
#IT DATABASE_MONGODB_authorization|authorization
#IT DATABASE_MONGODB_replSetName|replSetName
#IT DATABASE_MONGODB_maxIncomingConnections|maxIncomingConnections
#IT DATABASE_MONGODB_current|current
#IT DATABASE_MONGODB_available|available
#IT DATABASE_MONGODB_syncdelay|syncdelay
#IT DATABASE_MONGODB_cpu|cpu
#IT DATABASE_MONGODB_nssize|nssize
#IT DATABASE_MONGODB_logappend|logappend
#IT DATABASE_MONGODB_wiredTigerCollectionBlockMaxWaitMS|wiredTigerCollectionBlockMaxWaitMS
#IT DATABASE_MONGODB_wiredTigerConcurrentReadLimit|wiredTigerConcurrentReadLimit
#IT DATABASE_MONGODB_resident|resident
#IT DATABASE_MONGODB_virtual|virtual
#IT DATABASE_MONGODB_journal|journal
#IT DATABASE_MONGODB_Confdir|Conf_dir
#IT DATABASE_MONGODB_dbPath|dbPath
#IT_END
shname=`basename $0`
ATTR="_X(g=$shname,p=cmdb,t=script,f=0)"
#多指标输出开始
echo COL_DETAIL_START:
hostname=`hostname -s`
#服务ip
if command -v ifconfig >/dev/null 2>&1; then
ip=`ifconfig -a | grep inet |grep -v 127.0.0.1 | grep -v "broadcast 0.0.0.0" | grep -v inet6 |awk '{print $2}' |cut -d ':' -f 2 | tr "\n" "," |sed 's/.$//g'`
elif command -v ip >/dev/null 2>&1; then
ip=`ip addr show| grep inet |grep -v 127.0.0.1 | grep -v "broadcast 0.0.0.0" | grep -v inet6 |awk '{print $2}' |cut -d '/' -f 1 | tr "\n" " " |sed 's/.$//g'`
elif command -v hostname >/dev/null 2>&1; then
ip=`hostname -I|tr " " ","| awk '{print substr($0, 1, length($0)-1)}'`
else
echo "command ifconfig or ip or hostname not exist!!!"
fi
#安装路径
# 查找mongod可执行文件的路径
pid=`ps -ef|grep mongo|grep -v grep | awk '{print $2}'`
#MONGODB_PATH=$(which mongod)
MONGODB_PATH=`ls -al /proc/${pid}/exe |awk '{print $NF}'`
#版本 version
#version=`mongo --eval 'db.version()' | grep -i "version" |grep -w "server"|awk '{ print $NF}'`
version=`mongod --version|grep "db version"|awk '{print $NF}'`
#配置文件
#Conf_dir=`ps -ef|grep mongo|grep -v grep|grep -oE '(/[^\]*\.config|/[^\]*\.conf)'|awk '{print $NF}'`
Conf_dir=`ps -ef|grep mongo|grep -v grep|grep -oP '[^ ]*(?<=\.conf)[^ ]*'|awk '{print $NF}'`
Get(){
cat ${Conf_dir} | sed -n '/^[ ]*#/!p' | grep -wi "$1" | cut -d "=" -f 2 |sed 's/"//g' |sed 's/ //g'|sed "s/'//g"
}
if [ -f $Conf_dir ];then
#端口
port=`Get port`
#日志文件路径
logpath=`Get logpath`
#数据文件存储路径
dbPath=`Get dbpath`
#以守护进程方式运行MongoDB
fork=`Get fork`
#同时打开的最大连接数
maxConns=`Get maxConns`
#指定存储引擎,如MMAPv1、WiredTiger(storageEngine)
storageEngine=`Get storageEngine`
#绑定的IP地址
bindIp=`Get bind_ip`
#是否启用用户认证
authorization=`Get authorization`
#副本集名称
replSetName=`Get replSetName`
#最大并发连接数
maxIncomingConnections=`Get maxIncomingConnections`
#当前活跃连接数
current=`Get current`
#可用连接数
available=`Get available`
#数据写入磁盘的延迟时间
syncdelay=`Get syncdelay`
#是否记录CPU利用率到日志
cpu=`Get cpu`
#.ns文件大小
nssize=`Get nssize`
#是否追加到现有日志文件
logappend=`Get logappend`
#读最大线程数
wiredTigerCollectionBlockMaxWaitMS=`Get wiredTigerCollectionBlockMaxWaitMS`
#线程池大小
wiredTigerConcurrentReadLimit=`Get wiredTigerConcurrentReadLimit`
#当前占据的内存大小
resident=`Get resident`
#虚拟内存大小
virtual=`Get virtual`
#数据操作记录日志
journal=`Get journal`
fi
echo "ip[$ATTR]|+|$ip"
echo "MONGODBPATH[$ATTR]|+|$MONGODB_PATH"
echo "version[$ATTR]|+|$version"
echo "port[$ATTR]|+|$port"
echo "logpath[$ATTR]|+|$logpath"
echo "fork[$ATTR]|+|$fork"
echo "maxConns[$ATTR]|+|$maxConns"
echo "storageEngine[$ATTR]|+|$storageEngine"
echo "bindIp[$ATTR]|+|$bindIp"
echo "authorization[$ATTR]|+|$authorization"
echo "replSetName[$ATTR]|+|$replSetName"
echo "maxIncomingConnections[$ATTR]|+|$maxIncomingConnections"
echo "current[$ATTR]|+|$current"
echo "available[$ATTR]|+|$available"
echo "syncdelay[$ATTR]|+|$syncdelay"
echo "cpu[$ATTR]|+|$cpu"
echo "nssize[$ATTR]|+|$nssize"
echo "logappend[$ATTR]|+|$logappend"
echo "wiredTigerCollectionBlockMaxWaitMS[$ATTR]|+|$wiredTigerCollectionBlockMaxWaitMS"
echo "wiredTigerConcurrentReadLimit[$ATTR]|+|$wiredTigerConcurrentReadLimit"
echo "resident[$ATTR]|+|$resident"
echo "virtual[$ATTR]|+|$virtual"
echo "journal[$ATTR]|+|$journal"
echo "Conf_dir[$ATTR]|+|$Conf_dir"
echo "dbPath[$ATTR]|+|$dbPath"
#多指标输出结束
echo COL_DETAIL_END:
运行结果如下:(10.14.1.43)
COL_DETAIL_START:
ip[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|10.14.1.43
MONGODBPATH[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|/usr/local/mongodb/bin/mongod
version[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|v4.2.19
port[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|2717
logpath[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|/usr/local/mongodb/logs
fork[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|true
maxConns[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|
storageEngine[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|
bindIp[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|0.0.0.0
authorization[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|
replSetName[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|
maxIncomingConnections[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|
current[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|
available[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|
syncdelay[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|
cpu[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|
nssize[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|
logappend[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|true
wiredTigerCollectionBlockMaxWaitMS[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|
wiredTigerConcurrentReadLimit[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|
resident[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|
virtual[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|
journal[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|true
Conf_dir[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|/usr/local/mongodb/etc/mongodb.conf
dbPath[_X(g=a.sh,p=cmdb,t=script,f=0)]|+|/usr/local/mongodb/data
COL_DETAIL_END: