4dba60c9ff675dc68e335c2439ec7ab392b869bd.svn-base 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package org.jeecg.modules.monitor.controller;
  2. import com.alibaba.fastjson.JSONArray;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.jeecg.common.api.vo.Result;
  5. import org.jeecg.modules.monitor.domain.RedisInfo;
  6. import org.jeecg.modules.monitor.service.RedisService;
  7. import org.springframework.beans.factory.annotation.Autowired;
  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 javax.servlet.http.HttpServletRequest;
  12. import javax.servlet.http.HttpServletResponse;
  13. import javax.swing.filechooser.FileSystemView;
  14. import java.io.File;
  15. import java.util.ArrayList;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. @Slf4j
  20. @RestController
  21. @RequestMapping("/sys/actuator/redis")
  22. public class ActuatorRedisController {
  23. @Autowired
  24. private RedisService redisService;
  25. /**
  26. * Redis详细信息
  27. * @return
  28. * @throws Exception
  29. */
  30. @GetMapping("/info")
  31. public Result<?> getRedisInfo() throws Exception {
  32. List<RedisInfo> infoList = this.redisService.getRedisInfo();
  33. log.info(infoList.toString());
  34. return Result.ok(infoList);
  35. }
  36. @GetMapping("/keysSize")
  37. public Map<String, Object> getKeysSize() throws Exception {
  38. return redisService.getKeysSize();
  39. }
  40. /**
  41. * 获取redis key数量 for 报表
  42. * @return
  43. * @throws Exception
  44. */
  45. @GetMapping("/keysSizeForReport")
  46. public Map<String, JSONArray> getKeysSizeReport() throws Exception {
  47. return redisService.getMapForReport("1");
  48. }
  49. /**
  50. * 获取redis 内存 for 报表
  51. *
  52. * @return
  53. * @throws Exception
  54. */
  55. @GetMapping("/memoryForReport")
  56. public Map<String, JSONArray> memoryForReport() throws Exception {
  57. return redisService.getMapForReport("2");
  58. }
  59. /**
  60. * 获取redis 全部信息 for 报表
  61. * @return
  62. * @throws Exception
  63. */
  64. @GetMapping("/infoForReport")
  65. public Map<String, JSONArray> infoForReport() throws Exception {
  66. return redisService.getMapForReport("3");
  67. }
  68. @GetMapping("/memoryInfo")
  69. public Map<String, Object> getMemoryInfo() throws Exception {
  70. return redisService.getMemoryInfo();
  71. }
  72. //update-begin--Author:zhangweijian Date:20190425 for:获取磁盘信息
  73. /**
  74. * @功能:获取磁盘信息
  75. * @param request
  76. * @param response
  77. * @return
  78. */
  79. @GetMapping("/queryDiskInfo")
  80. public Result<List<Map<String,Object>>> queryDiskInfo(HttpServletRequest request, HttpServletResponse response){
  81. Result<List<Map<String,Object>>> res = new Result<>();
  82. try {
  83. // 当前文件系统类
  84. FileSystemView fsv = FileSystemView.getFileSystemView();
  85. // 列出所有windows 磁盘
  86. File[] fs = File.listRoots();
  87. log.info("查询磁盘信息:"+fs.length+"个");
  88. List<Map<String,Object>> list = new ArrayList<>();
  89. for (int i = 0; i < fs.length; i++) {
  90. if(fs[i].getTotalSpace()==0) {
  91. continue;
  92. }
  93. Map<String,Object> map = new HashMap<>();
  94. map.put("name", fsv.getSystemDisplayName(fs[i]));
  95. map.put("max", fs[i].getTotalSpace());
  96. map.put("rest", fs[i].getFreeSpace());
  97. map.put("restPPT", (fs[i].getTotalSpace()-fs[i].getFreeSpace())*100/fs[i].getTotalSpace());
  98. list.add(map);
  99. log.info(map.toString());
  100. }
  101. res.setResult(list);
  102. res.success("查询成功");
  103. } catch (Exception e) {
  104. res.error500("查询失败"+e.getMessage());
  105. }
  106. return res;
  107. }
  108. //update-end--Author:zhangweijian Date:20190425 for:获取磁盘信息
  109. }