zabbix监控数据库
目录:zabbix && mongodb......1-1346
zabbix && redis........1349-3727
zabbix && mysql........3731-end
//zabbix 监控mongodb
cat /etc/zabbix/zabbix_agentd.d/userparameter_mongo.conf
UserParameter=mongo.service,ps -ef | grep mongo |grep -v grep |wc -l
UserParameter=mongo.mem_resident,echo "db.serverStatus().mem"| mongo|grep resident | cut -d ":" -f 2 |cut -d "," -f 1| cut -d " " -f 2
UserParameter=mongo.mem_virtual,echo "db.serverStatus().mem"| mongo|grep virtual | cut -d ":" -f 2 |cut -d "," -f 1| cut -d " " -f 2
UserParameter=mongo.mem_mapped,echo "db.serverStatus().mem"| mongo|grep '\bmapped\b' | cut -d ":" -f 2 |cut -d "," -f 1| cut -d " " -f 2
UserParameter=mongo.network
[*],echo "db.serverStatus().network"|mongo | grep $1 | cut -d ":" -f 2 |cut -d "," -f1 |cut -d " " -f 2
UserParameter=mongo.index
[*],echo "db.serverStatus().indexCounters"|mongo | grep $1| cut -d ":" -f 2 |cut -d "," -f1 |cut -d " " -f 2
UserParameter=mongo.connection_current,echo "db.serverStatus().connections"| mongo| grep current|cut -d ":" -f 2|cut -d "," -f 1|cut -d " " -f 2
UserParameter=mongo.connection_available,echo "db.serverStatus().connections"| mongo| grep current| cut -d ":" -f 3|cut -d "," -f 1 |cut -d " " -f 2
UserParameter=mongo.opcounters
[*],echo "db.serverStatus().opcounters" |mongo | grep $1|cut -d ":" -f 2|cut -d "," -f 1 |cut -d " " -f 2
UserParameter=mongo.rpstatus,echo "rs.status()"| mongo | grep myState| cut -d ":" -f 2| cut -d "," -f 1 |cut -d " " -f 2
UserParameter=mongo.queue_write,echo "db.serverStatus().globalLock.currentQueue.writers"|mongo |sed -n 3p
UserParameter=mongo.queue_reader,echo "db.serverStatus().globalLock.currentQueue.readers"|mongo |sed -n 3p
UserParameter=mongo.backgroundFlush,echo "db.serverStatus().backgroundFlushing.last_ms" |mongo |sed -n 3p
UserParameter=mongo.curosor_Totalopen,echo "db.serverStatus().cursors.totalOpen" |mongo |sed -n 3p
UserParameter=mongo.curospr_timedOu,echo "db.serverStatus().cursors.timedOut" |mongo |sed -n 3p
UserParameter=mongo.pagefaults,echo "db.serverStatus().extra_info.page_faults" |mongo|sed -n 3p
UserParameter=mongo.oplog_storetime,echo "db.printReplicationInfo()"|mongo|sed -n 4p|cut -d "(" -f 2|cut -d "h" -f 1
//根据xml文件直接导入模板++下载模板
http://pan.baidu.com/s/1hsMkxiW
+++++++++++++++++++++++++监控redis+++++++++++
//配置文件
cat userparameter_redis.conf
# Redis
# This content is licensed GNU GPL v2
# Author: Alexey Dubkov
# Discovery
UserParameter=redis.discovery,/etc/zabbix/script/redis/zbx_redis_stats.py -p 6379 -a Cloudcc@2017 192.168.5.205 list_key_space_db
# Return Redis statistics
UserParameter=redis
[*],/etc/zabbix/script/redis/zbx_redis_stats.py -p 6379 -a Cloudcc@2017 $1 $2 $3
vim /etc/hosts
//添加
172.16.1.172 L-172.16.1.172
//安装python依赖包
yum -y install python-pip
pip install argparse
pip install redis
mkdir -p /etc/zabbix/script/redis
chmod +x /etc/zabbix/script/redis/zbx_redis_stats.py
=================python程序============================
cat /etc/zabbix/script/redis/zbx_redis_stats.py
#!/usr/bin/python
import sys, redis, json, re, struct, time, socket, argparse
parser = argparse.ArgumentParser(description='Zabbix Redis status script')
parser.add_argument('redis_hostname',nargs='?')
parser.add_argument('metric',nargs='?')
parser.add_argument('db',default='none',nargs='?')
parser.add_argument('-p','--port',dest='redis_port',action='store',help='Redis server port',default=6379,type=int)
parser.add_argument('-a','--auth',dest='redis_pass',action='store',help='Redis server pass',default=None)
args = parser.parse_args()
zabbix_host = '192.168.5.209' # Zabbix Server IP
zabbix_port = 10051 # Zabbix Server Port
# Name of monitored server like it shows in zabbix web ui display
redis_hostname = args.redis_hostname if args.redis_hostname else socket.gethostname()
class Metric(object):
def __init__(self, host, key, value, clock=None):
self.host = host
self.key = key
self.value = value
self.clock = clock
def __repr__(self):
result = None
if self.clock is None:
result = 'Metric(%r, %r, %r)' % (self.host, self.key, self.value)
else:
result = 'Metric(%r, %r, %r, %r)' % (self.host, self.key, self.value, self.clock)
return result
def send_to_zabbix(metrics, zabbix_host='127.0.0.1', zabbix_port=10051):
result = None
j = json.dumps
metrics_data = []
for m in metrics:
clock = m.clock or ('%d' % time.time())
metrics_data.append(('{"host":%s,"key":%s,"value":%s,"clock":%s}') % (j(m.host), j(m.key), j(m.value), j(clock)))
json_data = ('{"request":"sender data","data":[%s]}') % (','.join(metrics_data))
data_len = struct.pack('
页:
[1]