91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

redis監控zabbix自動化模板-節點狀態、內存、連接數

發布時間:2020-05-10 14:07:00 來源:網絡 閱讀:346 作者:鼻涕蟲YP 欄目:系統運維

首先介紹下監控redis那些信息:

Redis ping:檢驗ping
Redis alive:查看檢查端口是否alive
Redis connections:查看連接數
Redis blockedClients:正在等待阻塞客戶端數量
Redis connectionsUsage:redis的連接使用率
Redis memoryUsage:redis內存使用量
Redis memoryUsageRate:redis內存使用率
Redis evictedKeys:運行以來刪除過的key的數量
Redis rejectedConnections:拒絕連接數
Redis ops:redis的OPS
Redis hitRate:redis命中率

redis自動檢測端口(shell)

#!/bin/sh
REDIS_SERVER_PIDS="$(ps -ef|egrep -v 'grep|egrep|vi|vim|find|cat|tac|head|tail|more|less'|grep 'redis-server'|awk '{print $2}')"
REDIS_PORTS=""
for pid in ${REDIS_SERVER_PIDS};do
  PORTS=$(sudo netstat -anlp|grep -w ${pid}|awk '{print $4}'|awk -F: '{print $2}'|grep -v "[0-9][0-9][0-9][0-9][0-9]"|grep -v "^$" |head -1)
  REDIS_PORTS="${PORTS} ${REDIS_PORTS}"
done
port=(${REDIS_PORTS})

