|
|
|
@ -1,21 +1,19 @@
|
|
|
|
|
package cn.stylefeng.guns.modular.system.controller;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.EscapeUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.stylefeng.guns.core.consts.ProjectConstants;
|
|
|
|
|
import cn.stylefeng.guns.modular.system.model.PromResultInfo;
|
|
|
|
|
import cn.stylefeng.guns.modular.system.service.MetricService;
|
|
|
|
|
import cn.stylefeng.guns.modular.system.warpper.SystemHardwareWarpper;
|
|
|
|
|
import cn.stylefeng.guns.modular.system.warpper.SystemHardwareWrapper;
|
|
|
|
|
import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource;
|
|
|
|
|
import cn.stylefeng.roses.kernel.resource.api.annotation.GetResource;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.StringEscapeUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.ui.Model;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
@ -23,15 +21,12 @@ import java.util.Objects;
|
|
|
|
|
* 项目监控
|
|
|
|
|
*
|
|
|
|
|
* @author chenli
|
|
|
|
|
* @Date 2020/12/30 16:40
|
|
|
|
|
* @date 2020/12/30 16:40
|
|
|
|
|
*/
|
|
|
|
|
@Controller
|
|
|
|
|
@Slf4j
|
|
|
|
|
@ApiResource(name = "项目监控")
|
|
|
|
|
public class MonitorController {
|
|
|
|
|
|
|
|
|
|
private String PREFIX = "/modular/frame";
|
|
|
|
|
|
|
|
|
|
@Value("${server.port}")
|
|
|
|
|
private String port;
|
|
|
|
|
|
|
|
|
@ -44,83 +39,84 @@ public class MonitorController {
|
|
|
|
|
@Value("${prometheus.instance}")
|
|
|
|
|
private String prometheusInstance;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
@Resource
|
|
|
|
|
private MetricService service;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 系统硬件信息页面
|
|
|
|
|
*
|
|
|
|
|
* @author fengshuonan
|
|
|
|
|
* @Date 2018/12/24 22:43
|
|
|
|
|
* @date 2018/12/24 22:43
|
|
|
|
|
*/
|
|
|
|
|
@GetResource(name = "服务器监控", path = "/monitor/systemInfo")
|
|
|
|
|
@GetResource(name = "服务器监控", path = "/view/monitor/systemInfo")
|
|
|
|
|
public String systemInfo(Model model) {
|
|
|
|
|
SystemHardwareWarpper systemHardwareWarpper = new SystemHardwareWarpper();
|
|
|
|
|
systemHardwareWarpper.copyTo();
|
|
|
|
|
model.addAttribute("server",systemHardwareWarpper);
|
|
|
|
|
return PREFIX+"/systemInfo.html";
|
|
|
|
|
SystemHardwareWrapper systemHardwareWrapper = new SystemHardwareWrapper();
|
|
|
|
|
systemHardwareWrapper.copyTo();
|
|
|
|
|
model.addAttribute("server", systemHardwareWrapper);
|
|
|
|
|
return "/modular/frame/systemInfo.html";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* durid sql监控页面
|
|
|
|
|
* druid sql监控页面
|
|
|
|
|
*
|
|
|
|
|
* @author chenli
|
|
|
|
|
* @Date 2021/1/4 16:32
|
|
|
|
|
* @date 2021/1/4 16:32
|
|
|
|
|
*/
|
|
|
|
|
@GetResource(name = "SQL监控", path = "/monitor/druid")
|
|
|
|
|
public String duridInfo(Model model){
|
|
|
|
|
model.addAttribute("port",port);
|
|
|
|
|
return PREFIX+"/druid.html";
|
|
|
|
|
@GetResource(name = "SQL监控", path = "/view/monitor/druid")
|
|
|
|
|
public String druidInfo(Model model) {
|
|
|
|
|
model.addAttribute("port", port);
|
|
|
|
|
return "/modular/frame/druid.html";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* tomcat监控页面
|
|
|
|
|
*
|
|
|
|
|
* @author chenli
|
|
|
|
|
* @Date 2021/1/4 16:32
|
|
|
|
|
* @date 2021/1/4 16:32
|
|
|
|
|
*/
|
|
|
|
|
@GetResource(name = "tomcat监控", path = "/monitor/tomcatInfo")
|
|
|
|
|
public String tomcatInfo(Model model){
|
|
|
|
|
getMetricInfos("tomcat_",model);
|
|
|
|
|
return PREFIX+"/tomcatInfo.html";
|
|
|
|
|
@GetResource(name = "tomcat监控", path = "/view/monitor/tomcatInfo")
|
|
|
|
|
public String tomcatInfo(Model model) {
|
|
|
|
|
getMetricInfos("tomcat_", model);
|
|
|
|
|
return "/modular/frame/tomcatInfo.html";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* jvm监控
|
|
|
|
|
*
|
|
|
|
|
* @author chenli
|
|
|
|
|
* @Date 2021/1/4 16:32
|
|
|
|
|
* @date 2021/1/4 16:32
|
|
|
|
|
*/
|
|
|
|
|
@GetResource(name = "jvm监控", path = "/monitor/jvmInfo")
|
|
|
|
|
public String jvmInfo(Model model){
|
|
|
|
|
getMetricInfos("jvm_",model);
|
|
|
|
|
return PREFIX+"/jvmInfo.html";
|
|
|
|
|
@GetResource(name = "jvm监控", path = "/view/monitor/jvmInfo")
|
|
|
|
|
public String jvmInfo(Model model) {
|
|
|
|
|
getMetricInfos("jvm_", model);
|
|
|
|
|
return "/modular/frame/jvmInfo.html";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分别输出监控名称以及对应的值
|
|
|
|
|
*
|
|
|
|
|
* @author chenli
|
|
|
|
|
* @Date 2021/1/4 16:32
|
|
|
|
|
* @date 2021/1/4 16:32
|
|
|
|
|
*/
|
|
|
|
|
private void getMetricInfos(String metric,Model model){
|
|
|
|
|
private void getMetricInfos(String metric, Model model) {
|
|
|
|
|
String promQL = "";
|
|
|
|
|
if(!StringUtils.isEmpty(prometheusInstance)){
|
|
|
|
|
promQL = "{application=\""+name+"\",instance=\""+prometheusInstance+"\"}";
|
|
|
|
|
if (!StrUtil.isEmpty(prometheusInstance)) {
|
|
|
|
|
promQL = "{application=\"" + name + "\",instance=\"" + prometheusInstance + "\"}";
|
|
|
|
|
} else {
|
|
|
|
|
promQL = "{application=\""+name+"\"}";
|
|
|
|
|
promQL = "{application=\"" + name + "\"}";
|
|
|
|
|
}
|
|
|
|
|
if(!StringUtils.isEmpty(prometheusUrl)){
|
|
|
|
|
if (!StrUtil.isEmpty(prometheusUrl)) {
|
|
|
|
|
List<PromResultInfo> promResultInfos = service.getMetricInfo(prometheusUrl.concat(ProjectConstants.PROMETHEUS_QUERY_RANGE), promQL);
|
|
|
|
|
for(PromResultInfo promResultInfo : promResultInfos){
|
|
|
|
|
for (PromResultInfo promResultInfo : promResultInfos) {
|
|
|
|
|
String metricName = promResultInfo.getMetric().get__name__();
|
|
|
|
|
if(!Objects.isNull(metricName)){
|
|
|
|
|
if(metricName.contains(metric)){
|
|
|
|
|
String metricValues = StringEscapeUtils.unescapeJava(JSON.toJSONString(promResultInfo.getValues()));
|
|
|
|
|
model.addAttribute(metricName, metricValues.replace("\"",""));
|
|
|
|
|
if (!Objects.isNull(metricName)) {
|
|
|
|
|
if (metricName.contains(metric)) {
|
|
|
|
|
String metricValues = EscapeUtil.unescape(JSON.toJSONString(promResultInfo.getValues()));
|
|
|
|
|
model.addAttribute(metricName, metricValues.replace("\"", ""));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|