Redis-audit工具使用

本文涉及的产品
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
云数据库 Tair(兼容Redis),内存型 2GB
简介:

在我的线上环境中,由于应用上对redis数据没有做冷热处理,所以经常会出现redis内存使用率居高不下的情况,一直以来都想知道都是什么样的数据比较消耗redis内存,就好比写一个sql语句放在数据库中运行,看各表占空间的大小情况然后排序下,这看上去蛮简单的一个功能,貌似在redis上还不容易实现,redis-audit工具基本上可以满足类似的需求。下面是简单的安装和使用介绍!

1:安装ruby

1
2
3
4
5
6
7
8
9
10
[root@db1 ~]# wget ftp: //ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p0.tar.gz
[root@db1 ~]# tar -zxvpf ruby- 1.9 . 2 -p0.tar.gz
[root@db1 ~]# cd ruby- 1.9 . 2 -p0
[root@db1 ruby- 1.9 . 2 -p0]# ./configure  --prefix=/usr/local/ruby
[root@db1 ruby- 1.9 . 2 -p0]# make && make install
[root@db1 ruby- 1.9 . 2 -p0]# cd
[root@redis2 ~]# grep PATH /root/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/ruby/bin:$PATH
export PATH
[root@redis2 ~]# source /root/.bash_profile

2:安装rubygems

1
2
3
4
[root@db1 ~]# wget http: //production.cf.rubygems.org/rubygems/rubygems-2.0.7.tgz
[root@db1 ~]# tar zxvf rubygems- 2.0 . 7 .tgz
[root@db1 ~]# cd rubygems- 2.0 . 7
[root@db1 rubygems- 2.0 . 7 ]# ruby setup.rb

3:使用gem安装bundler

1
2
3
4
5
6
7
[root@db1 rubygems- 2.0 . 7 ]# cd
[root@db1 ~]#  wget http: //tokyo-m.rubygems.org/gems/bundler-1.3.5.gem
[root@db1 ~]# gem install bundler -l
Successfully installed bundler- 1.3 . 5
1  gem installed
Installing ri documentation  for  bundler- 1.3 . 5 ...
Installing RDoc documentation  for  bundler- 1.3 . 5 ...

4:安装git

1
2
3
4
5
6
7
[root@db1 ~]# cat /etc/yum.repos.d/git.repo
[puias-computational]
name=PUIAS Computational
baseurl=http: //puias.math.ias.edu/data/puias/computational/5/x86_64/
enabled= 1
gpgcheck= 0
[root@db1 ~]# yum -y install git

