Lepus 天兔 监控-增加redis 内存使用报警
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Lepus 天兔 监控-增加redis 内存使用报警相关的知识,希望对你有一定的参考价值。
Lepus天兔搭建文档
文档连接:http://www.lepus.cc/manual/index
安装需求
php和Python都是跨平台的语言,所以理论上系统应该可以支持在不同的平台上运行。但是由于时间和精力以及资源有限,目前天兔系统只测试完善了Centos/RedHat系统的支持。我们目前提供的技术支持也是只针对于Centos/RedHat系统,其他系统暂不支持技术服务。
需要的核心包如下:
以下软件包只需要部署在监控机即可。被监控机无需部署。
1.mysql 5.0及以上(必须,用来存储监控系统采集的数据)
2.Apache 2.2及以上(必须,WEB服务器运行服务器)
3.PHP 5.3以上(必须,提供WEB界面支持)
4.Python2 (必须,推荐2.6及以上版本,执行数据采集和报警任务,不支持Python3)
5.Python连接和监控数据库的相关驱动模块包:
MySQLdb for python (Python连接MySQl的接口,用于监控MySQL,此模块必须安装)
cx_oracle for python (Python连接Oracle的接口,非必须,如果需要监控oracle此模块必须安装)
Pymongo for python (Python连接MongoDB的接口,非必须,如果需要监控MongoDB此模块必须安装)
redis-py for python (Python连接Redis的接口,非必须,如果需要监控Redis此模块必须安装)
安装LAMP环境
(略)
安装Python基础模块
首先安装Python环境(Python版本要求为Python2.6以上,不支持Python3)
其次安装数据库连接Python的驱动包
1.安装MySQLdb for python (必须安装)
MySQLdb为Python连接和操作MySQL的类库,如果您准备使用lepus系统监控MySQL数据库,那么该模块必须安装。
安装步骤如下:
#wgethttp://cdn.lepus.cc/cdncache/software/MySQLdb-python.zip
# unzip MySQLdb-python.zip
# cd MySQLdb1-master/
# which mysql_config
/usr/local/mysql/bin/mysql_config
# vim site.cfg 修改如下:
mysql_config =/usr/local/mysql/bin/mysql_config
echo"mysql_config = /usr/local/mysql/bin/mysql_config" >> site.cfg
# python setup.py build
# python setup.py install
常见错误解决:
1).如果编译python出现如下问题
/usr/bin/ld: cannot find -lpython2.7
collect2: ld returned 1 exit status
error: command ‘gcc‘ failed with exit status 1
请按如下步骤处理:
A.检查并安装python-devel包
# yum -y install python-devel
B.将libpython2.7.so库文件建立软连接到/usr/lib下
32位服务器下执行
# ln -s/usr/local/Python2.7/lib/libpython2.7.so /usr/lib/libpython2.7.so
64位服务器下执行
# ln -s/usr/local/Python2.7/lib/libpython2.7.so /usr/lib64/libpython2.7.so
C.检查下/etc/ld.so.conf是否包含/usr/local/Python2.7/lib
#vi /etc/ld.so.conf 添加/usr/local/Python2.7/lib
#/sbin/ldconfig
2).安装时一定要安装mysql-devel,否则上面安装报错。
yum install mysql-devel
3).需要制定so文件,否则报错。
find / -name libmysqlclient.so.18
cp/usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
2.安装cx_oracle for python (如果需要监控Oracle则必须安装)
下载安装oracleinstant client
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
如果是64位的,请选择.*x86_64.rpm,否则是.*i386.rpm
如果是oracle 9i或更高,请选择Instant Client 11,如果是8或8i,请选择Instant Client 10
[[email protected] software]# rpm -ivhoracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
Preparing...########################################### [100%]
1:oracle-instantclient11.###########################################[100%]
[[email protected] software]# rpm -ivhoracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
Preparing...########################################### [100%]
1:oracle-instantclient11.###########################################[100%]
[[email protected] software]# rpm -ivhoracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm
Preparing...########################################### [100%]
1:oracle-instantclient11.###########################################[100%]
[[email protected] home]# vim /root/.bash_profile
ORACLE_HOME="/usr/lib/oracle/11.2/client64"
PATH=$PATH:$ORACLE_HOME/bin
export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:/usr/local/lib
export LD_LIBRARY_PATH
修改完成后重新加载bash_profile文件
[[email protected] cx_Oracle-5.1.2]# source ~/.bash_profile
[[email protected] software]# vim /etc/ld.so.conf加入
/usr/lib/oracle/11.2/client64/lib
执行ldconfig生效
[[email protected] software]# ldconfig
安装cx_oracle
# wget http://cdn.lepus.cc/cdncache/software/cx_Oracle-5.1.2.tar.gz
# tar zxvf cx_Oracle-5.1.2.tar.gz
# cd cx_Oracle-5.1.2
# python setup.py build
# python setup.py install
3.安装Pymongo for python (如果需要监控Mongodb则必须安装)
pymongo为Python连接和操作MongoDB的类库,如果您准备使用lepus系统监控MongoDBs数据库,那么该模块必须安装。
安装步骤如下:
# wget http://cdn.lepus.cc/cdncache/software/pymongo-2.7.tar.gz
# tar zxvf pymongo-2.7.tar.gz
# cd pymongo-2.7
# python setup.py install
4.安装Redis 驱动(如果需要监控Redis则必须安装)
# wget http://cdn.lepus.cc/cdncache/software/redis-py-2.10.3.tar.gz
# tar zxvf redis-py-2.10.3.tar.gz
# cd redis-2.10.3/
# python setup.py install
5.安装SQLServer驱动(如果需要监控SQLServer则必须安装)
安装pymssql需要的包:
freetds(http://www.filewatcher.com/m/freetds-0.82.tar.gz.1596755-0.html)
setuptools(https://pypi.python.org/pypi/setuptools)
pymssql(https://pypi.python.org/pypi/pymssql/)
安装步骤:
A. 安装freetds
#tar zxvf freetds-0.82.tar.gz
#cd freetds-0.82
#./configure --prefix=/usr/local/freetds--with-tdsver=8.0 --enable-msdblib --enable-dbmfix --with-gnu-ld--enable-shared --enable-static
#make && make install
#echo "/usr/local/freetds/lib">> /etc/ld.so.conf.d/freetds.conf
#ldconfig -v
B. 安装setuptools
#tar zxvf setuptools-3.5.1.tar.gz
#cd setuptools-3.5.1
# python setup.py install
C. 安装pymssql
#tar zxvf pymssql-2.1.0.tar.gz
#cd pymssql-2.1.0
#python setup.py install
注:如果不安装freetds,会报如下错误:
error: command ‘gcc‘ failed with exit status 1
6.测试各个驱动是否正常运行(非必须)
在lepus的安装文件包python目录中,你可以找到如下测试文件,测试上述驱动是否安装正确。
# python test_driver_mysql.py
MySQL python drivier is ok!
# python test_driver_oracle.py
Oracle python drivier is ok!
# python test_driver_mongodb.py
MongoDB python drivier is ok!
# python test_driver_redis.py
Redis python drivier is ok!
安装Lepus采集器
安装Lepus监控系统
注:在安装Lepus系统之前,请先根据前面内容安装LAMP和Python运行基础环境。
1)上传软件包到监控机服务器并解压缩软件到您的系统
# unzip lepus_vx.x.x.zip
2).在监控机创建监控数据库,并授权。
mysql> create database lepus defaultcharacter set utf8;
mysql> grantselect,insert,update,delete,create on lepus.* to ‘lepus_user‘@‘localhost‘identified by ‘xxxxxx‘;
##以上的是对监控机的程序连接数据库进行的授权,与对其他mysql实例监控无关。
mysql> flush privileges;
导入SQL文件夹里的SQL文件(表结构和数据文件)
# mysql -uroot –p lepus < sql/lepus_table.sql
# mysql -uroot –p lepus < sql/lepus_data.sql
注意:需要修改lepus_table.sql脚本中的字段host的长度,因为规定了varchar(30),如果监控类似阿里云RDS时,主机名长度在40以上,那么此时数据库会截断该字段,造成无法同被监控数据库实例相连。
4)安装Lpeus程序
进入到软件包的python文件夹
# cd python/
授予install.sh可执行权限
# chmod +x install.sh
执行安装
# ./install.sh
[note] lepus will be install on basedir:/usr/local/lepus
[note] /usr/local/lepus directory does notexist,will be created.
[note] /usr/local/lepus directory createdsuccess.
[note] wait copy files.......
[note] change script permission.
[note] create links.
[note] install complete.
5) 修改配置文件
进入到安装目录,默认为/usr/local/lepus
# cd /usr/local/lepus/
# vim etc/config.ini
###监控机MySQL数据库连接地址###
[monitor_server]
host="127.0.0.1"
port=3306
user=" lepus_user “
##该用户填写上面的对监控机的授权
passwd="xxxxxx"
dbname="lepus"
6) 启动Lepus (可选)
此时,你可以执行启动命令启动lepus采集进程
[[email protected] lepus]# lepus start
nohup: 把输出追加到"nohup.out"
lepus server start success!
但是因为没有添加主机,所以查看日志会看到如下提示,属于正常提示。您也可以在部署完Lepus WEB控制台后再进行启动。
[[email protected] lepus]# tail -f logs/lepus.log
2015-08-03 13:09:09 [WARNING] check mongodb:not found any servers
2015-08-03 13:09:09 [INFO] check mongodbcontroller finished.
2015-08-03 13:09:12 [INFO] check rediscontroller started.
2015-08-03 13:09:12 [WARNING] check redis: notfound any servers
2015-08-03 13:09:12 [INFO] check rediscontroller finished.
2015-08-03 13:09:15 [INFO] check os controllerstarted.
2015-08-03 13:09:15 [WARNING] check os: notfound any servers
2015-08-03 13:09:15 [INFO] check os controllerfinished.
2015-08-03 13:09:38 [INFO] alarm controllerstarted.
2015-08-03 13:09:38 [INFO] alarm controllerfinished.
Lepus采集程序安装完毕!
安装WEB管理台
复制PHP文件夹里的文件到Apache对应的网站虚拟目录(备注:根本不同的安装方式,这个目录是不一样的,如果采用xampp安装的Apache环境,则默认程序目录为/opt/lampp/htdocs/),例如
# cp -rf php/* /opt/lampp/htdocs/
打开application\config\database.php文件,修改PHP连接监控服务器的数据库信息
$db[‘default‘][‘hostname‘] = ‘127.0.0.1‘;
$db[‘default‘][‘username‘] = ‘lepus_user‘;
$db[‘default‘][‘password‘] = ‘xxxxxx‘;
$db[‘default‘][‘database‘] = lepus;
$db[‘default‘][‘dbdriver‘] = ‘mysql‘;
9)登录进行添加主机和监控
通过浏览器输入IP地址或域名打开监控界面,即可登录系统。.默认管理员账号密码admin/Lepusadmin登录后请修改管理员密码,增加普通账号。
启动和关闭Lepus
启动监控系统
执行以下命令启动系统采集进程
# lepus start
执行以下命令关闭系统采集进程
# lepus stop
执行以下命令监控系统是否正常运行
# lepus status
lepus server is running...
查看启动关闭帮助命令
#lepus --help
lepus help:
support-site: www.lepus.cc
====================================================================
start Start lepus monitor server; Command: #lepus start
stop Stop lepus monitor server; Command: #lepus stop
status Check lepus monitor run status; Command: #lepus status
监控主机OS系统
yum -y install net-snmp*
sed -i "s/com2sec notConfigUser default public/com2sec notConfigUser 10.44.183.33 lepus/g"/etc/snmp/snmpd.conf
sed -i "s/systemview none none/all nonenone/g" /etc/snmp/snmpd.conf
sed -i "s/#view all included /view all included /g" /etc/snmp/snmpd.conf
#/etc/init.d/snmpd start
#grep ‘Simple Net Mgmt Proto‘ /etc/services
#echo $?
#lsof -i :161
#ps -ef | grep ‘snmpd‘
sed -i ‘s|OPTIONS="-LS0-6d -Lf /dev/null-p /var/run/snmpd.pid"|OPTIONS="-LS 4 d -p /var/run/snmpd.pid-a"|g‘ /etc/init.d/snmpd
/etc/init.d/snmpd restart
监控机器验证脚本
for ip in 192.168.1.10 192.168.1.11
do
snmpwalk -v 1 -c lepus $ip
snmpwalk -v 2c -c lepus $ip
done
修改库增加监控:
update lepus.db_servers_os setthreshold_warning_os_process=1000 ,threshold_critical_os_process=1500 wherehost=‘10.47.210.138‘;
lepus.db_servers_os
insert into lepus.db_servers_os(host,community,tags,monitor,send_mail,threshold_warning_os_process,threshold_critical_os_process)values(‘10.45.14.51‘,‘lepus‘,‘Comment_DB_S1‘,1,1,1000,1500);
insert intolepus.db_servers_os(host,community,tags,monitor,send_mail,threshold_warning_os_process,threshold_critical_os_process)values(‘10.47.211.26‘,‘lepus‘,‘redis2_socket_OS‘,1,1,1000,1500);
lepus.db_servers_redis
insert into lepus.db_servers_redis values(0,‘10.47.211.26‘,6784, null,"redis1_socket_6684_slave",1,1,"[email protected]",0,null,1,1,1,1000,10000,5,3000,12000,15,0,0,CURRENT_TIMESTAMP );
注:OS 中网络的单位是KB。
监控MySQL数据库
授权即可
GRANT PROCESS, SUPER ON *.* TO‘lepus‘@‘10.44.183.33‘ IDENTIFIED BY PASSWORD ‘*FCCFDA924CEE3ED0338661DD2144CA85326E2F4D‘
注意:
1.后期添加新db类型监控项如Oracle,mongodb时,需安装python模块后进行验证,然后平台配置中,需要注意开启全局设置中的开关,同时需要重启lepus后才可正常采集数据。
添加对redis的内存监控
表结构修改:
##增加redis阈值报警字段,默认警告阈值为80%,默认严重阈值为90%,如需调整,则到DB中手动进行调整。
alter tabledb_servers_redis add `alarm_memory_used` tinyint(2) NOT NULL DEFAULT ‘1‘,add`threshold_warning_memory_used_percent` bigint(20) NOT NULL DEFAULT ‘80‘,add`threshold_critical_memory_used_percent` bigint(20) NOT NULL DEFAULT ‘90‘;
alter tableredis_status add `maxmemory` bigint(20) NOT NULL DEFAULT ‘-1‘;
alter tableredis_status_history add `maxmemory` bigint(20) NOT NULL DEFAULT ‘-1‘ aftercreate_time;
修改py脚本
……………………………………修改check_redis.py,添加最大内存配置查询项
defcheck_redis(host,port,passwd,server_id,tags):
try:
r=redis.StrictRedis(host=host,port=int(port),password=passwd,db=0,socket_timeout=3,charset=‘utf-8‘)
info=r.info()
time.sleep(1)
info_2=r.info()
config=r.config_get()
#get config
maxmemory = config[‘maxmemory‘]
# Server
redis_version = info[‘redis_version‘]
sql = "insertintoredis_status(server_id,host,port,tags,redis_role,connect,redis_version,redis_git_sha1,redis_git_dirty,redis_mode,os,arch_bits,multiplexing_api,gcc_version,process_id,run_id,tcp_port,uptime_in_seconds,uptime_in_days,hz,lru_clock,connected_clients,client_longest_output_list,client_biggest_input_buf,blocked_clients,used_memory,used_memory_human,used_memory_rss,used_memory_peak,used_memory_peak_human,used_memory_lua,mem_fragmentation_ratio,mem_allocator,loading,rdb_changes_since_last_save,rdb_bgsave_in_progress,rdb_last_save_time,rdb_last_bgsave_status,rdb_last_bgsave_time_sec,rdb_current_bgsave_time_sec,aof_enabled,aof_rewrite_in_progress,aof_rewrite_scheduled,aof_last_rewrite_time_sec,aof_current_rewrite_time_sec,aof_last_bgrewrite_status,total_connections_received,total_commands_processed,current_commands_processed,instantaneous_ops_per_sec,rejected_connections,expired_keys,evicted_keys,keyspace_hits,keyspace_misses,pubsub_channels,pubsub_patterns,latest_fork_usec,used_cpu_sys,used_cpu_user,used_cpu_sys_children,used_cpu_user_children,maxmemory)values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);"
param =(server_id,host,port,tags,role,connect,redis_version,redis_git_sha1,redis_git_dirty,redis_mode,os,arch_bits,multiplexing_api,gcc_version,process_id,run_id,tcp_port,uptime_in_seconds,uptime_in_days,hz,lru_clock,connected_clients,client_longest_output_list,client_biggest_input_buf,blocked_clients,used_memory,used_memory_human,used_memory_rss,used_memory_peak,used_memory_peak_human,used_memory_lua,mem_fragmentation_ratio,mem_allocator,loading,rdb_changes_since_last_save,rdb_bgsave_in_progress,rdb_last_save_time,rdb_last_bgsave_status,rdb_last_bgsave_time_sec,rdb_current_bgsave_time_sec,aof_enabled,aof_rewrite_in_progress,aof_rewrite_scheduled,aof_last_rewrite_time_sec,aof_current_rewrite_time_sec,aof_last_bgrewrite_status,total_connections_received,total_commands_processed,current_commands_processed,instantaneous_ops_per_sec,rejected_connections,expired_keys,evicted_keys,keyspace_hits,keyspace_misses,pubsub_channels,pubsub_patterns,latest_fork_usec,used_cpu_sys,used_cpu_user,used_cpu_sys_children,used_cpu_user_children,maxmemory)
vim alarm.py
……………………………………修改alarm.py,添加内存的查询项
defget_alarm_redis_status():
sql = "selecta.server_id,a.connect,a.connected_clients,a.current_commands_processed,a.blocked_clients,a.create_time,b.host,b.port,b.alarm_connected_clients,b.alarm_command_processed,b.alarm_blocked_clients,b.threshold_warning_connected_clients,b.threshold_critical_connected_clients,b.threshold_warning_command_processed,b.threshold_critical_command_processed,b.threshold_warning_blocked_clients,b.threshold_critical_blocked_clients,b.send_mail,b.send_mail_to_list,b.send_sms,b.send_sms_to_list,b.tags,‘redis‘as db_type,b.alarm_memory_used,b.threshold_warning_memory_used_percent,b.threshold_critical_memory_used_percent,round(a.used_memory/1024/1024)as memory_used_MB,round(a.maxmemory/1024/1024) asmaxmemory_MB,round(a.used_memory/a.maxmemory*100) as used_max_memory_percentfrom redis_status a, db_servers_redis b where a.server_id=b.id ;"
result=func.mysql_query(sql)
if result <> 0:
for line in result:
server_id=line[0]
connect=line[1]
connected_clients=line[2]
current_commands_processed=line[3]
blocked_clients=line[4]
create_time=line[5]
host=line[6]
port=line[7]
alarm_connected_clients=line[8]
alarm_command_processed=line[9]
alarm_blocked_clients=line[10]
threshold_warning_connected_clients=line[11]
threshold_critical_connected_clients=line[12]
threshold_warning_command_processed=line[13]
threshold_critical_command_processed=line[14]
threshold_warning_blocked_clients=line[15]
threshold_critical_blocked_clients=line[16]
send_mail=line[17]
send_mail_to_list=line[18]
send_sms=line[19]
send_sms_to_list=line[20]
tags=line[21]
db_type=line[22]
alarm_memory_used=line[23]
threshold_warning_memory_used_percent=line[24]
threshold_critical_memory_used_percent=line[25]
memory_used_MB=line[26]
maxmemory_MB=[27]
used_max_memory_percent=line[28]
……………………………………………… (在”ifint(alarm_command_processed)==1:”前面加上对于内存的报警)
if int(alarm_memory_used)==1:
ifint(used_max_memory_percent) >= int(threshold_critical_memory_used_percent):
send_mail =func.update_send_mail_status(server_id,db_type,‘used_max_memory_percent‘,send_mail,send_mail_max_count)
send_sms =func.update_send_sms_status(server_id,db_type,‘used_max_memory_percent‘,send_sms,send_sms_max_count)
func.add_alarm(server_id,tags,host,port,create_time,db_type,‘used_max_memory_percent‘,used_max_memory_percent,‘critical‘,‘toomuch memory used‘,send_mail,send_mail_to_list,send_sms,send_sms_to_list)
func.update_db_status(‘sessions‘,3,host,port,create_time,‘used_max_memory_percent‘,used_max_memory_percent,‘critical‘)
elif int(used_max_memory_percent)>= int(threshold_warning_memory_used_percent):
send_mail =func.update_send_mail_status(server_id,db_type,‘used_max_memory_percent‘,send_mail,send_mail_max_count)
send_sms =func.update_send_sms_status(server_id,db_type,‘used_max_memory_percent‘,send_sms,send_sms_max_count)
func.add_alarm(server_id,tags,host,port,create_time,db_type,‘used_max_memory_percent‘,used_max_memory_percent,‘warning‘,‘toomuch memory used‘,send_mail,send_mail_to_list,send_sms,send_sms_to_list)
func.update_db_status(‘sessions‘,2,host,port,create_time,‘used_max_memory_percent‘,used_max_memory_percent,‘warning‘)
else:
func.check_if_ok(server_id,tags,host,port,create_time,db_type,‘used_max_memory_percent‘,used_max_memory_percent,‘memoryis ok‘,send_mail,send_mail_to_list,send_sms,send_sms_to_list)
func.update_db_status(‘sessions‘,1,host,port,create_time,‘used_max_memory_percent‘,used_max_memory_percent,‘ok‘)
ifint(alarm_command_processed)==1:
本文出自 “浮生凤年” 博客,请务必保留此出处http://liuzhanbin.blog.51cto.com/10060150/1891775
以上是关于Lepus 天兔 监控-增加redis 内存使用报警的主要内容,如果未能解决你的问题,请参考以下文章