对比新文件 |
| | |
| | | package com.ruoyi.system.controller.monitor; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.system.domain.vo.CacheListInfoVo; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.redisson.spring.data.connection.RedissonConnectionFactory; |
| | | import org.springframework.data.redis.connection.RedisConnection; |
| | | 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 |
| | | */ |
| | | @RequiredArgsConstructor |
| | | @RestController |
| | | @RequestMapping("/monitor/cache") |
| | | public class CacheController { |
| | | |
| | | private final RedissonConnectionFactory connectionFactory; |
| | | |
| | | /** |
| | | * 鑾峰彇缂撳瓨鐩戞帶鍒楄〃 |
| | | */ |
| | | @SaCheckPermission("monitor:cache:list") |
| | | @GetMapping() |
| | | public R<CacheListInfoVo> getInfo() throws Exception { |
| | | RedisConnection connection = connectionFactory.getConnection(); |
| | | Properties commandStats = connection.commands().info("commandstats"); |
| | | |
| | | 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); |
| | | }); |
| | | } |
| | | |
| | | CacheListInfoVo infoVo = new CacheListInfoVo(); |
| | | infoVo.setInfo(connection.commands().info()); |
| | | infoVo.setDbSize(connection.commands().dbSize()); |
| | | infoVo.setCommandStats(pieList); |
| | | return R.ok(infoVo); |
| | | } |
| | | |
| | | } |