Zabbix监控memcached

??Zabbix对memcached的监控的主要思路是可以memcached自带的的查询状态命令stats,在通过脚本来使用此命令进行数据的展示并结合相关命令将数值取出来完成zabbix对memcached的实时监控。这里的memcached服务我就安装Linux主机上了,监控的话也就在zabbix web界面上添加自定义的模板就好了。

1、准备memcached服务

??安装memcached,并配置好memcached,同时也需要安装zabbix agent、nmap基本工具包。

root@Linux:~# wget https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1%2Bfocal_all.debroot@Linux:~# dpkg -i zabbix-release_5.0-1+focal_all.debroot@Linux:~# apt updateroot@Linux:~# apt -y install zabbix-agent memcached nmap ncatroot@Linux:~# vi /etc/memcached.confroot@Linux:~# grep -Ev "#|^$" /etc/memcached.conf-dlogfile /var/log/memcached.log-m 512-p 11211-u memcache-l 0.0.0.0-P /var/run/memcached/memcached.pidroot@Linux:~# systemctl restart memcached.serviceroot@Linux:~# systemctl enable memcachedroot@Linux:~# lsof -i:11211COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEmemcached 5380 memcache 26u IPv4 55532 0t0 TCP *:11211 (LISTEN)2、监控脚本#首先先用stats查看一下memcached的运行状态root@Linux:~# telnet 127.0.0.1 11211Trying 127.0.0.1…Connected to 127.0.0.1.Escape character is ‘^]’.statsSTAT pid 5380STAT uptime 154STAT time 1670232197STAT version 1.5.22STAT libevent 2.1.11-stableSTAT pointer_size 64STAT rusage_user 0.000000STAT rusage_system 0.037778STAT max_connections 1024STAT curr_connections 1STAT total_connections 2STAT rejected_connections 1STAT connection_structures 2STAT reserved_fds 20STAT cmd_get 0STAT cmd_set 0STAT cmd_flush 0STAT cmd_touch 0STAT cmd_meta 0STAT get_hits 0STAT get_misses 0STAT get_expired 0STAT get_flushed 0STAT delete_misses 0STAT delete_hits 0STAT incr_misses 0STAT incr_hits 0STAT decr_misses 0STAT decr_hits 0STAT cas_misses 0STAT cas_hits 0STAT cas_badval 0STAT touch_hits 0STAT touch_misses 0STAT auth_cmds 0STAT auth_errors 0STAT bytes_read 7STAT bytes_written 0STAT limit_maxbytes 536870912STAT accepting_conns 1STAT listen_disabled_num 0STAT time_in_listen_disabled_us 0STAT threads 4STAT conn_yields 0STAT hash_power_level 16STAT hash_bytes 524288STAT hash_is_expanding 0STAT slab_reassign_rescues 0STAT slab_reassign_chunk_rescues 0STAT slab_reassign_evictions_nomem 0STAT slab_reassign_inline_reclaim 0STAT slab_reassign_busy_items 0STAT slab_reassign_busy_deletes 0STAT slab_reassign_running 0STAT slabs_moved 0STAT lru_crawler_running 0STAT lru_crawler_starts 510STAT lru_maintainer_juggles 204STAT malloc_fails 0STAT log_worker_dropped 0STAT log_worker_written 0STAT log_watcher_skipped 0STAT log_watcher_sent 0STAT bytes 0STAT curr_items 0STAT total_items 0STAT slab_global_page_pool 0STAT expired_unfetched 0STAT evicted_unfetched 0STAT evicted_active 0STAT evictions 0STAT reclaimed 0STAT crawler_reclaimed 0STAT crawler_items_checked 0STAT lrutail_reflocked 0STAT moves_to_cold 0STAT moves_to_warm 0STAT moves_within_lru 0STAT direct_reclaims 0STAT lru_bumps_dropped 0END#测试使用命令行取出需要的数据root@Linux:~# echo -e "stats\nquit" | ncat 10.0.0.102 11211 | grep "STAT connection_structures"STAT connection_structures 2root@Linux:~# echo -e "stats\nquit" | ncat 10.0.0.102 11211 | grep "STAT connection_structures" | awk ‘{print $3}’2#按照上面的逻辑可以来完成脚本的编辑root@Linux:~# vi memcache_monitor.sh#!/bin/bashmemcache_status(){ M_PORT=$1 M_COMMAND=$2 echo -e "stats\nquit" | ncat 127.0.0.1 "$M_PORT" | grep "STAT $M_COMMAND" | awk ‘{print $3}’}main(){ case $1 in memcached_status) memcache_status $2 $3 ;; esac}main $1 $2 $3#授权并测试脚本可用性root@Linux:~# chmod a+x memcache_monitor.shroot@Linux:~# bash memcache_monitor.sh memcached_status 11211 curr_connections1root@Linux:~# bash memcache_monitor.sh memcached_status 11211 threads43、添加zabbix agent的自定义监控项root@Linux:~# vi /etc/zabbix/zabbix_agentd.confroot@Linux:~# grep -Ev "#|^$" /etc/zabbix/zabbix_agentd.confPidFile=/tmp/zabbix_agentd.pidLogFile=/tmp/zabbix_agentd.logLogFileSize=0Server=10.0.0.100,10.0.0.104ListenPort=10050ListenIP=0.0.0.0StartAgents=3ServerActive=10.0.0.104Hostname=10.0.0.102Timeout=30AllowRoot=1User=rootInclude=/etc/zabbix/zabbix_agentd.d/*.confUserParameter=linux_status[*],/etc/zabbix/zabbix_agentd.d/tcp_conn_plugin.sh "$1" "$2"UserParameter=memcache_status[*],/etc/zabbix/zabbix_agentd.d/memcache_monitor.sh "$1" "$2" "$3"root@Linux:~# mv memcache_monitor.sh /etc/zabbix/zabbix_agentd.d/root@Linux:~# systemctl restart zabbix-agentroot@Linux:~# ss -tnlState Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 1024 0.0.0.0:11211 0.0.0.0:* LISTEN 0 4096 0.0.0.0:111 0.0.0.0:* LISTEN 0 511 0.0.0.0:80 0.0.0.0:* LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 127.0.0.1:6010 0.0.0.0:* LISTEN 0 4096 0.0.0.0:64958 0.0.0.0:* LISTEN 0 4096 0.0.0.0:46302 0.0.0.0:* LISTEN 0 64 0.0.0.0:2049 0.0.0.0:* LISTEN 0 4096 0.0.0.0:10050 0.0.0.0:* LISTEN 0 64 0.0.0.0:35654 0.0.0.0:* LISTEN 0 4096 0.0.0.0:54694 0.0.0.0:* LISTEN 0 4096 [::]:22476 [::]:* LISTEN 0 4096 [::]:111 [::]:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 4096 [::]:59638 [::]:* LISTEN 0 64 [::]:33208 [::]:* LISTEN 0 128 [::1]:6010 [::]:* LISTEN 0 4096 [::]:46462 [::]:* LISTEN 0 64 [::]:2049 [::]:*4、在zabbix server上用zabbix_get工具测试监控项数据root@zabbix-server:~# zabbix_get -s 10.0.0.102 -p 10050 -k "memcache_status["memcached_status","11211","curr_connections"]"1root@zabbix-server:~# zabbix_get -s 10.0.0.102 -p 10050 -k "memcache_status["memcached_status","11211","threads"]"45、zabbix web界面制作memcached模板5.1、创建模板

5.2、创建监控项

5.3、创建触发器

5.4、创建图形

6、关联模板、验证监控数据

这个主机是我前面加好了,这里我就不重复添加了

【文章转自高防服务器 复制请保留原URL】生活若剥去了理想梦想幻想,那生命便只是一堆空架子

Zabbix监控memcached

相关文章:

你感兴趣的文章:

标签云: