zabbix监控memcached服务

摘要:
否则,将追究法律责任。

             zabbix监控memcached服务

                                     作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.安装并配置memcached服务

1>.使用yum方式安装memcached

zabbix监控memcached服务第1张zabbix监控memcached服务第2张
[root@node201.yinzhengjie.org.cn ~]# yum -y install memcached
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.tuna.tsinghua.edu.cn
base                                                                                                                                                                                                                                                   | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                                                                                                                                                       | 3.5 kB  00:00:00     
extras                                                                                                                                                                                                                                                 | 2.9 kB  00:00:00     
kubernetes                                                                                                                                                                                                                                             | 1.4 kB  00:00:00     
updates                                                                                                                                                                                                                                                | 2.9 kB  00:00:00     
zabbix                                                                                                                                                                                                                                                 | 2.9 kB  00:00:00     
zabbix-non-supported                                                                                                                                                                                                                                   |  951 B  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package memcached.x86_64 0:1.4.15-10.el7_3.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================================================================================================
 Package                                                          Arch                                                          Version                                                                     Repository                                                   Size
==============================================================================================================================================================================================================================================================================
Installing:
 memcached                                                        x86_64                                                        1.4.15-10.el7_3.1                                                           base                                                         85 k

Transaction Summary
==============================================================================================================================================================================================================================================================================
Install  1 Package

Total download size: 85 k
Installed size: 176 k
Downloading packages:
memcached-1.4.15-10.el7_3.1.x86_64.rpm                                                                                                                                                                                                                 |  85 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : memcached-1.4.15-10.el7_3.1.x86_64                                                                                                                                                                                                                         1/1 
  Verifying  : memcached-1.4.15-10.el7_3.1.x86_64                                                                                                                                                                                                                         1/1 

Installed:
  memcached.x86_64 0:1.4.15-10.el7_3.1                                                                                                                                                                                                                                        

Complete!
[root@node201.yinzhengjie.org.cn ~]# 
[root@node201.yinzhengjie.org.cn ~]# yum -y install memcached

2>.查看memcached的配置文件

[root@node201.yinzhengjie.org.cn ~]# cat /etc/sysconfig/memcached 
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""
[root@node201.yinzhengjie.org.cn ~]# 

3>.启动memcached服务

[root@node201.yinzhengjie.org.cn ~]# systemctl start memcached.service 
[root@node201.yinzhengjie.org.cn ~]# 
[root@node201.yinzhengjie.org.cn ~]# systemctl enable memcached.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/memcached.service to /usr/lib/systemd/system/memcached.service.
[root@node201.yinzhengjie.org.cn ~]# 
[root@node201.yinzhengjie.org.cn ~]# ss -ntl | grep 11211
LISTEN     0      1024         *:11211                    *:*                  
LISTEN     0      1024        :::11211                   :::*                  
[root@node201.yinzhengjie.org.cn ~]# 
[root@node201.yinzhengjie.org.cn ~]# 

二.zabbix agent端配置监控memcached的脚本

1>.在命令行中查看数据memcached的监控指标

zabbix监控memcached服务第3张zabbix监控memcached服务第4张
[root@node201.yinzhengjie.org.cn ~]# yum -y install nc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package nmap-ncat.x86_64 2:6.40-19.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================================================================================================
 Package                                                           Arch                                                           Version                                                                  Repository                                                    Size
==============================================================================================================================================================================================================================================================================
Installing:
 nmap-ncat                                                         x86_64                                                         2:6.40-19.el7                                                            base                                                         206 k

Transaction Summary
==============================================================================================================================================================================================================================================================================
Install  1 Package

Total download size: 206 k
Installed size: 423 k
Downloading packages:
nmap-ncat-6.40-19.el7.x86_64.rpm                                                                                                                                                                                                                       | 206 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2:nmap-ncat-6.40-19.el7.x86_64                                                                                                                                                                                                                             1/1 
  Verifying  : 2:nmap-ncat-6.40-19.el7.x86_64                                                                                                                                                                                                                             1/1 

Installed:
  nmap-ncat.x86_64 2:6.40-19.el7                                                                                                                                                                                                                                              

