移除监控模块,移入kernel

pull/65/head
fengshuonan 2021-02-19 20:34:26 +08:00
parent eeee86cce9
commit e4c23901c7
14 changed files with 60 additions and 414 deletions

22
pom.xml
View File

@ -24,10 +24,9 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<mysql-connector-java.version>8.0.21</mysql-connector-java.version>
<docker.img.version>latest</docker.img.version>
<oshi.version>3.9.1</oshi.version>
<beetl.version>3.3.1.RELEASE</beetl.version>
<roses.kernel.version>7.0.0</roses.kernel.version>
<docker.img.version>latest</docker.img.version>
</properties>
<dependencies>
@ -39,6 +38,13 @@
<version>${roses.kernel.version}</version>
</dependency>
<!--安全模块-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>security-spring-boot-starter</artifactId>
<version>${roses.kernel.version}</version>
</dependency>
<!--系统配置-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
@ -187,18 +193,6 @@
<artifactId>lombok</artifactId>
</dependency>
<!-- actuator monitor -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- prometheus meter -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -1,29 +0,0 @@
package cn.stylefeng.guns.config;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
*
* @author fengshuonan
* @date 2021/1/21 22:07
*/
@Configuration
public class ActuatorConfiguration {
/**
*
*/
@Value("${spring.application.name}")
private String applicationName;
@Bean
public MeterRegistryCustomizer<MeterRegistry> configurer() {
return (registry) -> registry.config().commonTags("application", applicationName);
}
}

View File

@ -0,0 +1,47 @@
package cn.stylefeng.guns.modular.system.monitor;
import cn.stylefeng.roses.kernel.monitor.system.holder.SystemHardwareInfoHolder;
import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.resource.api.annotation.GetResource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import javax.annotation.Resource;
/**
*
*
* @author chenli
* @date 2020/12/30 16:40
*/
@Controller
@ApiResource(name = "项目监控")
public class MonitorController {
@Resource
private SystemHardwareInfoHolder systemHardwareInfoHolder;
/**
*
*
* @author fengshuonan
* @date 2018/12/24 22:43
*/
@GetResource(name = "服务器监控", path = "/view/monitor/systemInfo")
public String systemInfo(Model model) {
model.addAttribute("server", systemHardwareInfoHolder.getSystemHardwareInfo());
return "/modular/system/monitor/systemInfo.html";
}
/**
* druid sql
*
* @author chenli
* @date 2021/1/4 16:32
*/
@GetResource(name = "SQL监控", path = "/view/monitor/druid")
public String druidInfo() {
return "/modular/system/monitor/druid.html";
}
}

View File

