search
HomeDatabaseMysql TutorialNagios监控生产环境redis集群服务实战
Nagios监控生产环境redis集群服务实战Jun 07, 2016 pm 04:04 PM
nagiosredisActual combatServeenvironmentProductionmonitorcluster

前言: 以前做了cacti上展示redis性能报表图,可以看到redis的性能变化趋势图, 但是还缺了实时报警通知的功能,现在补上这一环节。在redis服务瓶颈或者异常时候即使报警通知,方便dba第一时间处理维护。 1,下载redis监控插件 Redis已经在服务器安装好了,

前言: 以前做了cacti上展示redis性能报表图,可以看到redis的性能变化趋势图,但是还缺了实时报警通知的功能,现在补上这一环节。在redis服务瓶颈或者异常时候即使报警通知,方便dba第一时间处理维护。
1,下载redis监控插件

Redis已经在服务器安装好了,所以直接可以进行监控,redis集群安装请参考:http://blog.itpub.net/26230597/viewspace-1145831/,下载地址为:http://download.csdn.net/detail/mchdba/8023351,有2个版本,一个是perl脚本写成的,一个是php脚本写成的,可以任意选择一个,这里选择的是perl脚本。

2,赋予执行权限

将check_redis.php和check_redis.pl复制到/usr/lib/nagios/plugins/目录,然后赋予执行权限,

[root@wgq_41 plugins]# cd /usr/lib/nagios/plugins/

[root@wgq_41 plugins]# chown -R nagios.nagios check_redis.*

[root@wgq_41 plugins]# chmod 750 check_redis.*

3,定义监控命令

[root@wgq objects] vim /usr/local/nagios/etc/objects/commands.cfg

# add by tim on 20141010,for redis

# check redis

define command {

command_name check_redis

command_line /usr/lib/nagios/plugins/check_redis.pl -H $HOSTADDRESS$ -p $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$ -f

}

4,定义redis监控主机

[root@wgq etc]# vim /usr/local/nagios/etc/hosts.cfg

# No.018,redis master server

define host{

use linux-server

host_name cache-1

alias cache-1

address 10.xxx.3.x0

check_command check-host-alive

max_check_attempts 5

check_period 24x7

contact_groups ops

notification_interval 30

notification_period 24x7

notification_options d,u,r

}

# No.020 cache-3 redis slave server

define host{

use linux-server

host_name cache-3

alias cache-3

address 10.xx.3.x2

check_command check-host-alive

max_check_attempts 5

check_period 24x7

contact_groups ops

notification_interval 30

notification_period 24x7

notification_options d,u,r

}

5,定义redis监控主机组

define hostgroup {

hostgroup_name Redis_Servers

alias Redisservices

members cache-1,cache-2

}

6,定义redis监控服务选项

[root@wgq objects]# vim /usr/local/nagios/etc/objects/services_redis.cfg

# Redis Master 监控选项

define service {

host_name cache-1

servicegroups Redisservices

service_description Redis Master Clients

check_command check_redis!6379!'connected_clients,blocked_clients,client_longest_output_list,client_biggest_input_buf'!200,50,~,~!600,150,~,~

max_check_attempts 5

normal_check_interval 3

retry_check_interval 2

check_period 24x7

notification_interval 10

notification_period 24x7

notification_options w,u,c,r

contact_groups ops

}

define service {

host_name cache-1

servicegroups Redisservices

service_description Redis Master Memory

check_command check_redis!6379!'used_memory_human,used_memory_peak_human'!~,~!~,~

max_check_attempts 5

normal_check_interval 3

retry_check_interval 2

check_period 24x7

notification_interval 10

notification_period 24x7

notification_options w,u,c,r

contact_groups ops

}

define service {

host_name cache-1

servicegroups Redisservices

service_description Redis Master CPU

check_command check_redis!6379!'used_cpu_sys,used_cpu_user,used_cpu_sys_children,used_cpu_user_children'!~,~,~,~!~,~,~,~ ; #未定义监控报警阀值

max_check_attempts 5

normal_check_interval 3

retry_check_interval 2

check_period 24x7

notification_interval 10

notification_period 24x7

notification_options w,u,c,r

contact_groups ops

}