function node_port {
length=${#port[@]}
printf "{\n"
printf '\t'"\"data\":["
for ((i=0;i<$length;i++));do
printf '\n\t\t{'
printf "\"{#REDIS_PORT}\":\"${port[$i]}\"}"
if [ $i -lt $[$length-1] ];then
printf ','
fi
done
printf "\n\t]\n"
printf "}\n"
}
node_por

redis監控zabbix自動化模板-節點狀態、內存、連接數

redis自動檢測端口(python)

#!/usr/bin/env python
import os
import json
#t=os.popen("""netstat -natp|awk -F: '/redis-server/&&/LISTEN/{print $2}'|awk '{print $1}' """)
t=os.popen("""ps aux |egrep -v 'grep|egrep|vi|vim|cat|tac|head|tail|more|less'|grep 'redis-server'|awk -F '*:' '{print $2}'|awk '{print $1}' """)
ports = []
for port in t.readlines():
    r = os.path.basename(port.strip())
    ports += [{'{#REDIS_PORT}':r}]
print json.dumps({'data':ports},sort_keys=True,indent=4,separators=(',',':'))

檢測內存、節點狀態、連接數、內存使用率、連接數使用率等等

#!/usr/bin/env python
#-*- coding: utf-8 -*-
__author__ = 'chenmingle'

import sys
import subprocess
import json

try:
    import redis
except Exception, e:
    print 'pip install redis'
    sys.exit(1)

class Redis(object):  
    def __init__(self, host, port, password=None):
        self.host = host
        self.port = port
        self.password = password
        if self.password:
            self.rds = redis.StrictRedis(host=host, port=port, password=self.password)
        else:
            self.rds = redis.StrictRedis(host=host, port=port)
        try:
            self.info = self.rds.info()
        except Exception, e:
            self.info = None

    def redis_connections(self):
        try:
            return self.info['connected_clients']
        except Exception, e:
            return 0

    def redis_connections_usage(self):
        try:
            curr_connections = self.redis_connections()
            max_clients = self.parse_config('maxclients')
            rate = float(curr_connections) / float(max_clients)
            return "%.2f" % (rate * 100)
        except Exception, e:
            return 0

    def redis_used_memory(self):
        try:
            return self.info['used_memory']
        except Exception, e:
            return 0

    def redis_memory_usage(self):
        try:
            used_memory = self.info['used_memory']
            max_memory = self.info['maxmemory']
            system_memory = self.info['total_system_memory']
            if max_memory:
                rate = float(used_memory) / float(max_memory)
            else:
                rate = float(used_memory) / float(system_memory)
            return "%.2f" % (rate * 100)
        except Exception, e:
            return 0

    def redis_ping(self):
        try:
            return self.rds.ping()
        except Exception, e:
            return False

    def rejected_connections(self):
        try:
            return self.info['rejected_connections']
        except Exception, e:
            return 999

    def evicted_keys(self):
        try:
            return self.info['evicted_keys']
        except Exception, e:
            return 999

    def blocked_clients(self):
        try:
            return self.info['blocked_clients']
        except Exception, e:
            return 0

    def ops(self):
        try:
            return self.info['instantaneous_ops_per_sec']
        except Exception, e:
            return 0

    def hitRate(self):
        try:
            misses = self.info['keyspace_misses']
            hits = self.info['keyspace_hits']
            rate = float(hits) / float(int(hits) + int(misses))
            return "%.2f" % (rate * 100)
        except Exception, e:
            return 0

    def parse_config(self, type):
        try:
            return self.rds.config_get(type)[type]
        except Exception, e:
            return None

    def test(self):
        print 'Redis ping: %s' % self.redis_ping()
        print 'Redis alive: %s ' % check_alive(self.host, self.port)
        print 'Redis connections: %s' % self.redis_connections()
        print 'Redis blockedClients %s' % self.blocked_clients()
        print 'Redis connectionsUsage: %s%%' % self.redis_connections_usage()
        print 'Redis memoryUsage: %s' % self.redis_used_memory()
        print 'Redis memoryUsageRate: %s%%' % self.redis_memory_usage()
        print 'Redis evictedKeys: %s' % self.evicted_keys()
        print 'Redis rejectedConnections: %s' % self.rejected_connections()
        print 'Redis ops: %s' % self.ops()
        print 'Redis hitRate: %s%%' % self.hitRate()

def check_alive(host, port):
    cmd = 'nc -z %s %s > /dev/null 2>&1' % (host, port)
    return subprocess.call(cmd, shell=True)

def parse(type, host, port, password):
    rds = Redis(host, port, password)
    if type == 'connections':
        print rds.redis_connections()
    elif type == 'connectionsUsage':
        print rds.redis_connections_usage()
    elif type == 'blockedClients':
        print rds.blocked_clients()
    elif type == 'ping':
        print rds.redis_ping()
    elif type == 'alive':
        print check_alive(host, port)
    elif type == 'memoryUsage':
        print rds.redis_used_memory()
    elif type == 'memoryUsageRate':
        print rds.redis_memory_usage()
    elif type == 'rejectedConnections':
        print rds.rejected_connections()
    elif type == 'evictedKeys':
        print rds.evicted_keys()
    elif type == 'hitRate':
        print rds.hitRate()
    elif type == 'ops':
        print rds.ops()
    else:
        rds.test()

if __name__ == '__main__':
    try:
        type = sys.argv[1]
        host = sys.argv[2]
        port = sys.argv[3]
        if sys.argv.__len__() >=5:
            password = sys.argv[4]
        else:
            password = None
    except Exception, e:
        print "Usage: python %s type 127.0.0.1 6379" % sys.argv[0]
        sys.exit(1)
    parse(type, host, port, password)
        ###python支持redis模板否則會報錯

redis監控zabbix自動化模板-節點狀態、內存、連接數

zabbix配置配置文件添加

UserParameter=redis_port.discovery-py,/app/sinova/zabbix/scripts/check_redis_port.py
UserParameter=redis.stats[*],/app/sinova/python2.7.15/bin/python /app/sinova/zabbix/scripts/check_redis.py $1 127.0.0.1 $2

###配置完重啟zabbix否則不生效

zabbix模板配置

redis監控zabbix自動化模板-節點狀態、內存、連接數
redis監控zabbix自動化模板-節點狀態、內存、連接數

自動發現規則

redis監控zabbix自動化模板-節點狀態、內存、連接數

 ###配置監控相項把以上需要監控配置即可

例子

redis監控zabbix自動化模板-節點狀態、內存、連接數

 redis.stats[memoryUsageRate,{#REDIS_PORT}]

redis監控zabbix自動化模板-節點狀態、內存、連接數

 {HOST.NAME}:{#REDIS_PORT} redis redis 連接數使用率>80%,達到{ITEM.LASTVALUE1}
 {Template for redis-zabbix:redis.stats[connectionsUsage,{#REDIS_PORT}].last()}>80
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

桐梓县| 威远县| 秦安县| 德安县| 郧西县| 柘荣县| 大城县| 宜川县| 云梦县| 绥化市| 石泉县| 绍兴县| 安岳县| 松原市| 五指山市| 怀集县| 扶风县| 嫩江县| 商丘市| 宜章县| 乌拉特前旗| 银川市| 苗栗市| 太白县| 贵定县| 岳池县| 深圳市| 双牌县| 山东省| 邵阳市| 图们市| 巨鹿县| 温宿县| 县级市| 茌平县| 泰来县| 龙川县| 高邑县| 浦北县| 磐石市| 扶绥县|