From 695cb6d76b838b1e4cb161bae335faa948dca12a Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期三, 27 十月 2021 13:16:19 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into satoken --- ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java | 107 ++++++++++++++++++++++++++++------------------------- 1 files changed, 57 insertions(+), 50 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java index b3efd5a..255f0b1 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java @@ -1,50 +1,57 @@ -package com.ruoyi.web.controller.monitor; - -import cn.hutool.core.util.StrUtil; -import com.ruoyi.common.core.domain.AjaxResult; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisCallback; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.*; - -/** - * 缂撳瓨鐩戞帶 - * - * @author ruoyi - */ -@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 - { - Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info()); - Properties commandStats = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info("commandstats")); - 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", StrUtil.removePrefix(key, "cmdstat_")); - data.put("value", StrUtil.subBetween(property, "calls=", ",usec")); - pieList.add(data); - }); - result.put("commandStats", pieList); - return AjaxResult.success(result); - } -} +package com.ruoyi.web.controller.monitor; + +import cn.dev33.satoken.annotation.SaCheckPermission; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.utils.StringUtils; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.connection.RedisServerCommands; +import org.springframework.data.redis.core.RedisCallback; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.*; + +/** + * 缂撳瓨鐩戞帶 + * + * @author Lion Li + */ +@Api(value = "缂撳瓨鐩戞帶", tags = {"缂撳瓨鐩戞帶绠$悊"}) +@RequiredArgsConstructor(onConstructor_ = @Autowired) +@RestController +@RequestMapping("/monitor/cache") +public class CacheController { + + private final RedisTemplate<String, String> redisTemplate; + + @ApiOperation("鑾峰彇缂撳瓨鐩戞帶璇︾粏淇℃伅") + @SaCheckPermission("monitor:cache:list") + @GetMapping() + public AjaxResult<Map<String, Object>> getInfo() throws Exception { + Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) RedisServerCommands::info); + Properties commandStats = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info("commandstats")); + Object dbSize = redisTemplate.execute((RedisCallback<Object>) RedisServerCommands::dbSize); + + Map<String, Object> result = new HashMap<>(3); + result.put("info", info); + result.put("dbSize", dbSize); + + List<Map<String, String>> pieList = new ArrayList<>(); + if (commandStats != null) { + 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); + } +} -- Gitblit v1.9.3