首页 > 其他分享 >Zabbix监控memcached

Zabbix监控memcached

时间:2022-12-05 19:00:18浏览次数:49  
标签:STAT 0.0 zabbix Zabbix 监控 root memcached LISTEN

  Zabbix对memcached的监控的主要思路是可以memcached自带的的查询状态命令stats,在通过脚本来使用此命令进行数据的展示并结合相关命令将数值取出来完成zabbix对memcached的实时监控。

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.deb
root@Linux:~# dpkg -i zabbix-release_5.0-1+focal_all.deb
root@Linux:~# apt update
root@Linux:~# apt -y install zabbix-agent memcached nmap ncat
root@Linux:~# vi /etc/memcached.conf
root@Linux:~# grep -Ev "#|^$" /etc/memcached.conf
-d
logfile /var/log/memcached.log
-m 512
-p 11211
-u memcache
-l 0.0.0.0
-P /var/run/memcached/memcached.pid
root@Linux:~# systemctl restart memcached.service
root@Linux:~# systemctl enable memcached
root@Linux:~# lsof -i:11211
COMMAND    PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
memcached 5380 memcache   26u  IPv4  55532      0t0  TCP *:11211 (LISTEN)

2、监控脚本

#首先先用stats查看一下memcached的运行状态
root@Linux:~# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stats
STAT pid 5380
STAT uptime 154
STAT time 1670232197
STAT version 1.5.22
STAT libevent 2.1.11-stable
STAT pointer_size 64
STAT rusage_user 0.000000
STAT rusage_system 0.037778
STAT max_connections 1024
STAT curr_connections 1
STAT total_connections 2
STAT rejected_connections 1
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 cmd_meta 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 7
STAT bytes_written 0
STAT limit_maxbytes 536870912
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 510
STAT lru_maintainer_juggles 204
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
END

#测试使用命令行取出需要的数据
root@Linux:~# echo -e "stats\nquit" | ncat 10.0.0.102 11211 | grep "STAT connection_structures"
STAT connection_structures 2
root@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/bash
memcache_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.sh
root@Linux:~# bash memcache_monitor.sh memcached_status 11211 curr_connections
1
root@Linux:~# bash memcache_monitor.sh memcached_status 11211 threads
4

3、添加zabbix agent的自定义监控项

root@Linux:~# vi /etc/zabbix/zabbix_agentd.conf
root@Linux:~# grep -Ev "#|^$" /etc/zabbix/zabbix_agentd.conf
PidFile=/tmp/zabbix_agentd.pid
LogFile=/tmp/zabbix_agentd.log
LogFileSize=0
Server=10.0.0.100,10.0.0.104
ListenPort=10050
ListenIP=0.0.0.0
StartAgents=3
ServerActive=10.0.0.104
Hostname=10.0.0.102
Timeout=30
AllowRoot=1
User=root
Include=/etc/zabbix/zabbix_agentd.d/*.conf
UserParameter=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-agent
root@Linux:~# ss -tnl
State                   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"]"
1
root@zabbix-server:~# zabbix_get -s 10.0.0.102 -p 10050 -k "memcache_status["memcached_status","11211","threads"]"
4

5、zabbix web界面制作memcached模板

5.1、创建模板

image.png image.png

5.2、创建监控项

image.png image.png image.png image.png image.png

5.3、创建触发器

image.png image.png image.png image.png

5.4、创建图形

image.png image.png image.png image.png

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

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

标签:STAT,0.0,zabbix,Zabbix,监控,root,memcached,LISTEN
From: https://blog.51cto.com/u_15105742/5913251

相关文章

  • Zabbix阿里云短信告警
    环境准备(不一定要这样子的环境,可根据具体的生产环境配置)应用版本CentOS7.4Zabbix6.0.4Pythonv2阿里云短信服务SDK2.0.22准备阿里云短信签名和......
  • JVM---性能监控与调优(JVM监控及诊断工具GUI)
    JVM监控及诊断工具-GUI概述 ......
  • 前端视频监控和回放方案
    采用方案:1、采用了萤石云(属于海康威视旗下的云服务)视频方案。2、支持第三方、海康部分及萤石云摄像头接入。3、萤石云接入登录入口:登录-用户认证中心(ys7.com)。 绑......
  • Linux系统zabbix_agentd客户端安装与配置
    官网下载zabbix安装包(zabbix安装包里包含了zabbix_agentd客户端安装包,我们只选择zabbix_agentd客户端安装) zbbix官网下载地址:  http://www.zabbix.com/download ......
  • zabbix监控进程和监控日志
    zabbix监控进程和监控日志文章目录​​zabbix监控进程和监控日志​​​​一、自定义监控进程​​​​1、新建脚本存放目录​​​​2、修改zabbix_agentd.conf文件​​​​3......
  • 监控库中存储和函数变更记录存储
    监控库中存储和函数变更记录存储1、建表createtableetl_logselectnow()etl_time,routine_typeobject_type,specific_nameobject_na......
  • zabbix-server性能优化
    zabbix性能低下的表现1.    zabbix队列有太多被延迟的item,可以通过administration-queue查看2.    zabbix绘图中经常出现断图,一些item没有数据3.    带有noda......
  • 常用命令_主机状态监控
    top =p#只显示某个进程的信息 -d#设置刷新时间 -c#显示产生进程的完整命令 -n#指定刷新次数 -b#以非交互全屏模式运行,top-b-n3>/tmp/test.log -i#......
  • 【2022-12-04】Prometheus+Grafana监控平台部署文档
    一、环境准备1.准备两台虚拟机\或者购买云服务器2.虚拟机硬件要求2.1内存不得少于4G,否则项目启动会有报错2.2CPU2核2G2.3硬盘至少20G3.系统镜像 ......
  • 网络性能监控工具整理
    提纲netperfiperfpathcharntttcpitracertnetperfnetperf是一款针对网络性能的测试工具,主要基于TCP或UDP的传输。根据应用的不同,可以进行批量数据传输(bulkdatat......