Zabbix--Zabbix-Memcached状态监控
Posted IT科技 不拘一格
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Zabbix--Zabbix-Memcached状态监控相关的知识,希望对你有一定的参考价值。
续:
推荐阅读:
安装 memcache 服务
通过自定义监控模板对memcache进行监控
为了测试效果,在主动模式下,因为主动模式获取数据比较快一些
环境:在这里复用mysql-slave的主机
安装 memcache
在zabbix的agent主机中172.20.32.105:Mysql-slave部署安装memcache
root@Mysql-slave:~# yum install -y memcached nmap -y
root@Mysql-slave:~# vim /etc/memcached.conf
root@Mysql-slave:~# grep ^[a-Z-] /etc/memcached.conf
-d
logfile /var/log/memcached.log
-m 64
-p 11211
-u memcache
-l 0.0.0.0
-P /var/run/memcached/memcached.pid
root@Mysql-slave:~# systemctl restart memcached.service
root@Mysql-slave:~# systemctl enable memcached.service
Synchronizing state of memcached.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable memcached
root@Mysql-slave:~# ss -ntl|grep 11211
LISTEN 0 1024 0.0.0.0:11211 0.0.0.0:*
root@Mysql-slave:~# lsof -i:11211
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
memcached 34697 memcache 26u IPv4 117844 0t0 TCP *:11211 (LISTEN)
编写监控脚本
写脚本提示
root@Mysql-slave:~# echo -e "stats
quit"|ncat 127.0.0.1 11211 |grep "STAT"
STAT pid 34697
STAT uptime 2109
STAT time 1588320402
STAT version 1.5.6 Ubuntu
STAT libevent 2.1.8-stable
STAT pointer_size 64
STAT rusage_user 0.027811
STAT rusage_system 0.278119
STAT max_connections 1024
STAT curr_connections 1
STAT total_connections 5
STAT rejected_connections 0
STAT connection_structures 2
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 get_expired 0
STAT get_flushed 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 72
STAT bytes_written 5727
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT time_in_listen_disabled_us 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT slab_reassign_rescues 0
STAT slab_reassign_chunk_rescues 0
STAT slab_reassign_evictions_nomem 0
STAT slab_reassign_inline_reclaim 0
STAT slab_reassign_busy_items 0
STAT slab_reassign_busy_deletes 0
STAT slab_reassign_running 0
STAT slabs_moved 0
STAT lru_crawler_running 0
STAT lru_crawler_starts 2040
STAT lru_maintainer_juggles 2157
STAT malloc_fails 0
STAT log_worker_dropped 0
STAT log_worker_written 0
STAT log_watcher_skipped 0
STAT log_watcher_sent 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT slab_global_page_pool 0
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT evicted_active 0
STAT evictions 0
STAT reclaimed 0
STAT crawler_reclaimed 0
STAT crawler_items_checked 0
STAT lrutail_reflocked 0
STAT moves_to_cold 0
STAT moves_to_warm 0
STAT moves_within_lru 0
STAT direct_reclaims 0
STAT lru_bumps_dropped 0
root@Mysql-slave:~# echo -e "stats
quit"|ncat 127.0.0.1 11211 |grep -w "STAT max_connections"|awk '{print $3}'
1024
root@Mysql-slave:~# echo -e "stats
quit"|ncat 127.0.0.1 11211 |grep -w "STAT bytes"|awk '{print $3}'
0
脚本编写
在机器172.20.32.105上面编写脚本
一般脚本放在/etc/zabbix/zabbix_agentd.d/这个文件目录下
root@Mysql-slave:/etc/zabbix/zabbix_agentd.d# vim memcache_monitor.sh
#!/bin/bash
#
# Edited on 20200501 by likai.tech
#
memcached_status(){
M_PORT=$1
M_COMMAND=$2
echo -e "stats
quit" | ncat 127.0.0.1 "$M_PORT" | grep -w "STAT $M_COMMAND" | awk '{print $3}'
#ubuntu使用ncat, 安装nmap
}
main(){
case $1 in
memcached_status)
memcached_status $2 $3
;;
esac
}
main $1 $2 $3
root@Mysql-slave:/etc/zabbix/zabbix_agentd.d# chmod a+x memcache_monitor.sh
测试:
root@Mysql-slave:/etc/zabbix/zabbix_agentd.d# bash memcache_monitor.sh memcached_status 11211 max_connections
1024
root@Mysql-slave:/etc/zabbix/zabbix_agentd.d# bash memcache_monitor.sh memcached_status 11211 curr_connections
1
添加和测试自定义监控项
在 agent 的配置文件中添加
root@Mysql-slave:/etc/zabbix/zabbix_agentd.d# vim /etc/zabbix/zabbix_agentd.conf
### Option: UserParameter
# User-defined parameter to monitor. There can be several user-defined parameters.
# Format: UserParameter=<key>,<shell command>
# See 'zabbix_agentd' directory for examples.
#
# Mandatory: no
# Default:
# UserParameter=
UserParameter=memcached_status[*],bin/bash /etc/zabbix/zabbix_agentd.d/memcache_monitor.sh "$1" "$2" "$3"
#key的名称为memcached_status [*]表示可接受多个变量 逗号后面是运行脚本的绝对路径 最后面是三个参数
root@Mysql-slave:/etc/zabbix/zabbix_agentd.d# systemctl restart zabbix-agent.service
测试自定义监控项
在172.20.32.101 zabbix server主机上面进行测试:
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.105 -p10050 -k "memcached_status["memcached_status","11211","max_connections"]"
1024
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.105 -p10050 -k "memcached_status["memcached_status","11211","curr_connections"]"
1
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.105 -p10050 -k "memcached_status["memcached_status","11211","bytes"]"
0
创建模板
在 web 添加自定义监控项
可以看到下图这一个空模板现在什么监控项都还是空的,其他的触发器 图形都是还需要自己创建的
创建应用集
创建应用集。点击应用集,创建应用集
可以看到上图中的应用集后面有数字,数字表示对应的个数
创建监控项
创建监控项。点击上图中的监控项-创建监控项。
键值:memcached_status["memcached_status","11211","curr_connections"]
同理再一次创建一个新的监控项:
键值:memcached_status["memcached_status","11211","threads"]
创建图形
创建图形。点击上图中的图形-创建图形。
关联主机
关联已经创建的主机
模板可以在多个主机进行关联和复用
检测数据图形
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.105 -p10050 -k "memcached_status["memcached_status","11211","curr_connections"]"
1
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.105 -p10050 -k "memcached_status["memcached_status","11211","threads"]"
4
创建触发器
触发器的创建要基于之前的监控项的创建,所以在创建触发器之前必须创建监控项
在检测图形中可以查看到触发器:
推荐阅读:
以上是关于Zabbix--Zabbix-Memcached状态监控的主要内容,如果未能解决你的问题,请参考以下文章