# Redis Slave 监控选项

define service {

host_name cache-3

servicegroups Redisservices

service_description Redis Slave Clients

check_command check_redis!6379!'connected_clients,blocked_clients,client_longest_output_list,client_biggest_input_buf'!200,50,~,~!600,150,~,~

max_check_attempts 5

normal_check_interval 3

retry_check_interval 2

check_period 24x7

notification_interval 10

notification_period 24x7

notification_options w,u,c,r

contact_groups ops

}

define service {

host_name cache-3

servicegroups Redisservices

service_description Redis Slave Memory

check_command check_redis!6379!'used_memory_human,used_memory_peak_human'!~,~!~,~

max_check_attempts 5

normal_check_interval 3

retry_check_interval 2

check_period 24x7

notification_interval 10

notification_period 24x7

notification_options w,u,c,r

contact_groups ops

}

define service {

host_name cache-3

servicegroups Redisservices

service_description Redis Slave CPU

check_command check_redis!6379!'used_cpu_sys,used_cpu_user,used_cpu_sys_children,used_cpu_user_children'!~,~,~,~!~,~,~,~ ; #未定义监控报警阀值

max_check_attempts 5

normal_check_interval 3

retry_check_interval 2

check_period 24x7

notification_interval 10

notification_period 24x7

notification_options w,u,c,r

contact_groups ops

}

赋予nagios用户执行权限

[root@wgq objects]# chown -R nagios.nagios services_redis.cfg

[root@wgq objects]# chmod 777 services_redis.cfg

添加监控服务项到nagios.cfg

[root@wgq etc]# vim /usr/local/nagios/etc/nagios.cfg

cfg_file=/usr/local/nagios/etc/objects/services_redis.cfg

7,测试redis监控服务

执行命令/usr/lib/nagios/plugins/check_redis.pl -H cache-1 -a 'connected_clients,blocked_clients' -w ~,~ -c ~,~ -m -M 4G -A -R -T 来测试下redis监控是否正常运行

[root@wgq plugins]# /usr/lib/nagios/plugins/check_redis.pl -H 10.2xx.3.x0 -a 'connected_clients,blocked_clients' -w ~,~ -c ~,~ -m -M 4G -A -R -T

OK: REDIS 2.8.8 on 10.2xx.3.x0:6379 has 1 databases (db0) with 28497 keys, up 76 days 2 hours - response in 0.004s, hitrate is 12.83%, memory use is 194.14M (peak 205.14M, 6.49% of max, fragmentation 1.37%), connected_clients is 35, blocked_clients is 11 | redis_build_id=d322d411218ade61 total_connections_received=341191c used_memory_lua=33792 aof_rewrite_buffer_length=0 used_memory_rss=278749184B redis_git_dirty=0 loading=0 redis_mode=standalone latest_fork_usec=5588 repl_backlog_first_byte_offset=0 sync_partial_ok=0 master_repl_offset=0 uptime_in_days=76c aof_rewrite_scheduled=0 lru_clock=3649276 rdb_bgsave_in_progress=0 rejected_connections=0 repl_backlog_active=0 aof_delayed_fsync=1 sync_full=0 process_id=7776 used_memory_human=194.14M aof_current_rewrite_time_sec=-1 used_memory=203570960 aof_enabled=1 blocked_clients=11 aof_last_bgrewrite_status=ok aof_rewrite_in_progress=0 sync_partial_err=0 used_cpu_sys_children=2222.75 connected_slaves=0 repl_backlog_histlen=0 uptime_in_seconds=6576292c repl_backlog_size=1048576 os=Linux 2.6.32-358.el6.x86_64 x86_64 used_cpu_sys=32640.80 aof_pending_bio_fsync=0 connected_clients=35 rdb_last_bgsave_time_sec=1 used_memory_peak_human=205.14M run_id=d1fc098d26fa4bbcef3eabeec6d19a858f03dd00 rdb_last_bgsave_status=ok pubsub_patterns=8 client_biggest_input_buf=0 keyspace_hits=42175896c rdb_last_save_time=1412935342 rdb_changes_since_last_save=318 db0_keys=28497 db0_expires=7 db0_avg_ttl=34003 aof_pending_rewrite=0 aof_buffer_length=0 config_file=/usr/local/redis-2.8.8/etc/redis.conf pubsub_channels=0 used_cpu_user_children=21375.34 hz=10 aof_last_rewrite_time_sec=2 aof_last_write_status=ok aof_base_size=82883253 used_cpu_user=18460.42 keyspace_misses=286602797c tcp_port=6379 total_commands_processed=797581196c mem_fragmentation_ratio=1.37 aof_current_size=146485850 rdb_current_bgsave_time_sec=-1 client_longest_output_list=0 instantaneous_ops_per_sec=114 evicted_keys=0c used_memory_peak=215106272B expired_keys=58977c total_keys=28497 total_expires=7 response_time=0.003802s hitrate=12.8281% memory_utilization=6.49013519287109%

