/usr/lib/check_mk_agent/plugins/mk_redis

#!/bin/bash

echo '<<<redis>>>'
hosts=$(netstat -nlp -t |grep redis-server|awk '{print $4}') for host in $hosts;
do
ip=$(echo $host|cut -d ':' -f1)
port=$(echo $host|cut -d ':' -f2)
echo "start $ip:$port"
redis-cli -p $port info |egrep '^redis_version|^redis_mode|^process_id|^uptime_in_days|^rdb_last_save_time|^rdb_changes_since_last_save|^master_link_down_since|^role|^connected_slaves|^master_last_io_seconds_ago|^blocked_clients|^connected_clients|^rejected_connections|^blocked_clients|^connected_clients|^rejected_connections|^instantaneous_ops_per_sec|^keyspace_hits|^keyspace_misses|^evicted_keys|^used_memory:|^mem_fragmentation_ratio'|awk -F ':' '{print $1,$2}'
echo "end $ip:$port"
done

/opt/omd/sites/test/share/check_mk/checks/redis

'''
start 127.0.0.1:6381
redis_version 2.8.19
redis_mode standalone
process_id 13675
uptime_in_days 5
rdb_changes_since_last_save 0
rdb_last_save_time 1490268431
role master
connected_slaves 0 connected_clients 1
blocked_clients 0
rejected_connections 0
evicted_keys 0
instantaneous_ops_per_sec 0 keyspace_hits 0
keyspace_misses 0 used_memory 502624 mem_fragmentation_ratio 11.67
end 127.0.0.1:6381
''' import time def inventory_redis_info(info):
inventory = []
for line in info:
if line[0] == 'start':
inventory.append((line[1], None))
return inventory def inventory_redis_stat(info):
inventory = []
for line in info:
if line[0] == 'start':
inventory.append((line[1], None))
return inventory def check_redis_info(item, params, info):
message = []
flag = False
for line in info:
if line[0] == 'end' and line[1] == item:
break elif line[0] == 'start' and line[1] == item:
flag = True elif flag:
if line[0] in ['redis_version', 'redis_mode', 'process_id', 'uptime_in_days', 'role', 'connected_slaves', 'rdb_changes_since_last_save']:
message.append(line[0]+': '+line[1])
elif line[0] in ['rdb_last_save_time']:
message.append(line[0]+': '+ time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(int(line[1])))) return 0, ', '.join(message) def check_redis_stat(item, params, info):
message = []
perfdata = []
flag = False for line in info:
if line[0] == 'end' and line[1] == item:
break elif line[0] == 'start' and line[1] == item:
flag = True elif flag:
if line[0] in ['connected_clients', 'blocked_clients', 'rejected_connections', 'evicted_keys', 'instantaneous_ops_per_sec', 'used_memory']:
message.append(line[0]+': '+line[1])
perfdata.append((line[0], int(line[1]), None, None, 0, None)) elif line[0] in ['mem_fragmentation_ratio']:
message.append(line[0]+': '+line[1])
perfdata.append((line[0], float(line[1]), None, None, 0, 100)) elif line[0] in ['keyspace_hits']:
message.append(line[0]+': '+line[1])
perfdata.append((line[0], int(line[1]), None, None, 0, None))
hits = int(line[1]) elif line[0] in ['keyspace_misses']:
message.append(line[0]+': '+line[1])
perfdata.append((line[0], int(line[1]), None, None, 0, None))
misses = int(line[1])
if (hits+misses) == 0:
hit_rate = 0
else:
hit_rate = round(hits/(hits+misses)*1.0, 2) message.append('hit_rate: %.2f' % hit_rate)
perfdata.append(('hit_rate', hit_rate*100, None, None, 0, 100)) return 0, ', '.join(message), perfdata check_info['redis.info'] = {
'check_function': check_redis_info,
'inventory_function': inventory_redis_info,
'service_description': 'redis_info %s',
} check_info['redis.stat'] = {
'check_function': check_redis_stat,
'inventory_function': inventory_redis_stat,
'service_description': 'redis_stat %s',
'has_perfdata': True,
}

/opt/omd/sites/test/share/check_mk/pnp-templates/check_mk-redis.stat.php

<?php