Complete!
[root@node201.yinzhengjie.org.cn ~]# 
[root@node201.yinzhengjie.org.cn ~]# yum -y install nc        #安装nc工具
[root@node201.yinzhengjie.org.cn ~]# echo -e "stats
quit" | nc 127.0.0.1 "11211" 
STAT pid 88756
STAT uptime 261
STAT time 1582849154
STAT version 1.4.15
STAT libevent 2.0.21-stable
STAT pointer_size 64
STAT rusage_user 0.014680
STAT rusage_system 0.014680
STAT curr_connections 10
STAT total_connections 11
STAT connection_structures 11
STAT reserved_fds 20
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 11
STAT bytes_written 0
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT evictions 0
STAT reclaimed 0
END
[root@node201.yinzhengjie.org.cn ~]# 

2>.编写脚本获取memcached的监控项数据

[root@node201.yinzhengjie.org.cn ~]# cat /etc/zabbix/zabbix_agentd.d/memcached_monitoring.sh 
#!/bin/bash
#
#********************************************************************
#Author:        yinzhengjie
#QQ:             1053419035
#Date:             2019-11-23
#FileName:        shell/menu.sh
#URL:             http://www.cnblogs.com/yinzhengjie
#Description:        The test script
#Copyright notice:     original works, no reprint! Otherwise, legal liability will be investigated.
#********************************************************************

function memcached_status(){
    M_PORT=$1
    M_COMMAND=$2
    echo -e "stats
quit" | nc 127.0.0.1 "$M_PORT" | grep "STAT $M_COMMAND " | awk '{print $3}'
}

function main(){
    case $1 in
        memcached_status)
            memcached_status $2 $3
            ;;
    esac
}

main $1 $2 $3
[root@node201.yinzhengjie.org.cn ~]# 
[root@node201.yinzhengjie.org.cn ~]# bash /etc/zabbix/zabbix_agentd.d/memcached_monitoring.sh memcached_status 11211 curr_connections
10
[root@node201.yinzhengjie.org.cn ~]# 
[root@node201.yinzhengjie.org.cn ~]# bash /etc/zabbix/zabbix_agentd.d/memcached_monitoring.sh memcached_status 11211 reserved_fds
20
[root@node201.yinzhengjie.org.cn ~]# 

 zabbix监控memcached服务第5张

3>.给自定义的脚本添加可执行权限

[root@node201.yinzhengjie.org.cn ~]# ll /etc/zabbix/zabbix_agentd.d/memcached_monitoring.sh 
-rw-r--r-- 1 root root 760 Feb 28 08:25 /etc/zabbix/zabbix_agentd.d/memcached_monitoring.sh
[root@node201.yinzhengjie.org.cn ~]# 
[root@node201.yinzhengjie.org.cn ~]# chmod +x /etc/zabbix/zabbix_agentd.d/memcached_monitoring.sh 
[root@node201.yinzhengjie.org.cn ~]# 
[root@node201.yinzhengjie.org.cn ~]# ll /etc/zabbix/zabbix_agentd.d/memcached_monitoring.sh 
-rwxr-xr-x 1 root root 760 Feb 28 08:25 /etc/zabbix/zabbix_agentd.d/memcached_monitoring.sh
[root@node201.yinzhengjie.org.cn ~]# 
[root@node201.yinzhengjie.org.cn ~]# 

4>.修改zaibbix agent的配置文件

