我需要创建一个页面,我可以在其中显示 Redis 缓存内存状态,例如分配了多少内存以及使用了多少内存。有什么方法可以使用 spring boot 获取所有这些信息吗?
最佳答案
是的,这是可能的。我告诉你如何使用 Redis-client: Jedis 来做到这一点
添加后jedis依赖到您的项目中,您可以定义一个 bean,例如:
@Bean
public JedisConnectionFactory connectionFactory() {
return new JedisConnectionFactory();
//in-case if you have a cluster
//return new JedisConnectionFactory(new RedisClusterConfiguration(Arrays.asList("127.0.0.1:6379,127.0.0.1:6369".split(","))));
}
现在您可以像这样使用它:
class DummyClass{
@Autowired
JedisConnectionFactory factory;
void printServerInfo(){
Properties info = factory.getConnection().info()
System.out.println(info)
}
}
这是一个非常基本的示例,说明如何在 spring-boot 中使用 jedis 获取服务器信息。 这是一个示例输出,包含的信息:希望能满足您关于服务器的所有信息。
[
uptime_in_seconds:6,
maxmemory_human:0 B,
aof_last_cow_size:0,
master_replid2:0000000000000000000000000000000000000000,
mem_replication_backlog:0,
aof_rewrite_scheduled:0,
total_net_input_bytes:14,
rss_overhead_ratio:1.36,
hz:10,
redis_build_id:5e26944 cbfa127d5,
aof_last_bgrewrite_status:ok,
multiplexing_api:epoll,
client_recent_max_output_buffer:0,
allocator_resident:3657728,
mem_fragmentation_bytes:4156584,
repl_backlog_first_byte_offset:0,
redis_mode:standalone,
redis_git_dirty:1,
allocator_rss_bytes:2510848,
repl_backlog_histlen:0,
rss_overhead_bytes:1310720,
total_system_memory:16679944192,
loading:0,
evicted_keys:0,
cluster_enabled:0,
redis_version:5.0 .3,
repl_backlog_active:0,
mem_aof_buffer:0,
allocator_frag_bytes:160352,
instantaneous_ops_per_sec:0,
used_memory_human:834.11 K,
role:master,
maxmemory:0,
used_memory_lua:37888,
rdb_current_bgsave_time_sec:-1,
used_memory_startup:790976,
lazyfree_pending_objects:0,
used_memory_dataset_perc:21.31 %,
allocator_frag_ratio:1.16,
arch_bits:64,
mem_clients_normal:49694,
expired_time_cap_reached_count:0,
mem_fragmentation_ratio:6.12,
aof_last_rewrite_time_sec:-1,
master_replid:95 dcc7b8b38c04621f8cbc089ce6e13c82d3ca58,
aof_rewrite_in_progress:0,
config_file:,
lru_clock:1356079,
maxmemory_policy:noeviction,
run_id:8 bfe7f1cebd97ff0dfb98436e76084db6c781010,
latest_fork_usec:0,
total_commands_processed:0,
expired_keys:0,
used_memory:854128,
mem_clients_slaves:0,
keyspace_misses:0,
executable:/redis-server,
used_memory_peak_human:834.11 K,
keyspace_hits:0,
rdb_last_cow_size:0,
used_memory_overhead:840670,
active_defrag_hits:0,
tcp_port:6379,
uptime_in_days:0,
used_memory_peak_perc:105.21 %,
blocked_clients:0,
sync_partial_err:0,
used_memory_scripts_human:0 B,
aof_current_rewrite_time_sec:-1,
aof_enabled:0,
master_repl_offset:0,
used_memory_dataset:13458,
used_cpu_user:0.011536,
rdb_last_bgsave_status:ok,
atomicvar_api:atomic-builtin,
allocator_rss_ratio:3.19,
client_recent_max_input_buffer:4,
aof_last_write_status:ok,
mem_allocator:jemalloc-5.1.0,
used_memory_scripts:0,
used_memory_peak:854128,
process_id:9682,
used_cpu_sys:0.007885,
repl_backlog_size:1048576,
connected_slaves:0,
gcc_version:7.3 .0,
total_system_memory_human:15.53 G,
sync_full:0,
connected_clients:1,
allocator_active:1146880,
total_net_output_bytes:0,
pubsub_channels:0,
active_defrag_key_hits:0,
rdb_changes_since_last_save:0,
instantaneous_input_kbps:0.00,
configured_hz:10,
used_memory_rss_human:4.74 M,
expired_stale_perc:0.00,
active_defrag_misses:0,
used_cpu_sys_children:0.000000,
number_of_cached_scripts:0,
sync_partial_ok:0,
used_memory_lua_human:37.00 K,
rdb_last_save_time:1561637161,
pubsub_patterns:0,
slave_expires_tracked_keys:0,
redis_git_sha1:9101 cbde,
used_memory_rss:4968448,
rdb_last_bgsave_time_sec:-1,
os:Linux 4.15.0-52-generic x86_64,
mem_not_counted_for_evict:0,
active_defrag_running:0,
rejected_connections:0,
active_defrag_key_misses:0,
allocator_allocated:986528,
instantaneous_output_kbps:0.00,
second_repl_offset:-1,
rdb_bgsave_in_progress:0,
used_cpu_user_children:0.000000,
total_connections_received:1,
migrate_cached_sockets:0
]
关于spring - Redis缓存内存状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56784239/
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
我正在使用Ruby2.1.1和Rails4.1.0.rc1。当执行railsc时,它被锁定了。使用Ctrl-C停止,我得到以下错误日志:~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.2/lib/spring/client/run.rb:47:in`gets':Interruptfrom~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.2/lib/spring/client/run.rb:47:in`verify_server_version'from~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.
当我的预订模型通过rake任务在状态机上转换时,我试图找出如何跳过对ActiveRecord对象的特定实例的验证。我想在reservation.close时跳过所有验证!叫做。希望调用reservation.close!(:validate=>false)之类的东西。仅供引用,我们正在使用https://github.com/pluginaweek/state_machine用于状态机。这是我的预订模型的示例。classReservation["requested","negotiating","approved"])}state_machine:initial=>'requested
ruby如何管理内存。例如:如果我们在执行过程中采用C程序,则以下是内存模型。类似于这个ruby如何处理内存。C:__________________|||stack|||------------------||||------------------|||||Heap|||||__________________|||data|__________________|text|__________________Ruby:? 最佳答案 Ruby中没有“内存”这样的东西。Class#allocate分配一个对象并返回该对象。这就是程序
我试过重新启动apache,缓存的页面仍然出现,所以一定有一个文件夹在某个地方。我没有“公共(public)/缓存”,那么我还应该查看哪些其他地方?是否有一个URL标志也可以触发此效果? 最佳答案 您需要触摸一个文件才能清除phusion,例如:touch/webapps/mycook/tmp/restart.txt参见docs 关于ruby-如何在Ubuntu中清除RubyPhusionPassenger的缓存?,我们在StackOverflow上找到一个类似的问题:
尝试在我的RoR应用程序中实现计数器缓存列时出现错误Unknownkey(s):counter_cache。我在这个问题中实现了模型关联:Modelassociationquestion这是我的迁移:classAddVideoVotesCountToVideos0Video.reset_column_informationVideo.find(:all).eachdo|p|p.update_attributes:videos_votes_count,p.video_votes.lengthendenddefself.downremove_column:videos,:video_vot
对于作为String#tr参数的单引号字符串文字中反斜杠的转义状态,我觉得有些神秘。你能解释一下下面三个例子之间的对比吗?我特别不明白第二个。为了避免复杂化,我在这里使用了'd',在双引号中转义时不会改变含义("\d"="d")。'\\'.tr('\\','x')#=>"x"'\\'.tr('\\d','x')#=>"\\"'\\'.tr('\\\d','x')#=>"x" 最佳答案 在tr中转义tr的第一个参数非常类似于正则表达式中的括号字符分组。您可以在表达式的开头使用^来否定匹配(替换任何不匹配的内容)并使用例如a-f来匹配一
我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur
转自:spring.profiles.active和spring.profiles.include的使用及区别说明下文笔者讲述spring.profiles.active和spring.profiles.include的区别简介说明,如下所示我们都知道,在日常开发中,开发|测试|生产环境都拥有不同的配置信息如:jdbc地址、ip、端口等此时为了避免每次都修改全部信息,我们则可以采用以上的属性处理此类异常spring.profiles.active属性例:配置文件,可使用以下方式定义application-${profile}.properties开发环境配置文件:application-dev