[root@wgq plugins]#

8,查看redis监控服务状态

先重新加载nagios,使刚添加的redis监控配置生效

[root@wgq objects]# service nagios reload

Running configuration check...

Reloading nagios configuration...

done

[root@wgq objects]#

redis监控服务界面,如下图所示:

\


9,操作过程中的报错处理过程

报错:

[root@wgq_line_cache_3_41 plugins]# ./check_redis.pl --help

Can't locate Redis.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at ./check_redis.pl line 421.

BEGIN failed--compilation aborted at ./check_redis.pl line 421.

[root@wgq_line_cache_3_41 plugins]#

[root@wgq_line_cache_3_41 plugins]# perl -MCPAN -e shell

Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v1.9402)

Enter 'h' for help.

cpan[1]> install Redis

Can't locate Module/Build/Tiny.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Build.PL line 2.

BEGIN failed--compilation aborted at Build.PL line 2.

Warning: No success on command[/usr/bin/perl Build.PL --installdirs site]

Warning (usually harmless): 'YAML' not installed, will not store persistent state

DAMS/Redis-1.976.tar.gz

/usr/bin/perl Build.PL --installdirs site -- NOT OK

Running Build test

Make had some problems, won't test

Running Build install

Make had some problems, won't install

Could not read '/root/.cpan/build/Redis-1.976-Zhz6xI/META.yml'. Falling back to other methods to determine prerequisites……

YAML是以数据为中央的标记语言,其使用ASCII码(如连字符、问号、冒号、逗号等)构造数据块(标量值或哈希码)。和XML相同,YAML也是一种机器可识别语言,并能和多种脚本语言相结合,其中一种便是Perl,需要安装YAML,如下执行:

cpan[2]>install YAML

……

Appending installation info to /usr/lib64/perl5/perllocal.pod

INGY/YAML-1.12.tar.gz

/usr/bin/make install -- OK

CPAN: YAML loaded ok (v1.12)

PS:这里可能会安装失败,失败原因是网络连接,可以多执行几次install YAML就会成功。

再继续执行install Redis,有如下提示信息

cpan[4]> install Redis

Running install for module 'Redis'

Running Build for D/DA/DAMS/Redis-1.976.tar.gz

Has already been unwrapped into directory /root/.cpan/build/Redis-1.976-cUL4rt

'/usr/bin/perl Build.PL --installdirs site' returned status 512, won't make

Running Build test

Make had some problems, won't test

Running Build install

Make had some problems, won't install

cpan[5]>

Build失败,Build.PL故障了,需要重新安装下执行命令install Build

cpan[5]> install Build

成功后,再执行install Redis

cpan[6]> install Redis

Redis安装执行成功。

\

\

参考文档:http://exchange.nagios.org/directory/Plugins/Databases/check_redis-2Epl/details

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
如何在FastAPI中实现请求日志记录和监控如何在FastAPI中实现请求日志记录和监控Jul 30, 2023 am 08:29 AM

如何在FastAPI中实现请求日志记录和监控引言:FastAPI是一个基于Python3.7+的高性能Web框架,它提供了许多强大的功能和特性,包括自动化的请求和响应模型验证、安全性、性能优化等。在实际开发中,我们经常需要在应用程序中记录请求日志以便进行排错和监控分析。本文将介绍如何在FastAPI中实现请求日志记录和监控,并提供相应的代码示例。一、安装依

