ccf05c912980c51ab9c6f58ac6a345f9d1e51253.svn-base 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package cn.com.goldenwater.dcproj.controller.monitor;
  2. import cn.com.goldenwater.dcproj.model.AjaxResult;
  3. import cn.com.goldenwater.dcproj.utils.StringUtils;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.data.redis.connection.RedisServerCommands;
  6. import org.springframework.data.redis.core.RedisCallback;
  7. import org.springframework.data.redis.core.RedisTemplate;
  8. import org.springframework.web.bind.annotation.GetMapping;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RestController;
  11. import java.util.*;
  12. /**
  13. * 缓存监控
  14. *
  15. * @author ruoyi
  16. */
  17. @RestController
  18. @RequestMapping("/monitor/cache")
  19. public class CacheController {
  20. @Autowired
  21. private RedisTemplate<String, String> redisTemplate;
  22. @GetMapping()
  23. public AjaxResult getInfo() throws Exception {
  24. Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) RedisServerCommands::info);
  25. Properties commandStats = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info("commandstats"));
  26. Object dbSize = redisTemplate.execute((RedisCallback<Object>) RedisServerCommands::dbSize);
  27. Map<String, Object> result = new HashMap<>(3);
  28. result.put("info", info);
  29. result.put("dbSize", dbSize);
  30. List<Map<String, String>> pieList = new ArrayList<>();
  31. commandStats.stringPropertyNames().forEach(key -> {
  32. Map<String, String> data = new HashMap<>(2);
  33. String property = commandStats.getProperty(key);
  34. data.put("name", StringUtils.removeStart(key, "cmdstat_"));
  35. data.put("value", StringUtils.substringBetween(property, "calls=", ",usec"));
  36. pieList.add(data);
  37. });
  38. result.put("commandStats", pieList);
  39. return AjaxResult.success(result);
  40. }
  41. }