5:使用git迁出redis-audit源代码,查看redis数据情况

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
[root@db1 ~]#  git clone https: //github.com/snmaynard/redis-audit.git
Cloning into redis-audit...
remote: Counting objects:  117 , done.
remote: Compressing objects:  100 % ( 79 / 79 ), done.
remote: Total  117  (delta  39 ), reused  113  (delta  36 )
Receiving objects:  100 % ( 117 / 117 ),  17.63  KiB, done.
Resolving deltas:  100 % ( 39 / 39 ), done.
[root@db1 ~]# cd redis-audit/
[root@db1 redis-audit]# bundle install
Fetching source index from http: //rubygems.org/
Installing redis ( 3.0 . 2 )
Using bundler ( 1.3 . 5 )
Your bundle  is  complete!
Use `bundle show [gemname]` to see where a bundled gem  is  installed.
[root@db1 redis-audit]# bundle exec ruby redis-audit.rb  192.168 . 1.13  65430  0  1000
Auditing  192.168 . 1.13 : 65430  db: 0  sampling  1000  keys
Getting a list of all  358  keys...
Auditing  358  keys...
35  keys sampled -  10 % complete -  2013 - 08 - 23  14 : 46 : 15  + 0800
70  keys sampled -  20 % complete -  2013 - 08 - 23  14 : 46 : 15  + 0800
105  keys sampled -  29 % complete -  2013 - 08 - 23  14 : 46 : 15  + 0800
140  keys sampled -  39 % complete -  2013 - 08 - 23  14 : 46 : 15  + 0800
175  keys sampled -  49 % complete -  2013 - 08 - 23  14 : 46 : 16  + 0800
210  keys sampled -  59 % complete -  2013 - 08 - 23  14 : 46 : 16  + 0800
245  keys sampled -  68 % complete -  2013 - 08 - 23  14 : 46 : 16  + 0800
280  keys sampled -  78 % complete -  2013 - 08 - 23  14 : 46 : 16  + 0800
315  keys sampled -  88 % complete -  2013 - 08 - 23  14 : 46 : 17  + 0800
350  keys sampled -  98 % complete -  2013 - 08 - 23  14 : 46 : 17  + 0800
DB has  358  keys
Sampled  464.34  MB of Redis memory
Found  12  key groups
==============================================================================
Found  23  keys containing strings, like:
ShoppingCart_6d7cfd49f68043669f30133dc5d983a9, ShoppingCart_177600d6b78d46b9990ab5f6dc5711a6, ShoppingCart_a58d6bd82e8b4e7eb55d874c831b66de,
ShoppingCart_6405daf3e0b042f580417e3100887871, ShoppingCart_8d6ff3326eaf46bc8b2e24fb9fad6f87, ShoppingCart_0179c7f4f7c84ab5bd387b068dd1632f,
ShoppingCart_93637af307fa47038db62e146351f373, ShoppingCart_0c2f7ed9663e432f8d9cdba89a186650, ShoppingCart_c08edc03c3db43c580d66593211da03f,
ShoppingCart_76069203a18c4ecba40f713b85ac24d9
These keys  use  0.0 % of the total sampled memory ( 4.33  kB)
None of these keys expire
Average last accessed time:  47  minutes,  40  seconds - (Max:  47  minutes,  40  seconds Min: 47  minutes,  40  seconds)
==============================================================================
Found  83  keys containing strings, like:
Class:TrainingOnline;UsrId:c99b93261e5642e4995e313174bc1c46;trnId:9f0ee4743e7f40c085247c14eb5eeae9;,
Class:TrainingOnline;UsrId:d6a7adaea2ea4b30907de24de0047ea6;trnId:4fb1eedb88b14d45aba927492d1c8713;,
Class:TrainingOnline;UsrId:32cdc62b1cdb4307888c6ad2fd53b996;trnId:9f0ee4743e7f40c085247c14eb5eeae9;,
Class:TrainingOnline;UsrId:7d4d033f68374ee49f12c60620ffe651;trnId:1b0ae6754ccf4733add782f9a11bd0ef;,
Class:TrainingOnline;UsrId:ecfe8652fc9d4177bf782701d764f19d;trnId:26b9d13727694fc69d3fb31a6a8d3e0b;,
Class:TrainingOnline;UsrId:7f36ff25369b4e6ba088c235f05b557c;trnId:8b3d8c8c2ab448d585ed7c4909292948;,
Class:TrainingOnline;UsrId:9d2e29e4a765495f99f27f8c703f298b;trnId:4fb1eedb88b14d45aba927492d1c8713;,
Class:TrainingOnline;UsrId:9b8a5fede6b049a0921ba093ba8009a6;trnId:5a7bcfa6c4c24e42b0e43b5c58f70fc1;,
Class:TrainingOnline;UsrId:76069203a18c4ecba40f713b85ac24d9;trnId:cda6b6e1c3fc417bb7e2e27c998a5862;,
Class:TrainingOnline;UsrId:785340fe2d1b4136ad6eb2cb4c85d601;trnId:ec44de45aae64487a93da3b522760d4c;
These keys  use  0.0 % of the total sampled memory ( 7.21  kB)
None of these keys expire
Average last accessed time:  47  minutes,  40  seconds - (Max:  47  minutes,  40  seconds Min: 47  minutes,  40  seconds)
==============================================================================
Found  1  keys containing hashs, like:
yd.mvc.Public.SsoModels.SsoTemp
These keys  use  0.01 % of the total sampled memory ( 28.46  kB)
None of these keys expire
Average last accessed time:  47  minutes,  40  seconds - (Max:  47  minutes,  40  seconds Min: 47  minutes,  40  seconds)
==============================================================================
Found  2  keys containing hashs, like:
yd.Model.Public.OnlineCustomer, yd.Model.Public.UserHasAction
These keys  use  0.02 % of the total sampled memory ( 74.29  kB)
None of these keys expire
Average last accessed time:  24  minutes,  10  seconds - (Max:  47  minutes,  40  seconds Min: 40  seconds)
==============================================================================
Found  1  keys containing hashs, like:
yd.Common.Monitoring.MvcRun
These keys  use  0.13 % of the total sampled memory ( 597.7  kB)
None of these keys expire
Average last accessed time:  10  seconds - (Max:  10  seconds Min: 10  seconds)
==============================================================================
Found  2  keys containing hashs, like:
yd.Util.MethodRun, yd.Util.WcfKeep
These keys  use  0.26 % of the total sampled memory ( 1.21  MB)
None of these keys expire
Average last accessed time:  15  seconds - (Max:  20  seconds Min: 10  seconds)
==============================================================================
Found  13  keys containing hashs, like:
yd.Model.Stu.StudyCourseHistory, yd.Model.Sso.Userlink, yd.Model.Sys.GlobalConfig, yd.Model.Sys.ConfigService, yd.Model.Sys.ServiceType, yd.Model.Sso.Domain,
yd.Model.Stu.TestTotal, yd.Model.Stu.TestRecord, yd.Model.Stu.StudyNote, yd.Model.Sta.StarStudent
These keys  use  3.54 % of the total sampled memory ( 16.42  MB)
None of these keys expire
Average last accessed time:  47  minutes,  40  seconds - (Max:  47  minutes,  40  seconds Min: 47  minutes,  40  seconds)
==============================================================================
Found  7  keys containing hashs, like:
yd.Model.Wot.WorkStandardConfig, yd.Model.Wot.TeacherAttention, yd.Model.Wot.TrainingWork, yd.Model.Wot.WorkStandard, yd.Model.Wot.WorkStudent,
yd.Model.Wot.WorkType, yd.Model.Wot.StudentWork
These keys  use  4.51 % of the total sampled memory ( 20.92  MB)
None of these keys expire
Average last accessed time:  47  minutes,  40  seconds - (Max:  47  minutes,  40  seconds Min: 47  minutes,  40  seconds)
==============================================================================
Found  19  keys containing hashs, like:
yd.Model.Cla.AssessTemplateConfig, yd.Model.Cla.WorkStandard, yd.Model.Cla.NewpaperTemplate, yd.Model.Cla.TeacherWorkDetail, yd.Model.Cla.AssessConfig,
yd.Model.Cla.OnlineDiscuss, yd.Model.Cla.StudentAssess, yd.Model.Cla.GrowArchive, yd.Model.Cla.LearningResource, yd.Model.Cla.StudentFileConfig
These keys  use  11.94 % of the total sampled memory ( 55.43  MB)
None of these keys expire
Average last accessed time:  47  minutes,  40  seconds - (Max:  47  minutes,  40  seconds Min: 47  minutes,  40  seconds)
==============================================================================
Found  28  keys containing hashs, like:
yd.Model.Asm.SysinfoConfigType, yd.Model.Asm.User, yd.Model.Ame.CardUseApply, yd.Model.Asm.BranchExpand, yd.Model.Ame.CardOperate, yd.Model.Ame.CardMoney,
yd.Model.Ame.CardSellerDetail, yd.Model.Asm.FavoritesType, yd.Model.Ame.Card, yd.Model.Ame.CardSeller
These keys  use  12.77 % of the total sampled memory ( 59.32  MB)
None of these keys expire
Average last accessed time:  46  minutes,  5  seconds - (Max:  47  minutes,  40  seconds Min: 3  minutes,  30  seconds)
==============================================================================
Found  22  keys containing hashs, like:
yd.Model.Tra.InvoicePrintDetail, yd.Model.Tra.TrainingYear, yd.Model.Tra.InvoicePrint, yd.Model.Tra.TrainingConfigType, yd.Model.Tra.StudentStudy,
yd.Model.Tra.CourseAndTeacher, yd.Model.Tra.SendProcess, yd.Model.Tra.StudentDredge, yd.Model.Tra.StudentDredgeHistory, yd.Model.Tra.TrainingMenu
These keys  use  15.74 % of the total sampled memory ( 73.09  MB)
None of these keys expire
Average last accessed time:  41  minutes,  36  seconds - (Max:  47  minutes,  40  seconds Min: 5  minutes,  10  seconds)
==============================================================================
Found  157  keys containing hashs, like:
yd.Model.Crm.LibraryType, yd.Model.Wot.StandardConfig, yd.Model.Tra.TrainingTemplate, yd.Model.Ctl.CodingSysinfo, yd.Model.Bbs.UserDynamicReply,
yd.Model.Asm.Contact, yd.Model.Buy.OfflineRecord, yd.Model.Cts.TimingTaskLog, yd.Model.Cla.Assess, yd.Model.Sys.ArgeService
These keys  use  51.09 % of the total sampled memory ( 237.25  MB)
None of these keys expire
Average last accessed time:  43  minutes,  18  seconds - (Max:  47  minutes,  50  seconds Min: 10  seconds)
==============================================================================
Summary
---------------------------------------------------+--------------+-------------------+---------------------------------------------------
Key                                                | Memory Usage | Expiry Proportion | Last Access Time                              
---------------------------------------------------+--------------+-------------------+---------------------------------------------------
yd.Model.Crm.LibraryType                           |  51.09 %       |  0.0 %              |  10  seconds                                    
yd.Model.Tra.InvoicePrintDetail                    |  15.74 %       |  0.0 %              |  5  minutes,  10  seconds                         
yd.Model.Asm.SysinfoConfigType                     |  12.77 %       |  0.0 %              |  3  minutes,  30  seconds                         
yd.Model.Cla.AssessTemplateConfig                  |  11.94 %       |  0.0 %              |  47  minutes,  40  seconds                        
yd.Model.Wot.WorkStandardConfig                    |  4.51 %        |  0.0 %              |  47  minutes,  40  seconds                        
yd.Model.Stu.StudyCourseHistory                    |  3.54 %        |  0.0 %              |  47  minutes,  40  seconds                        
yd.Util.MethodRun                                  |  0.26 %        |  0.0 %              |  10  seconds                                    
yd.Common.Monitoring.MvcRun                        |  0.13 %        |  0.0 %              |  10  seconds                                    
yd.Model.Public.OnlineCustomer                     |  0.02 %        |  0.0 %              |  40  seconds                                    
yd.mvc.Public.SsoModels.SsoTemp                    |  0.01 %        |  0.0 %              |  47  minutes,  40  seconds                        
Class:TrainingOnline;UsrId:c99b93261e5642e4995e313 |  0.0 %         |  0.0 %              |  47  minutes,  40  seconds                        
ShoppingCart_6d7cfd49f68043669f30133dc5d983a9      |  0.0 %         |  0.0 %              |  47  minutes,  40  seconds                        
---------------------------------------------------+--------------+-------------------+---------------------------------------------------