@ -1,123 +0,0 @@
package cn.stylefeng.guns.modular.system.monitor.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.monitor.model.PromResultInfo;
import cn.stylefeng.guns.modular.system.monitor.service.MetricService;
import cn.stylefeng.roses.kernel.monitor.system.holder.SystemHardwareInfoHolder;
import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.resource.api.annotation.GetResource;
import com.alibaba.fastjson.JSON;
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;
/**
*
*
* @author chenli
* @date 2020/12/30 16:40
*/
@Controller
@ApiResource(name = "项目监控")
public class MonitorController {
@Value("${server.port}")
private String port;
@Value("${spring.application.name}")
private String name;
@Value("${prometheus.url}")
private String prometheusUrl;
@Value("${prometheus.instance}")
private String prometheusInstance;
@Resource
private MetricService service;
@Resource
private SystemHardwareInfoHolder systemHardwareInfoHolder;
/**
*
*
* @author fengshuonan
* @date 2018/12/24 22:43
*/
@GetResource(name = "服务器监控", path = "/view/monitor/systemInfo")
public String systemInfo(Model model) {
model.addAttribute("server", systemHardwareInfoHolder.getSystemHardwareInfo());
return "/modular/system/monitor/systemInfo.html";
}
/**
* druid sql
*
* @author chenli
* @date 2021/1/4 16:32
*/
@GetResource(name = "SQL监控", path = "/view/monitor/druid")
public String druidInfo(Model model) {
model.addAttribute("port", port);
return "/modular/system/monitor/druid.html";
}
/**
* tomcat
*
* @author chenli
* @date 2021/1/4 16:32
*/
@GetResource(name = "tomcat监控", path = "/view/monitor/tomcatInfo")
public String tomcatInfo(Model model) {
getMetricInfos("tomcat_", model);
return "/modular/system/monitor/tomcatInfo.html";
}
/**
* jvm
*
* @author chenli
* @date 2021/1/4 16:32
*/
@GetResource(name = "jvm监控", path = "/view/monitor/jvmInfo")
public String jvmInfo(Model model) {
getMetricInfos("jvm_", model);
return "/modular/system/monitor/jvmInfo.html";
}
/**
*
*
* @author chenli
* @date 2021/1/4 16:32
*/
private void getMetricInfos(String metric, Model model) {
String promQL = "";
if (!StrUtil.isEmpty(prometheusInstance)) {
promQL = "{application=\"" + name + "\",instance=\"" + prometheusInstance + "\"}";
} else {
promQL = "{application=\"" + name + "\"}";
}
if (!StrUtil.isEmpty(prometheusUrl)) {
List<PromResultInfo> promResultInfos = service.getMetricInfo(prometheusUrl.concat(ProjectConstants.PROMETHEUS_QUERY_RANGE), promQL);
for (PromResultInfo promResultInfo : promResultInfos) {
String metricName = promResultInfo.getMetric().get__name__();
if (!Objects.isNull(metricName)) {
if (metricName.contains(metric)) {
String metricValues = EscapeUtil.unescape(JSON.toJSONString(promResultInfo.getValues()));
model.addAttribute(metricName, metricValues.replace("\"", ""));
}
}
}
}
}
}

View File

@ -1,31 +0,0 @@
package cn.stylefeng.guns.modular.system.monitor.model;
import lombok.Data;
import java.util.List;
/**
* prometheus
*
* @author chenli
* @date 2021/1/10 19:10
*/
@Data
public class PromDataInfo {
/**
* prometheus:
* <p>
* vector --
* matrix --
* scalar --
* string --
*/
private String resultType;
/**
* prometheus
*/
private List<PromResultInfo> result;
}

View File

@ -1,30 +0,0 @@
package cn.stylefeng.guns.modular.system.monitor.model;
import lombok.Data;
/**
* prometheus
*
* @author chenli
* @date 2021/1/10 18:53
*/
@Data
public class PromMetricInfo {
/**
* prometheus
*/
private String __name__;
/**
* prometheus
*/
private String instance;
/**
* prometheus
*/
private String job;
}

View File

@ -1,26 +0,0 @@
package cn.stylefeng.guns.modular.system.monitor.model;
import lombok.Data;
/**
* prometheus http
*
* @author chenli
* @date 2021/1/10 19:00
*/
@Data
public class PromResponseInfo {
/**
* :
* <p>
* -success
*/
private String status;
/**
* prometheus
*/
private PromDataInfo data;
}

View File

@ -1,24 +0,0 @@
package cn.stylefeng.guns.modular.system.monitor.model;
import lombok.Data;
/**
* prometheus
*
* @author chenli
* @date 2021/1/10 18:58
*/
@Data
public class PromResultInfo {
/**
* prometheus
*/
private PromMetricInfo metric;
/**
* prometheus
*/
private String[] values;
}

View File

@ -1,26 +0,0 @@
package cn.stylefeng.guns.modular.system.monitor.service;
import cn.stylefeng.guns.modular.system.monitor.model.PromResultInfo;
import java.util.List;
/**
* prometheus
*
* @author chenli
* @date 2021/1/10 16:09
*/
public interface MetricService {
/**
* prometheus
*
* @param promURL prometheus
* @param promQL prometheus
* @return Map<String, Object>
* @author chenli
* @date 2021/1/10 17:37
*/
List<PromResultInfo> getMetricInfo(String promURL, String promQL);
}