[root@node201.yinzhengjie.org.cn ~]# grep ^Include /etc/zabbix/zabbix_agentd.conf 
Include=/etc/zabbix/zabbix_agentd.d/*.conf
[root@node201.yinzhengjie.org.cn ~]# 
[root@node201.yinzhengjie.org.cn ~]# cat /etc/zabbix/zabbix_agentd.d/yinzhengjie_monitoring.conf 
UserParameter=tcp_status_monitoring[*],/etc/zabbix/zabbix_agentd.d/tcp_status_monitoring.sh $1 $2
UserParameter=memcached_monitoring[*],/etc/zabbix/zabbix_agentd.d/memcached_monitoring.sh $1 $2 $3
[root@node201.yinzhengjie.org.cn ~]# 

5>.重启zabbix agent服务使得配置生效

[root@node201.yinzhengjie.org.cn ~]# systemctl restart zabbix-agent.service 

zabbix监控memcached服务第6张

三.zabbix WebUI配置

1>.在zabbix server测试是否可以获取memcached的监控数据

[root@zabbix203.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/zabbix/bin/zabbix_get -s node201.yinzhengjie.org.cn -p 10050 -k "memcached_monitoring[memcached_status 11211 curr_connections]"
10
[root@zabbix203.yinzhengjie.org.cn ~]# 
[root@zabbix203.yinzhengjie.org.cn ~]# 
[root@zabbix203.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/zabbix/bin/zabbix_get -s node201.yinzhengjie.org.cn -p 10050 -k "memcached_monitoring[memcached_status 11211 reserved_fds]"
20
[root@zabbix203.yinzhengjie.org.cn ~]# 

2>.自定义memcached的模板

zabbix监控memcached服务第7张

3>.自定义memecached模板监控项图形

zabbix监控memcached服务第8张

4>.自定义触发器

zabbix监控memcached服务第9张

5>.将自定义的memcached模板和对应的zabbix agent主机进行关联

zabbix监控memcached服务第10张

6>.查看图形

zabbix监控memcached服务第11张

免责声明:文章转载自《zabbix监控memcached服务》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇matlab初探寻MapReduce应用案例--单表关联下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

zabbix企业应用之bind dns监控(转)

继续介绍zabbix监控企业应用的实例,本次介绍zabbix监控dns,我监控的dns为bind 9.8.2,本dns为公网dns,是为了解决公司内网服务器自动化所需求的dns解析,比如目前的puppet或者salt软件,如果结合dns,管理起来更方便,对于管理服务器来说,如果搬迁机房或者硬件出现故障,如果有dns解析,那么直接切换域名,30s内生效,这样...

Ubuntu下qemu环境搭建vexpress开发平台

在查找资料过程中,发现自己搭建虚拟的arm环境的话,有一个比较好的软件就是qemu了,当然还有其他的,大家各投所好就好。 接下来说一下qemu环境搭建过程。 其实搭建很简单,作为小白,我还是捣鼓了两三天才真正的安装成功,正在尝试着怎么使用。 上篇已经讲了安装Ubuntu系统后root密码的设置,这里就要用到root密码进行软件安装了。 可以在命令行模式下先...

Zabbix 主动和被动模式配置(主动模式无法获取数据解决)

一、zabbix主动模式无法获取数据原因及解决方案(zabbix5.2) 1、检查server端与agent端时间是否一致 2、检查agent机器 /etc/zabbix/zabbix-agent.conf 里面配置的hostname,是否与该机的hostname一致 (可在/etc/hosts 配置主机名与ip对应关系,保证主机名能ping通) 查看本机...

关于linux免密登录的配置及ssh客户端基于私钥文件的登录

操作系统环境: CentOS Linux release 7.7.1908 (Core) 1、首先在linux服务器上,使用ssh-keygen命令生成密钥对文件(一直回车即可,默认使用rsa算法),如下所示       其中还支持的算法有dsa | ecdsa | ed25519 | rsa | rsa1,使用其他算法只需要使用-t选项指定即可    ...

Centos下堡垒机Jumpserver V3.0环境部署完整记录(2)-配置篇

前面已经介绍了Jumpserver V3.0的安装,基于这篇安装文档,下面说下Jumpserver安装后的的功能使用: 一、jumpserver的启动 Jumpserver的启动和重启 [root@test-vm001 install]# /opt/jumpserver/service.sh start/restart 二、按照Jumpserver部署过...

ADB命令详解及大全( 声明:此文是参考大佬博客所做的笔记!)

   adb是什么?       adb的全称为Android Debug Bridge,就是起到调试桥的作用。通过adb我们可以在Eclipse中方面通过DDMS来调试Android程序,说白了就是debug工具。adb的工作方式比较特殊,采用监听Socket TCP 5554等端口的方式让IDE和Qemu通讯,默认情况下adb会daemon相关的网络端...