# clients
$opt[1] = "-t \"Clients\" -v \"Number\" -l 0 ";
$def[1] = ""; $def[1] .= "DEF:v1=$RRDFILE[1]:$DS[1]:MAX ";
$def[1] .= "LINE2:v1#ff4000:\"connected_clients\" ";
$def[1] .= "GPRINT:v1:LAST:\"last \:%5.0lf\" ";
$def[1] .= "GPRINT:v1:AVERAGE:\"avg \:%5.0lf\" ";
$def[1] .= "GPRINT:v1:MAX:\"max \:%5.0lf\" ";
$def[1] .= "GPRINT:v1:MIN:\"min \:%5.0lf\" "; $def[1] .= "DEF:v2=$RRDFILE[2]:$DS[2]:MAX ";
$def[1] .= "LINE2:v2#a00000:\"blocked_clients\" ";
$def[1] .= "GPRINT:v2:LAST:\"last \:%5.0lf\" ";
$def[1] .= "GPRINT:v2:AVERAGE:\"avg \:%5.0lf\" ";
$def[1] .= "GPRINT:v2:MAX:\"max \:%5.0lf\" ";
$def[1] .= "GPRINT:v2:MIN:\"min \:%5.0lf\" "; $def[1] .= "DEF:v6=$RRDFILE[6]:$DS[6]:MAX ";
$def[1] .= "LINE2:v6#00f040:\"rejected_connections\" ";
$def[1] .= "GPRINT:v6:LAST:\"last \:%5.0lf\" ";
$def[1] .= "GPRINT:v6:AVERAGE:\"avg \:%5.0lf\" ";
$def[1] .= "GPRINT:v6:MAX:\"max \:%5.0lf\" ";
$def[1] .= "GPRINT:v6:MIN:\"min \:%5.0lf\" "; $def[1] .= "DEF:v7=$RRDFILE[7]:$DS[7]:MAX ";
$def[1] .= "LINE2:v7#00b0b0:\"evicted_keys\" ";
$def[1] .= "GPRINT:v7:LAST:\"last \:%5.0lf\" ";
$def[1] .= "GPRINT:v7:AVERAGE:\"avg \:%5.0lf\" ";
$def[1] .= "GPRINT:v7:MAX:\"max \:%5.0lf\" ";
$def[1] .= "GPRINT:v7:MIN:\"min \:%5.0lf\" "; $def[1] .= "DEF:v8=$RRDFILE[8]:$DS[8]:MAX ";
$def[1] .= "LINE2:v8#c060ff:\"keyspace_hits\" ";
$def[1] .= "GPRINT:v8:LAST:\"last \:%5.0lf\" ";
$def[1] .= "GPRINT:v8:AVERAGE:\"avg \:%5.0lf\" ";
$def[1] .= "GPRINT:v8:MAX:\"max \:%5.0lf\" ";
$def[1] .= "GPRINT:v8:MIN:\"min \:%5.0lf\" "; $def[1] .= "DEF:v9=$RRDFILE[9]:$DS[9]:MAX ";
$def[1] .= "LINE2:v9#f000f0:\"keyspace_misses\" ";
$def[1] .= "GPRINT:v9:LAST:\"last \:%5.0lf\" ";
$def[1] .= "GPRINT:v9:AVERAGE:\"avg \:%5.0lf\" ";
$def[1] .= "GPRINT:v9:MAX:\"max \:%5.0lf\" ";
$def[1] .= "GPRINT:v9:MIN:\"min \:%5.0lf\" "; $def[1] .= "DEF:v5=$RRDFILE[5]:$DS[5]:MAX ";
$def[1] .= "LINE2:v5#ff4000:\"instantaneous_ops_per_sec\" ";
$def[1] .= "GPRINT:v5:LAST:\"last \:%5.0lf\" ";
$def[1] .= "GPRINT:v5:AVERAGE:\"avg \:%5.0lf\" ";
$def[1] .= "GPRINT:v5:MAX:\"max \:%5.0lf\" ";
$def[1] .= "GPRINT:v5:MIN:\"min \:%5.0lf\" "; # performance
$opt[2] = "-t \"Performance\" -v \"(%)\" -l 0 ";
$def[2] = ""; $def[2] .= "DEF:v4=$RRDFILE[4]:$DS[4]:MAX ";
$def[2] .= "LINE2:v4#a00000:\"mem_fragmentation_ratio\" ";
$def[2] .= "GPRINT:v4:LAST:\"last \:%5.2lf\" ";
$def[2] .= "GPRINT:v4:AVERAGE:\"avg \:%5.2lf\" ";
$def[2] .= "GPRINT:v4:MAX:\"max \:%5.2lf\" ";
$def[2] .= "GPRINT:v4:MIN:\"min \:%5.2lf\" "; $def[2] .= "DEF:v10=$RRDFILE[10]:$DS[10]:MAX ";
$def[2] .= "LINE2:v10#00f040:\"hit_rate\" ";
$def[2] .= "GPRINT:v10:LAST:\"last \:%5.2lf\" ";
$def[2] .= "GPRINT:v10:AVERAGE:\"avg \:%5.2lf\" ";
$def[2] .= "GPRINT:v10:MAX:\"max \:%5.2lf\" ";
$def[2] .= "GPRINT:v10:MIN:\"min \:%5.2lf\" "; # memory
$opt[3] = "-t \"Use Memory\" -v \"Bytes\" -l 0 ";
$def[3] = ""; $def[3] .= "DEF:v3=$RRDFILE[3]:$DS[3]:MAX ";
$def[3] .= "AREA:v3#FF6666:\"use_memory\" ";
$def[3] .= "GPRINT:v3:LAST:\"last \:%5.0lf\" ";
$def[3] .= "GPRINT:v3:AVERAGE:\"avg \:%5.0lf\" ";
$def[3] .= "GPRINT:v3:MAX:\"max \:%5.0lf\" ";
$def[3] .= "GPRINT:v3:MIN:\"min \:%5.0lf\" ";
?>





check_mk插件 redis的更多相关文章

  1. collectd的python插件(redis)

    https://blog.dbrgn.ch/2017/3/10/write-a-collectd-python-plugin/ redis_info.conf <LoadPlugin pytho ...

  2. Nagios监控生产环境redis群集服务战

    前言:     曾经做了cacti上展示redis性能报表图.能够看到redis的性能变化趋势图,可是还缺了实时报警通知的功能,如今补上这一环节. 在redis服务瓶颈或者异常时候即使报警通知,方便d ...

  3. 【JAVAWEB学习笔记】网上商城实战2:异步加载分类、Redis缓存分类和显示商品

    网上商城实战2 今日任务 完成分类模块的功能 完成商品模块的功能 1.1      分类模块的功能: 1.1.1    查询分类的功能: 1.1.2    查询分类的代码实现: 1.1.2.1  创建 ...

  4. 【Redis】集群方式

    一.概述 1.1 Redis3.0版本之前 1.2 常见集群方案 二.Redis-Cluster原理 三.搭建集群方案 3.1 准备工作 3.2 创建模拟集群的文件夹 3.3 复制脚本 3.4 复制一 ...

  5. 日志分析平台ELK之日志收集器logstash常用插件配置

    前文我们了解了logstash的工作流程以及基本的收集日志相关配置,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13761906.html:今天我们来了解下l ...

  6. 为什么Redis集群要使用反向代理?

    为什么要使用反向代理? 如果没有方向代理,一台Redis可能需要跟很多个客户端连接: 看着是不是很慌?看没关系,主要是连接需要消耗线程资源,没有代理的话,Redis要将很大一部分的资源用在与客户端建立 ...

  7. redis缓存穿透穿透解决方案-布隆过滤器

    redis缓存穿透穿透解决方案-布隆过滤器 我们先来看一段代码 cache_key = "id:1" cache_value = GetValueFromRedis(cache_k ...

  8. [Logstash-input-redis] 使用详解

    redis插件的完整配置 input { redis { batch_count => 1 #返回的事件数量,此属性仅在list模式下起作用. data_type => "lis ...

  9. logstash使用操作部分

    1.logstash的概念及特点.概念:logstash是一个数据采集.加工处理以及传输(输出)的工具.特点: - 所有类型的数据集中处理 - 不同模式和格式数据的正常化 - 自定义日志格式的迅速扩展 ...

随机推荐

  1. Qt 学习之路 2(14):对话框数据传递

    Home / Qt 学习之路 2 / Qt 学习之路 2(14):对话框数据传递 Qt 学习之路 2(14):对话框数据传递  豆子  2012年9月15日  Qt 学习之路 2  53条评论 对话框 ...

  2. java 解决Hash(散列)冲突的四种方法--开放定址法(线性探测,二次探测,伪随机探测)、链地址法、再哈希、建立公共溢出区

    java 解决Hash(散列)冲突的四种方法--开放定址法(线性探测,二次探测,伪随机探测).链地址法.再哈希.建立公共溢出区 标签: hashmaphashmap冲突解决冲突的方法冲突 2016-0 ...

  3. npm install 安装包报错

    D:\hapi_learn>npm .x.x npm ERR! code ENOSELF npm ERR! Refusing to install package with name " ...

  4. 【bzoj2935】[Poi1999]原始生物

    2935: [Poi1999]原始生物 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 145  Solved: 71[Submit][Status][D ...

  5. 小乐乐打游戏(BFS+曼哈顿距离)

    时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld 题目描述 小乐乐觉得学习太简单了,剩下那么多的时间好无聊 ...

  6. P1029 最大公约数和最小公倍数问题(思维题)

    题目描述 输入22个正整数x_0,y_0(2 \le x_0<100000,2 \le y_0<=1000000)x0​,y0​(2≤x0​<100000,2≤y0​<=100 ...

  7. poj3728之离线LCA+dp思想/RMQ+LCA(非常好的题目)

    题意很简单 给一个树(n < 5w) 每个点有个权值,代表商品价格 若干个询问(5w) 对每个询问,问的是从u点走到v点(简单路径),商人在这个路径中的某点买入商品,然后在某点再卖出商品,   ...

  8. idea生成springBoot 报错403

    问题: idea创建springboot失败 Initialization failed Cannot download 'https://start.spring.io': Status: 403 ...

  9. [2019BUAA软工]第一次团队作业

    Team V1 团队启动   BUAA Team V1 于2019年3月正式成立,将开始为期四个月的合作. 队员介绍 Name Summary Sefie wxmwy V1-bug制造公司资深工程师精 ...

  10. Problem07 处理字符串

    题目:输入一行字符,分别统计出其中英文字母.空格.数字和其它字符的个数. 程序分析:利用while 语句,条件为输入的字符不为'\n'. import java.util.*; public clas ...