/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. vue项目中禁止移动端双击放大,双手拉大放大的方法

    在vue打包后生成的dist目录文件下下面有index.html 打开里面 把原来的这个 <meta name=viewport content="width=device-width ...

  2. CAS 5.X 安装

    官方文档: https://apereo.github.io/cas/5.1.x/index.html 几个基本概念 CAS Server: SSO服务器端 CAS Client : SSO客户端,内 ...

  3. 随性练习:python字典实现文本合并

    主要用到,字典.字符串分割和连接.文件等操作 例如:有以下两个txt文本,要合并成一个 代码: address_book1 = {} address_book2 = {} def read_addre ...

  4. Why Nexiq 125032 USB Link Truck diagnostic tool is so helpful ?

    As for as I am concerned , Heavy Duty Diagnostic Nexiq 125032 USB is a helpful tool , which has exce ...

  5. 转载 Some indexes or index [sub]partitions of table VAS.TAB_PUB_CALLLOG have been marked unusable

    http://www.xifenfei.com/2011/12/some-indexes-or-index-subpartitions-of-table-vas-tab_pub_calllog-hav ...

  6. axios拦截器搭配token使用

    在了解到cookie.session.token的作用后学习token的使用 cookie是随着url将参数发送到后台,安全性最低,并且大小受限,不超过4kb左右,它的数据保存在客户端 session ...

  7. vue interceptors 设置请求头

    在main.js添加过滤器,可以 Vue.http.interceptors.push((request,next)=>{ //request.credentials = true; // 接口 ...

  8. maya2014安装失败如何卸载重装

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  9. [转]jQuery.getJSON的缓存问题的解决办法

    本文转自:http://mfan.iteye.com/blog/974132 今天做测试工作,发现了一个令我费解的问题,jquery的getJson方法在firefox上运行可以得到返回的结果,但是在 ...

  10. linux上的常用命令

    删除目录及文件 (删除tem目录和所有.xml文件) rm -rf tem/ *.xml 复制文件 cp zoo_sample.cfg zoo.cfg 两台机的目录相互拷贝 scp -r apps/ ...