View File

@ -1,62 +0,0 @@
package cn.stylefeng.guns.modular.system.monitor.service.impl;
import cn.hutool.http.HttpUtil;
import cn.stylefeng.guns.core.consts.ProjectConstants;
import cn.stylefeng.guns.modular.system.monitor.model.PromResponseInfo;
import cn.stylefeng.guns.modular.system.monitor.model.PromResultInfo;
import cn.stylefeng.guns.modular.system.monitor.service.MetricService;
import com.alibaba.excel.util.StringUtils;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* prometheus
*
* @author chenli
* @date 2021/1/10 16:09
*/
@Service
public class MetricServiceImpl implements MetricService {
/**
* prometheus
*
* @author chenli
* @date 2021/1/10 16:09
*/
@Override
public List<PromResultInfo> getMetricInfo(String promURL, String promQL) {
Map<String, Object> paramMap = new HashMap<>();
// prometheus查询命令
paramMap.put(ProjectConstants.PROMETHEUS_QUERY, promQL);
// 查询5分钟数据
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) - 5);
// 查询开始时间
paramMap.put(ProjectConstants.PROMETHEUS_START, (calendar.getTime().getTime()) / 1000L);
// 查询结束时间
paramMap.put(ProjectConstants.PROMETHEUS_END, (new Date().getTime()) / 1000L);
// 查询步长
paramMap.put(ProjectConstants.PROMETHEUS_STEP, 15);
// 获取查询结果
PromResponseInfo responseInfo = JSON.parseObject(HttpUtil.get(promURL, paramMap), PromResponseInfo.class);
if (StringUtils.isEmpty(responseInfo)) {
// prometheus未开启
return null;
}
if (StringUtils.isEmpty(responseInfo.getStatus()) || !"success".equals(responseInfo.getStatus())) {
// prometheus查询失败
return null;
}
return responseInfo.getData().getResult();
}
}

View File

@ -15,30 +15,9 @@
"type": "java.lang.String",
"description": "Description for sys-log.file-save-path."
},
{
"name": "spring.datasource.max-active",
"type": "java.lang.String",
"description": "Description for spring.datasource.max-active."
},
{
"name": "spring.datasource.max-pool-prepared-statement-per-connection-size",
"type": "java.lang.String",
"description": "Description for spring.datasource.max-pool-prepared-statement-per-connection-size."
},
{
"name": "web-socket.open",
"type": "java.lang.String",
"description": "Description for web-socket.open."
},
{
"name": "prometheus.url",
"type": "java.lang.String",
"description": "Description for prometheus.url."
},
{
"name": "prometheus.instance",
"type": "java.lang.String",
"description": "Description for prometheus.instance."
}
]
}
] }

View File

@ -2,9 +2,9 @@
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://114.215.203.183:3306/guns_beetl_dev?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT&nullCatalogMeansCurrent=true
url: jdbc:mysql://localhost:3306/guns?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT&nullCatalogMeansCurrent=true
username: root
password: sksTykzfZeMFbwJf
password: 123456
# 连接池大小根据实际情况调整
max-active: 100

View File

@ -1,14 +1,10 @@
server:
port: 8088
max-http-header-size: 10240
# Mysql数据库
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/guns_beetl_dev?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT&nullCatalogMeansCurrent=true
url: jdbc:mysql://localhost:3306/guns?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT&nullCatalogMeansCurrent=true
username: root
password: sksTykzfZeMFbwJf
password: 123456
# 连接池大小根据实际情况调整
max-active: 100

View File

@ -50,25 +50,6 @@ mybatis-plus:
id-type: assign_id
table-underline: true
# prometheus监控
management:
endpoints:
web:
exposure:
include: "*"
metrics:
tags:
application: ${spring.application.name}
export:
prometheus:
enabled: true
jmx:
enabled: true
prometheus:
url: http://localhost:9090/api/v1/
# 非必须配置项
instance:
# 是否开启websocket推送消息
web-socket:
open: true