mirror of https://gitee.com/stylefeng/guns
移除监控模块,移入kernel
parent
eeee86cce9
commit
e4c23901c7
22
pom.xml
22
pom.xml
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
|
||||
}
|
|
@ -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("\"", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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."
|
||||
}
|
||||
]
|
||||
}
|
||||
] }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue