监控memcache

memcache监控脚本

[root@zabbix-web02 zabbix_agentd.d]# cat memcache_monitor.sh
#!/bin/bash
#
#********************************************************************
#Author:                xuanlv
#QQ:                    360956175
#Date:                  2021-07-31
#FileName:             memcache_monitor.sh
#URL:                   https://www.cnblogs.com/xuanlv-0413/
#Description:          The test script
#Copyright (C):         2021 All rights reserved
#********************************************************************
memcached_status(){
    ME_PORT=$1
    ME_COMMAND=$2
    echo -e "stats
quit" | ncat 127.0.0.1 "$ME_PORT" | grep "STAT $ME_COMMAND" | awk '{print $3}'
}

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

授权

[root@zabbix-web02 zabbix_agentd.d]# chmod a+x memcache_monitor.sh

测试

[root@zabbix-web02 zabbix_agentd.d]# bash memcache_monitor.sh memcached_status 11211  curr_connections
1

修改agent配置文件

[root@zabbix-web02 zabbix_agentd.d]# vim ../zabbix_agentd.conf

UserParameter=memcache_status[*],/etc/zabbix/zabbix_agentd.d/memcache_monitor.sh* "$1" "$2" "$3"

重启

[root@zabbix-web02 zabbix_agentd.d]# systemctl restart zabbix-agent.service

server端测试

[root@zabbix-server ~]# zabbix_get -s 172.31.1.26 -p 10050 -k "memcache_status["memcached_status","11211","curr_connections"]"
1

web界面自定义模板

创建模板

创建监控项

创建触发器

创建图形

主机关联模板

检测看看刚才自定义的是否能收到数据

原文地址:https://www.cnblogs.com/xuanlv-0413/p/15171545.html