
正文
zabbix监控memcached服务
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
zabbix监控memcached服务
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.安装并配置memcached服务
1>.使用yum方式安装memcached
[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 ::
docker-ce-stable | 3.5 kB ::
extras | 2.9 kB ::
kubernetes | 1.4 kB ::
updates | 2.9 kB ::
zabbix | 2.9 kB ::
zabbix-non-supported | B ::
Resolving Dependencies
--> Running transaction check
---> Package memcached.x86_64 :1.4.-.el7_3. will be installed
--> Finished Dependency Resolution Dependencies Resolved ==============================================================================================================================================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================================================================================================================================
Installing:
memcached x86_64 1.4.-.el7_3. base k Transaction Summary
==============================================================================================================================================================================================================================================================================
Install Package Total download size: k
Installed size: k
Downloading packages:
memcached-1.4.-.el7_3..x86_64.rpm | kB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : memcached-1.4.-.el7_3..x86_64 /
Verifying : memcached-1.4.-.el7_3..x86_64 / Installed:
memcached.x86_64 :1.4.-.el7_3. 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=""
USER="memcached"
MAXCONN=""
CACHESIZE=""
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
LISTEN *: *:*
LISTEN ::: :::*
[root@node201.yinzhengjie.org.cn ~]#
[root@node201.yinzhengjie.org.cn ~]#
二. zabbix agent端配置监控memcached的脚本
1>. 在命令行中查看数据 memcached 的监控指标
[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 :6.40-.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ==============================================================================================================================================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================================================================================================================================
Installing:
nmap-ncat x86_64 :6.40-.el7 base k Transaction Summary
==============================================================================================================================================================================================================================================================================
Install Package Total download size: k
Installed size: k
Downloading packages:
nmap-ncat-6.40-.el7.x86_64.rpm | kB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : :nmap-ncat-6.40-.el7.x86_64 /
Verifying : :nmap-ncat-6.40-.el7.x86_64 / Installed:
nmap-ncat.x86_64 :6.40-.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\nquit" | nc 127.0.0.1 ""
STAT pid
STAT uptime
STAT time
STAT version 1.4.
STAT libevent 2.0.-stable
STAT pointer_size
STAT rusage_user 0.014680
STAT rusage_system 0.014680
STAT curr_connections
STAT total_connections
STAT connection_structures
STAT reserved_fds
STAT cmd_get
STAT cmd_set
STAT cmd_flush
STAT cmd_touch
STAT get_hits
STAT get_misses
STAT delete_misses
STAT delete_hits
STAT incr_misses
STAT incr_hits
STAT decr_misses
STAT decr_hits
STAT cas_misses
STAT cas_hits
STAT cas_badval
STAT touch_hits
STAT touch_misses
STAT auth_cmds
STAT auth_errors
STAT bytes_read
STAT bytes_written
STAT limit_maxbytes
STAT accepting_conns
STAT listen_disabled_num
STAT threads
STAT conn_yields
STAT hash_power_level
STAT hash_bytes
STAT hash_is_expanding
STAT bytes
STAT curr_items
STAT total_items
STAT expired_unfetched
STAT evicted_unfetched
STAT evictions
STAT reclaimed
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:
#Date: --
#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=$
M_COMMAND=$
echo -e "stats\nquit" | nc 127.0.0.1 "$M_PORT" | grep "STAT $M_COMMAND " | awk '{print $3}'
} function main(){
case $ in
memcached_status)
memcached_status $ $
;;
esac
} main $ $ $
[root@node201.yinzhengjie.org.cn ~]#
[root@node201.yinzhengjie.org.cn ~]# bash /etc/zabbix/zabbix_agentd.d/memcached_monitoring.sh memcached_status curr_connections [root@node201.yinzhengjie.org.cn ~]#
[root@node201.yinzhengjie.org.cn ~]# bash /etc/zabbix/zabbix_agentd.d/memcached_monitoring.sh memcached_status reserved_fds [root@node201.yinzhengjie.org.cn ~]#
3>.给自定义的脚本添加可执行权限
[root@node201.yinzhengjie.org.cn ~]# ll /etc/zabbix/zabbix_agentd.d/memcached_monitoring.sh
-rw-r--r-- root root Feb : /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 root root Feb : /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 WebUI配置
1>. 在zabbix server测试是否可以获取memcached的监控数据
[root@zabbix203.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/zabbix/bin/zabbix_get -s node201.yinzhengjie.org.cn -p -k "memcached_monitoring[memcached_status 11211 curr_connections]" [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 -k "memcached_monitoring[memcached_status 11211 reserved_fds]" [root@zabbix203.yinzhengjie.org.cn ~]#
2>.自定义memcached的模板
3>.自定义memecached模板监控项图形
4>.自定义触发器
5>.将自定义的memcached模板和对应的zabbix agent主机进行关联
6>.查看图形