win10监控摄像头打开照片的方法win10监控摄像头打开照片的方法Jul 10, 2023 pm 09:41 PM

如果我们手头没有手机,只有电脑,但我们必须拍照,我们可以使用电脑内置的监控摄像头拍照,那么如何打开win10监控摄像头,事实上,我们只需要下载一个相机应用程序。打开win10监控摄像头的具体方法。win10监控摄像头打开照片的方法:1.首先,盘快捷键Win+i打开设置。2.打开后,进入个人隐私设置。3.然后在相机手机权限下打开访问限制。4.打开后,您只需打开相机应用软件。(如果没有,可以去微软店下载一个)5.打开后,如果计算机内置监控摄像头或组装了外部监控摄像头,则可以拍照。(因为人们没有安装摄

Linux下的实时日志监控与分析Linux下的实时日志监控与分析Jul 29, 2023 am 08:06 AM

Linux下的实时日志监控与分析在日常的系统管理和故障排查中,日志是一个非常重要的数据来源。通过对系统日志的实时监控和分析,我们可以及时发现异常情况并进行相应的处理。本文将介绍Linux下如何进行实时日志监控和分析,并提供相应的代码示例。一、实时日志监控在Linux下,最常用的日志系统是rsyslog。通过配置rsyslog,我们可以实现将不同应用程序的日志

如何使用Golang实现Web应用程序监控如何使用Golang实现Web应用程序监控Jun 24, 2023 am 09:00 AM

在当今的互联网时代,Web应用程序的高效稳定运行是非常重要的。然而,应用程序可能会出现故障或崩溃,影响用户体验。为了确保应用程序的正常运行,我们需要对其进行监控。本文将探讨如何使用Golang实现Web应用程序监控。一、Golang的Web应用程序监控工具Golang拥有非常适合Web应用程序监控的工具。其中最流行的就是Prometheus。Promethe

Nginx性能监控与安全分析辅助工具Nginx性能监控与安全分析辅助工具Jun 10, 2023 pm 02:41 PM

随着互联网的发展,web应用程序的性能监控以及安全分析越来越受到重视。nginx作为一款高性能的Web服务器和反向代理工具,其在性能监控和安全分析方面也受到广泛的关注和应用。本文将介绍一些Nginx性能监控和安全分析的辅助工具。Nginx性能监控工具NginxAmplifyNginxAmplify是Nginx公司推出的一款性能监控工具。该工具可以

Nginx监控实时状态配置,实时查看网站运行Nginx监控实时状态配置,实时查看网站运行Jul 04, 2023 pm 05:18 PM

Nginx监控实时状态配置,实时查看网站运行引言:Nginx是一款非常流行的反向代理服务器,其高性能和高并发能力使得它成为了许多网站的首选。为了保证网站的稳定运行,我们需要时刻监控Nginx的运行状态。本篇文章将介绍如何配置Nginx实时状态监控,并通过示例代码来让读者更好地理解。一、安装Nginx状态监控模块要实现Nginx的实时状态监控,需要在Nginx

基于go-zero实现微服务调用链监控基于go-zero实现微服务调用链监控Jun 23, 2023 am 09:53 AM

随着微服务架构的广泛应用,调用链监控已经成为了保障微服务健康运行的重要手段。而基于go-zero框架实现微服务调用链监控,则是更加高效可靠的实现方式。一、调用链监控的基本概念微服务架构中,一个请求可能经过多个微服务组件的调用,这些调用形成了一条调用链。而一旦某一个环节出现问题,整个服务甚至整个系统都有可能受到影响。因此,调用链监控这个技术,就是通过记录整条调

如何在Linux上设置高可用的网络存储监控如何在Linux上设置高可用的网络存储监控Jul 07, 2023 pm 12:07 PM

如何在Linux上设置高可用的网络存储监控在现代的IT环境中,网络存储是一个关键组件,用于存储和管理海量的数据。为了确保数据的可靠性和高可用性,对网络存储的监控和故障恢复是非常重要的。本文将介绍如何在Linux上设置高可用的网络存储监控,并提供代码示例。第一步:安装监控工具在Linux上,我们可以使用一个开源的监控工具来监控网络存储,比如Nagios。首先,

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),