You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

MonitorController.java 2.0 kB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package com.educoder.bridge.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.educoder.bridge.service.K8sService;
  4. import io.fabric8.kubernetes.client.KubernetesClient;
  5. import io.swagger.annotations.Api;
  6. import io.swagger.annotations.ApiOperation;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.http.MediaType;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.slf4j.Logger;
  11. import org.slf4j.LoggerFactory;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import java.util.List;
  14. /**
  15. * Created by liqiankun on 2017/11/16 0016
  16. * Description:
  17. */
  18. @Api(value = "资源监控", hidden = true)
  19. @RestController
  20. @RequestMapping("/monitor")
  21. public class MonitorController {
  22. Logger logger = LoggerFactory.getLogger(MonitorController.class);
  23. @Autowired
  24. private K8sService k8sService;
  25. /**
  26. * 简单地获取集群中的Pod总量及各个节点上的Pod分布
  27. *
  28. * @return
  29. * @throws Exception
  30. */
  31. @RequestMapping(path = "/getPodsInfo")
  32. @ApiOperation(value = "获取集群中某个节点的信息", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
  33. public JSONObject podsInfo() throws Exception {
  34. int podSum = k8sService.getPodSum();
  35. List<String> nodeIP = k8sService.getNodesIP();
  36. //生成Json格式的返回结果
  37. StringBuffer jsonResult = new StringBuffer("[");
  38. for (String ip : nodeIP) {
  39. int num = k8sService.getPodNum(ip);
  40. jsonResult.append("{\"ip\":" + "\"" + ip + "\"," + "\"num\":" + "\"" + num + "\"},");
  41. }
  42. int length = jsonResult.length() - 1;
  43. jsonResult.deleteCharAt(length);
  44. jsonResult.append("]");
  45. JSONObject response = new JSONObject();
  46. response.put("sum", podSum);
  47. response.put("distr", jsonResult);
  48. response.put("code", 0);
  49. return response;
  50. }
  51. }

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...