zoukankan      html  css  js  c++  java
  • SpringBoot整合RedisTemplate实现缓存信息监控

    1、CacheController接口代码

    @RestController
    @RequestMapping("/monitor/cache")
    public class CacheController
    {
        @Autowired
        private RedisTemplate<String, String> redisTemplate;
    
        @PreAuthorize("@ss.hasPermi('monitor:cache:list')")// 自定义权限注解
        @GetMapping()
        public AjaxResult getInfo() throws Exception
        {
            // 获取redis缓存完整信息
            //Properties info = redisTemplate.getRequiredConnectionFactory().getConnection().info();
            Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info());
    
            // 获取redis缓存命令统计信息
            //Properties commandStats = redisTemplate.getRequiredConnectionFactory().getConnection().info("commandstats");
            Properties commandStats = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info("commandstats"));
    
            // 获取redis缓存中可用键Key的总数
            //Long dbSize = redisTemplate.getRequiredConnectionFactory().getConnection().dbSize();
            Object dbSize = redisTemplate.execute((RedisCallback<Object>) connection -> connection.dbSize());
    
            Map<String, Object> result = new HashMap<>(3);
            result.put("info", info);
            result.put("dbSize", dbSize);
    
            List<Map<String, String>> pieList = new ArrayList<>();
            commandStats.stringPropertyNames().forEach(key -> {
                Map<String, String> data = new HashMap<>(2);
                String property = commandStats.getProperty(key);
                data.put("name", StringUtils.removeStart(key, "cmdstat_"));
                data.put("value", StringUtils.substringBetween(property, "calls=", ",usec"));
                pieList.add(data);
            });
            result.put("commandStats", pieList);
    
            return AjaxResult.success(result);
        }
    }
    

      

    没有停止的脚步,只有倒下去的脚步
  • 相关阅读:
    十天学会php之第一天
    学习PHP的一些经验
    PHP中的数据类型(1)
    PHP中的常量
    赵凡导师并发知识第一次分享观后感
    面向对象之 __setitem__()、__getitem__()、__delitem__() 用法
    spider数据抓取(第二章)
    识别网站所用技术
    scrapy安装要求
    基于bs4的防止xss攻击,过滤script标签
  • 原文地址:https://www.cnblogs.com/hkMblogs/p/15059454.html
Copyright © 2011-2022 走看看