#####redis-audit####
统计key分布,是否配置过期时间,是否长时间没有操作:
1、安装:https://github.com/snmaynard/redis-audit下载
2、依赖包:rubygems ruby bundler-1.10.5.gem redis-3.2.1.gem
3、进入到目录下: bundle exec ruby redis-audit.rb 127.0.0.1 40000 0 1000
(bundle exec ruby redis-audit.rb [host] [port] [dbnum] [(optional)sample_size])
4、需要auth的可以在连接redis的时候配置password
5、dbsize获取数据库大小; 使用randomkey获取随机key;debug object 获取key大小;
type获取key类型;ttl获取key的过期信息;匹配超过key长度1/3的放到一个组
示例输出:
[root@bjm6-24-20 redis-audit-master]# bundle exec ruby /work/soft/redis-audit-master/redis-audit.rb 127.0.0.1 40000 0 10
Auditing 127.0.0.1:40000 dbnum:0 sampling 10 keys
Sampling 10 keys...
1 keys sampled - 10% complete - Sun Jun 28 17:50:55 +0800 2015
2 keys sampled - 20% complete - Sun Jun 28 17:50:55 +0800 2015
3 keys sampled - 30% complete - Sun Jun 28 17:50:55 +0800 2015
4 keys sampled - 40% complete - Sun Jun 28 17:50:55 +0800 2015
5 keys sampled - 50% complete - Sun Jun 28 17:50:55 +0800 2015
6 keys sampled - 60% complete - Sun Jun 28 17:50:55 +0800 2015
7 keys sampled - 70% complete - Sun Jun 28 17:50:55 +0800 2015
8 keys sampled - 80% complete - Sun Jun 28 17:50:55 +0800 2015
9 keys sampled - 90% complete - Sun Jun 28 17:50:55 +0800 2015
10 keys sampled - 100% complete - Sun Jun 28 17:50:55 +0800 2015
DB has 39844482 keys
Sampled 50 bytes of Redis memory
Found 3 key groups
==============================================================================
Found 1 keys containing strings, like:
c69820248
These keys use 10.0% of the total sampled memory (5 bytes)
None of these keys expire
Average last accessed time: 7 hours, 12 minutes, 37 seconds - (Max: 7 hours, 12 minutes, 37 seconds Min:7 hours, 12 minutes, 37 seconds)
==============================================================================
Found 2 keys containing strings, like:
a96563681, a96026184
These keys use 20.0% of the total sampled memory (10 bytes)
None of these keys expire
Average last accessed time: 4 hours, 28 minutes, 5 seconds - (Max: 4 hours, 37 minutes, 1 seconds Min:4 hours, 19 minutes, 9 seconds)
==============================================================================
Found 7 keys containing strings, like:
b74872995, b73310193, b64434574, b64319909, b71458564, b66514883, b71289887
These keys use 70.0% of the total sampled memory (35 bytes)
None of these keys expire
Average last accessed time: 7 hours, 31 minutes, 56 seconds - (Max: 10 hours, 31 minutes, 19 seconds Min:4 hours, 22 minutes, 49 seconds)
==============================================================================
Summary
---------------------------------------------------+--------------+-------------------+---------------------------------------------------
Key | Memory Usage | Expiry Proportion | Last Access Time
---------------------------------------------------+--------------+-------------------+---------------------------------------------------
b74872995 | 70.0% | 0.0% | 4 hours, 22 minutes, 49 seconds
a96563681 | 20.0% | 0.0% | 4 hours, 19 minutes, 9 seconds
c69820248 | 10.0% | 0.0% | 7 hours, 12 minutes, 37 seconds
---------------------------------------------------+--------------+-------------------+---------------------------------------------------
[root@bjm6-24-20 redis-audit-master]#
####redis-sampler####
统计key类型分布,各个类型的数据情况
1、安装:https://github.com/antirez/redis-sampler下载
2、使用:./redis-sampler.rb 127.0.0.1 6379 0 6
(redis-sampler.rb )
3、需要auth的可以在连接redis的时候配置password
示例输出:
[root@db redis-sampler-master]# ./redis-sampler.rb 127.0.0.1 6379 0 6
Sampling 127.0.0.1:6379 DB:0 with 6 RANDOMKEYS
TYPES
=====
string: 5 (83.33%) list: 1 (16.67%)
EXPIRES
=======
unknown: 6 (100.00%)
Average: 0.00 Standard Deviation: 0.00
Min: 0 Max: 0
Powers of two distribution: (NOTE <= p means: p/2 < x <= p)
Note: 'unknown' expire means keys with no expire
STRINGS, SIZE OF VALUES
=======================
2: 3 (60.00%) 4: 2 (40.00%)
Average: 2.80 Standard Deviation: 0.98
Min: 2 Max: 4
Powers of two distribution: (NOTE <= p means: p/2 < x <= p)
<= 2: 3 (60.00%) <= 4: 2 (40.00%)
LISTS, NUMBER OF ELEMENTS
=========================
3: 1 (100.00%)
Average: 3.00 Standard Deviation: 0.00
Min: 3 Max: 3
Powers of two distribution: (NOTE <= p means: p/2 < x <= p)
<= 4: 1 (100.00%)
LISTS, SIZE OF ELEMENTS
=======================
1: 1 (100.00%)
Average: 1.00 Standard Deviation: 0.00
Min: 1 Max: 1
Powers of two distribution: (NOTE <= p means: p/2 < x <= p)
<= 1: 1 (100.00%)
####redis-stat####
实时输出redis当前状态:cpu,内存,命中率,key总数等信息,并且还包括了web展示功能
1、安装:下载jar包;或者ruby包(ruby好多依赖包,还是jar比较好调试)
https://github.com/junegunn/redis-stat
2、使用:
java -jar redis-stat-0.4.12.jar 127.0.0.1:40000 --server=8380
usage: redis-stat [HOST[:PORT] ...] [INTERVAL [COUNT]]
-a, --auth=PASSWORD Password
-v, --verbose Show more info
--style=STYLE Output style: unicode|ascii
--no-color Suppress ANSI color codes
--csv[=CSV_FILE] Print or save the result in CSV
--es=ELASTICSEARCH_URL Send results to ElasticSearch: [http://]HOST[:PORT][/INDEX]
--server[=PORT] Launch redis-stat web server (default port: 63790)
--daemon Daemonize redis-stat. Must be used with --server option.
--version Show version
--help Show this message
示例输出,也可以访问http://xxx.xxx.xxx.xxx:8380查看
[root@bjm6-24-20 soft]# java -jar redis-stat-0.4.12.jar 127.0.0.1:40000 --server=8380
┌────────────────────────┬─────────────────┐
│ │ 127.0.0.1:40000 │
├────────────────────────┼─────────────────┤
│ redis_version │ 3.0.2 │
│ redis_mode │ standalone │
│ process_id │ 34392 │
│ uptime_in_seconds │ 262423 │
│ uptime_in_days │ 3 │
│ role │ master │
│ connected_slaves │ 0 │
│ aof_enabled │ 0 │
│ rdb_bgsave_in_progress │ 1 │
│ rdb_last_save_time │ 1435485239 │
└────────────────────────┴─────────────────┘
┌────────┬──┬──┬──┬───┬──────┬──────┬─────┬─────┬─────┬─────┬──────┬─────┬─────┬─
────┐
time us sy cl bcl mem rss keys cmd/s exp/s evt/s hit%/s hit/s mis/s aofcs
├────────┼──┼──┼──┼───┼──────┼──────┼─────┼─────┼─────┼─────┼──────┼─────┼─────┼─
────┤
17:55:08 - - 2 0 4.66GB 5.76GB 39.9M - - - - - - 0B
17:55:10 4 10 1 0 4.66GB 5.76GB 39.9M 1.40k 0 322 33.3 723 1.45k 0B
17:55:12 4 10 1 0 4.66GB 5.76GB 39.9M 1.38k 0 475 33.3 711 1.42k 0B
17:55:14 5 10 1 0 4.66GB 5.76GB 39.9M 1.37k 0 477 33.3 709 1.42k 0B
17:55:16 3 11 1 0 4.66GB 5.76GB 39.9M 1.35k 0 463 33.3 697 1.39k 0B
17:55:18 5 9 2 0 4.66GB 5.76GB 39.9M 1.35k 0 464 33.3 698 1.40k 0B
17:55:20 5 10 1 0 4.66GB 5.76GB 39.9M 1.33k 0 456 33.3 689 1.38k 0B
17:55:22 4 9 1 0 4.66GB 5.76GB 39.9M 1.31k 0 432 33.3 703 1.41k 0B
17:55:24 4 10 1 0 4.66GB 5.76GB 39.9M 1.30k 0 424 33.3 703 1.41k 0B
17:55:26 5 10 1 0 4.66GB 5.76GB 39.9M 1.30k 0 429 33.3 701 1.40k 0B
└────────┴──┴──┴──┴───┴──────┴──────┴─────┴─────┴─────┴─────┴──────┴─────┴─────┴─
────┘
####redis-rdb-tools#######
功能:rdb解析,生成json,protocol,diff等解析格式
1、下载:https://github.com/sripathikrishnan/redis-rdb-tools
2、确保python环境(需要安装setuptools, redis-py)
3、python setup.py install
多出几个命令:rdb redis-profiler redis-memory-for-key
使用:
rdb:
1)rdb --command json dump.rdb:解析成json串
2)rdb --command json --key "user.*" dump.rdb:解析rdb文件,找出包含user关键字的key
雷同:rdb --command json --db 2 --type list --key "a.*" dump.rdb
3)rdb -c memory /var/redis/6379/dump.rdb > memory.csv:到csv文件
4)对比:
rdb --command diff dump1.rdb | sort > dump1.txt
rdb --command diff dump2.rdb | sort > dump2.txt
kdiff3 dump1.txt dump2.txt
5)解析成redis协议的流:
rdb --command protocol /var/redis/6379/dump.rdb
rdb -c protocol dump.rdb | redis-cli -d 1 -p 40002 --pipe (导入到指定数据库)
redis-memory-for-key
找出一个key占用内存的大小:
redis-memory-for-key -s 127.0.0.1 -p 6379 -a password person
redis-profiler:解析成html格式:
redis-profiler dump40000.rdb >1.html
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/20625855/viewspace-1715597/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/20625855/viewspace-1715597/