从实际使用的情况上看,当要分析采样的数据较多时,会出现timeout报错信息,目前尚不清楚如何处理!

本文转自斩月博客51CTO博客,原文链接http://blog.51cto.com/ylw6006/1281548如需转载请自行联系原作者


ylw6006

相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore     ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
9月前
|
NoSQL 数据可视化 关系型数据库
推荐几个好用的redis可视化工具
推荐几个好用的redis可视化工具
4141 1
|
1月前
|
JSON NoSQL Java
从Redis到Tair:开源工具的最佳实践
《从Redis到Tair:开源工具的最佳实践》介绍了Redis闭源后Valkey社区的成立及其兼容性测试、性能测试、数据迁移与校验、客户端接入最佳实践,以及Tair的开源模块。内容涵盖Redis闭源背景、阿里云在Valkey社区中的贡献、Tair与Redis的兼容性测试工具(如resp-compatibility)、性能测试工具(如RESP-Benchmark)、数据迁移工具(如Redis Shake)及数据校验工具。此外,还详细介绍了TairHash和TairDoc两个开源模块的应用场景,帮助用户更好地理解和使用这些工具。
|
2月前
|
存储 NoSQL 网络协议
Redis性能攻略:Redis-benchmark工具与实用性能优化技巧
Redis 是一种高性能的内存数据库,广泛应用于各种业务场景。随着业务规模扩大和数据量增长,性能问题逐渐凸显。本文深入探讨 Redis 性能优化方案,包括硬件配置(网络、内存优化)、参数配置(maxmemory、timeout 等)、数据结构选择、过期策略、持久化机制(RDB、AOF)及集群方案(主从复制、哨兵模式、集群模式),帮助提升 Redis 的整体性能表现。
72 0
|
4月前
|
NoSQL 数据可视化 Linux
redis学习四、可视化操作工具链接 centos redis,付费Redis Desktop Manager和免费Another Redis DeskTop Manager下载、安装
本文介绍了Redis的两个可视化管理工具:付费的Redis Desktop Manager和免费的Another Redis DeskTop Manager,包括它们的下载、安装和使用方法,以及在使用Another Redis DeskTop Manager连接Redis时可能遇到的问题和解决方案。
207 1
redis学习四、可视化操作工具链接 centos redis,付费Redis Desktop Manager和免费Another Redis DeskTop Manager下载、安装
|
6月前
|
存储 NoSQL Redis
【Azure Developer】一个复制Redis Key到另一个Redis服务的工具(redis_copy_net8)
【Azure Developer】一个复制Redis Key到另一个Redis服务的工具(redis_copy_net8)
|
6月前
|
NoSQL 数据可视化 Linux
2022 年超详细步骤讲解 CentOS 7 安装Redis 。解决Redis Desktop Manager 图形化工具连接失败解决 ;connection failed处理。开机自启Redis
这篇文章提供了在CentOS 7上安装Redis的详细步骤,包括上传Redis安装包、解压安装、编译、安装、备份配置文件、修改配置以支持后台运行和设置密码、启动Redis服务、使用客户端连接Redis、关闭Redis服务、解决Redis Desktop Manager图形化工具连接失败的问题、设置Redis开机自启动,以及Redis服务的启动和停止命令。
2022 年超详细步骤讲解 CentOS 7 安装Redis 。解决Redis Desktop Manager 图形化工具连接失败解决 ;connection failed处理。开机自启Redis
|
6月前
|
存储 监控 NoSQL
揭秘Redis慢查询:这个工具将彻底改变你的性能优化策略!
【8月更文挑战第8天】在互联网应用中,数据库性能常成瓶颈。Redis作为高速内存数据库亦可能遭遇慢查询问题。本文探讨慢查询成因与解决方法。首先定义慢查询及其影响因素,随后介绍Redis内置的慢查询日志功能,通过配置`slowlog-log-slower-than`与`slowlog-max-len`来监控执行时间过长的命令。利用`SLOWLOG get`命令分析日志,定位性能瓶颈所在。以`LRANGE`命令为例,提出数据结构调整、使用流水线、限制返回元素数量、异步执行及优化内存使用等策略。最终实现Redis性能提升,确保应用流畅运行。性能优化需持续监控、分析与调整。
175 1
|
6月前
|
缓存 NoSQL 网络安全
【Azure Redis 缓存】使用开源工具redis-copy时遇见6379端口无法连接到Redis服务器的问题
【Azure Redis 缓存】使用开源工具redis-copy时遇见6379端口无法连接到Redis服务器的问题
|
6月前
|
NoSQL 数据可视化 Linux
一文教会你如何在Linux系统中使用Docker安装Redis 、以及如何使用可视化工具连接【详细过程+图解】
这篇文章详细介绍了如何在Linux系统中使用Docker安装Redis,并提供了使用可视化工具连接Redis的步骤。内容包括安装Redis镜像、创建外部配置文件、映射文件和端口、启动和测试Redis实例、配置数据持久化存储,以及使用可视化工具连接和操作Redis数据库的过程。
|
7月前
|
存储 NoSQL Redis
【Azure Developer】一个复制Redis Key到另一个Redis服务的工具(redis_copy_net8)
介绍一个简单的工具,用于将Redis数据从一个redis端点复制到另一个redis端点,基于原始存储库转换为.NET 8:https://github.com/LuBu0505/redis-copy-net8