分类目录归档:zabbix

zabbix监控redis

1.脚本如下
cat redis.sh

#!/bin/bash
redis_conn="/usr/local/bin/redis-cli"
port=$1

case $2 in 
  "used_memory")
    used_memory=`$redis_conn -p $port info | grep used_memory:|awk -F':' '{print $2}'`
    echo $used_memory
    ;;
  "ops_sec")
    ops=`$redis_conn -p $port info|grep instantaneous_ops_per_sec:|awk -F':' '{print $2}'`
    echo $ops
    ;;
  "connected_clients")
    connected_clients=`$redis_conn -p $port info|grep connected_clients: | awk -F ':' '{print $2}'`
    echo $connected_clients
    ;;
  "blocked_clients")
    blocked_clients=`$redis_conn -p $port info|grep blocked_clients:|awk -F':' '{print $2}'`
    echo $blocked_clients
    ;; 
  *)
    echo "please input used_memory|ops_sec|connected_clients|blocked_clients"
    ;; 
esac

2.conf文件
cat zabbix_redis.conf
UserParameter=redis[*],/opt/script/zabbix/redis.sh $1 $2

zabbix监控memcache

1.脚本如下
cat memcached.sh

#!/bin/bash
port=$1
mem_conn="/bin/nc 127.0.0.1 $port"

case $2 in 
  conn)
    conn=`echo -e "stats\nquit"|$mem_conn|grep curr_connections | awk '{print $3}' `
    echo $conn
    ;;
  bytes)
    bytes=`echo -e "stats\nquit"|$mem_conn|grep bytes|awk '{print $3}'`
    echo `echo $bytes |tr -d " "`
    ;;
  cmd_get)
    cmd_get=`echo -e "stats\nquit"|$mem_conn|grep cmd_get| awk '{print $3}' `
    echo $cmd_get
    ;;
  cmd_set)
    cmd_set=`echo -e "stats\nquit"|$mem_conn|grep cmd_set| awk '{print $3}' `
    echo $cmd_set
    ;;
  get_hits)
    get_hits=`echo -e "stats\nquit"|$mem_conn|grep get_hits| awk '{print $3}' `
    echo $get_hits
    ;;
  read_qps_sec)
    count1=`echo -e "stats\nquit"|$mem_conn|grep cmd_get| awk '{print $3}'|tr -d '\r' `
    sleep 1
    count2=`echo -e "stats\nquit"|$mem_conn|grep cmd_get| awk '{print $3}'|tr -d '\r' `
    count=` expr $count2 - $count1`
    echo $count
    ;;
  write_qps_sec)
    count1=`echo -e "stats\nquit"|$mem_conn|grep cmd_set| awk '{print $3}' `
    sleep 1
    count2=`echo -e "stats\nquit"|$mem_conn|grep cmd_set| awk '{print $3}' `
    count=`echo $count2 $count1|awk '{printf($1-$2)}'`
    echo $count
    ;;
  
  hit_target)
    cmd_get=`echo -e "stats\nquit"|$mem_conn|grep cmd_get| awk '{print $3}' `
    get_hits=`echo -e "stats\nquit"|$mem_conn|grep get_hits| awk '{print $3}' `
    hit_target=`echo $get_hits $cmd_get|awk '{printf($1*100/$2)}'`
    echo $hit_target
    ;;
  *)
    echo "please input conn|bytes|cmd_get|cmd_set|get_hits|read_qps_sec|write_qps_sec|hit_target"
    ;;
esac

2.配置文件放到zabbix的conf.d/目录下,

cat zabbix_memcache.conf
UserParameter=memcache[*],/opt/script/zabbix/memcached.sh $1 $2