diff --git a/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/PrometheusApi.java b/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/PrometheusApi.java deleted file mode 100644 index f43136199..000000000 --- a/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/PrometheusApi.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.monitor.api; - -import cn.stylefeng.roses.kernel.monitor.api.pojo.prometheus.PromResultInfo; - -import java.util.List; - -/** - * 监控管理prometheus - * - * @author chenli - * @date 2021/1/10 16:09 - */ -public interface PrometheusApi { - - /** - * prometheus采集监控指标 - * - * @param promURL prometheus地址 - * @param promQL prometheus查询表达式 - * @param isRate prometheus是否需要计算周期内数值函数 - * @param promQL prometheus需要计算的指标 - * @return Map 指标名称与指标数据的集合 - * @author chenli - * @date 2021/1/10 17:37 - */ - List getMetricInfo(String promURL, String promQL, String isRate, String rateMetric); - - /** - * 配置prometheus无效链接则关闭prometheus相关菜单 - * - * @author chenli - * @date 2021/3/3 16:08 - */ - void closePrometheusMenu(); - - /** - * 配置prometheus有效链接无效则显示prometheus相关菜单 - * - * @author chenli - * @date 2021/3/3 16:08 - */ - void displayPrometheusMenu(); - -} diff --git a/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/constants/MonitorConstants.java b/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/constants/MonitorConstants.java index cf7400c70..753b70174 100644 --- a/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/constants/MonitorConstants.java +++ b/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/constants/MonitorConstants.java @@ -37,34 +37,4 @@ public interface MonitorConstants { */ String MONITOR_MODULE_NAME = "kernel-o-monitor"; - /** - * 异常枚举的步进值 - */ - String MONITOR_EXCEPTION_STEP_CODE = "27"; - - /** - * prometheus查询命令 - */ - String MONITOR_PROMETHEUS_QUERY = "query"; - - /** - * prometheus查询开始时间 - */ - String MONITOR_PROMETHEUS_START = "start"; - - /** - * prometheus查询结束时间 - */ - String MONITOR_PROMETHEUS_END = "end"; - - /** - * prometheus查询步长 - */ - String MONITOR_PROMETHEUS_STEP = "step"; - - /** - * prometheus查询区间向量命令 - */ - String PROMETHEUS_QUERY_RANGE = "query_range"; - } diff --git a/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/pojo/prometheus/PromDataInfo.java b/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/pojo/prometheus/PromDataInfo.java deleted file mode 100644 index 64ff92641..000000000 --- a/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/pojo/prometheus/PromDataInfo.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.monitor.api.pojo.prometheus; - -import lombok.Data; - -import java.util.List; - -/** - * prometheus查询返回结果信息 - * - * @author chenli - * @date 2021/1/10 19:10 - */ -@Data -public class PromDataInfo { - - /** - * prometheus结果类型: - *

- * vector -- 瞬时向量 - * matrix -- 区间向量 - * scalar -- 标量 - * string -- 字符串 - */ - private String resultType; - - /** - * prometheus指标属性和值 - */ - private List result; - -} diff --git a/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/pojo/prometheus/PromMetricInfo.java b/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/pojo/prometheus/PromMetricInfo.java deleted file mode 100644 index 7c9a129ec..000000000 --- a/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/pojo/prometheus/PromMetricInfo.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.monitor.api.pojo.prometheus; - -import lombok.Data; - -/** - * prometheus返回监控指标信息 - * - * @author chenli - * @date 2021/1/10 18:53 - */ -@Data -public class PromMetricInfo { - - /** - * prometheus监控指标id - */ - private String id; - - /** - * prometheus监控指标名称 - */ - private String __name__; - - /** - * prometheus实例名称 - */ - private String instance; - - /** - * prometheus任务名称 - */ - private String job; - - /** - * prometheus jvm区域指标 - */ - private String area; - - /** - * prometheus 日志监控级别 - */ - private String level; - - /** - * prometheus 是否需要计算周期内数据 - */ - private String isRate; - - /** - * prometheus 指定监控指标 - */ - private String rateMetric; -} - diff --git a/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/pojo/prometheus/PromResponseInfo.java b/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/pojo/prometheus/PromResponseInfo.java deleted file mode 100644 index c858a7e39..000000000 --- a/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/pojo/prometheus/PromResponseInfo.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.monitor.api.pojo.prometheus; - -import lombok.Data; - -/** - * prometheus http响应信息 - * - * @author chenli - * @date 2021/1/10 19:00 - */ -@Data -public class PromResponseInfo { - - /** - * 状态: - *

- * 成功-success - */ - private String status; - - /** - * prometheus指标属性和值 - */ - private PromDataInfo data; - -} diff --git a/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/pojo/prometheus/PromResultInfo.java b/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/pojo/prometheus/PromResultInfo.java deleted file mode 100644 index 55c398224..000000000 --- a/kernel-o-monitor/monitor-api/src/main/java/cn/stylefeng/roses/kernel/monitor/api/pojo/prometheus/PromResultInfo.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.monitor.api.pojo.prometheus; - -import lombok.Data; - -/** - * prometheus结果 - * - * @author chenli - * @date 2021/1/10 18:58 - */ -@Data -public class PromResultInfo { - - /** - * prometheus指标属性 - */ - private PromMetricInfo metric; - - /** - * prometheus指标值 - */ - private String[] values; - -} diff --git a/kernel-o-monitor/monitor-integration-beetl/README.md b/kernel-o-monitor/monitor-integration-beetl/README.md deleted file mode 100644 index a48bf3446..000000000 --- a/kernel-o-monitor/monitor-integration-beetl/README.md +++ /dev/null @@ -1 +0,0 @@ -监控模块的集成,针对于beetl模板引擎单体不分离项目 diff --git a/kernel-o-monitor/monitor-integration-beetl/pom.xml b/kernel-o-monitor/monitor-integration-beetl/pom.xml deleted file mode 100644 index 9e8645387..000000000 --- a/kernel-o-monitor/monitor-integration-beetl/pom.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - 4.0.0 - - - cn.stylefeng.roses - kernel-o-monitor - 7.2.2 - ../pom.xml - - - monitor-integration-beetl - - jar - - - - - - cn.stylefeng.roses - monitor-spring-boot-starter - ${roses.version} - - - - - - cn.stylefeng.roses - scanner-api - ${roses.version} - - - - - org.springframework.boot - spring-boot-starter-web - - - - - diff --git a/kernel-o-monitor/monitor-integration-beetl/src/main/java/cn/stylefeng/roses/kernel/monitor/integration/config/PrometheusConfiguration.java b/kernel-o-monitor/monitor-integration-beetl/src/main/java/cn/stylefeng/roses/kernel/monitor/integration/config/PrometheusConfiguration.java deleted file mode 100644 index 7b86db0f6..000000000 --- a/kernel-o-monitor/monitor-integration-beetl/src/main/java/cn/stylefeng/roses/kernel/monitor/integration/config/PrometheusConfiguration.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.monitor.integration.config; - -import cn.stylefeng.roses.kernel.monitor.api.PrometheusApi; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import javax.annotation.Resource; - -/** - * 是否显示prometheus菜单 - * - * @author chenli - * @date 2021/3/3 17:14 - */ -@Configuration -@Slf4j -public class PrometheusConfiguration { - - @Value("${prometheus.enabled}") - private boolean prometheusEnabled; - - @Resource - private PrometheusApi prometheusApi; - - /*** - * 配置是否开启prometheus相关菜单 - * - * @author chenli - * @date 2021/3/3 17:14 - */ - @Bean - public void configPrometheusMenu() { - if (prometheusEnabled) { - prometheusApi.displayPrometheusMenu(); - } else { - prometheusApi.closePrometheusMenu(); - } - } - -} diff --git a/kernel-o-monitor/monitor-integration-beetl/src/main/java/cn/stylefeng/roses/kernel/monitor/integration/controller/PrometheusMonitorController.java b/kernel-o-monitor/monitor-integration-beetl/src/main/java/cn/stylefeng/roses/kernel/monitor/integration/controller/PrometheusMonitorController.java deleted file mode 100644 index 2a91317a8..000000000 --- a/kernel-o-monitor/monitor-integration-beetl/src/main/java/cn/stylefeng/roses/kernel/monitor/integration/controller/PrometheusMonitorController.java +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.monitor.integration.controller; - -import cn.hutool.core.util.StrUtil; -import cn.stylefeng.roses.kernel.monitor.api.PrometheusApi; -import cn.stylefeng.roses.kernel.monitor.api.constants.MonitorConstants; -import cn.stylefeng.roses.kernel.monitor.api.pojo.prometheus.PromResultInfo; -import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource; -import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; - -import javax.annotation.Resource; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * 来自prometheus的监控 - * - * @author chenli - * @date 2020/12/30 16:40 - */ -@Controller -@ApiResource(name = "来自prometheus的监控") -public class PrometheusMonitorController { - - @Value("${spring.application.name}") - private String name; - - @Value("${prometheus.url}") - private String prometheusUrl; - - @Value("${prometheus.instance}") - private String prometheusInstance; - - @Resource - private PrometheusApi service; - - /** - * tomcat监控页面 - * - * @author chenli - * @date 2021/1/4 16:32 - */ - @GetResource(name = "tomcat监控首页", path = "/view/monitor/tomcatInfo") - public String tomcatIndex() { - return "/modular/system/monitor/tomcatInfo.html"; - } - - /** - * tomcat监控数据 - * - * @author chenli - * @date 2021/1/4 16:32 - */ - @GetResource(name = "tomcat监控数据", path = "/view/monitor/getTomcatInfo") - @ResponseBody - public String tomcatInfo() { - Map metricMap = getMetricInfos(getPromQl(), "tomcat_", "", ""); - return JSON.toJSONString(metricMap); - } - - /** - * jvm监控页面 - * - * @author chenli - * @date 2021/1/4 16:32 - */ - @GetResource(name = "jvm监控页面", path = "/view/monitor/jvmInfo") - public String jvmIndex() { - return "/modular/system/monitor/jvmInfo.html"; - } - - /** - * jvm监控数据 - * - * @author chenli - * @date 2021/1/4 16:32 - */ - @GetResource(name = "jvm监控数据", path = "/view/monitor/getJvmInfo") - @ResponseBody - public String jvmInfo(@RequestParam(value = "id",required = false) String id, @RequestParam(value = "area",required = false) String area) { - Map metricMap = getMetricInfos(getPromQl(id, area), "jvm_", "", ""); - return JSON.toJSONString(metricMap); - } - - /** - * 性能监控页面 - * - * @author chenli - * @date 2021/1/4 16:32 - */ - @GetResource(name = "性能监控页面", path = "/view/monitor/performanceInfo") - public String performanceIndex() { - return "/modular/system/monitor/performanceInfo.html"; - } - - /** - * 性能监控数据 - * - * @author chenli - * @date 2021/1/4 16:32 - */ - @GetResource(name = "CPU监控数据", path = "/view/monitor/getCpuInfo") - @ResponseBody - public String cpuInfo() { - Map metricMap = getMetricInfos(getPromQl(), "cpu_", "", ""); - return JSON.toJSONString(metricMap); - } - - /** - * 服务器负载监控数据 - * - * @author chenli - * @date 2021/1/4 16:32 - */ - @GetResource(name = "服务器负载监控数据", path = "/view/monitor/getLoadInfo") - @ResponseBody - public String loadInfo() { - Map metricMap = getMetricInfos(getPromQl(), "system_", "", ""); - return JSON.toJSONString(metricMap); - } - - /** - * 进程监控数据 - * - * @author chenli - * @date 2021/1/4 16:32 - */ - @GetResource(name = "进程监控数据", path = "/view/monitor/getProcessInfo") - @ResponseBody - public String processInfo() { - Map metricMap = getMetricInfos(getPromQl(), "process_", "", ""); - return JSON.toJSONString(metricMap); - } - - /** - * 日志监控页面 - * - * @author chenli - * @date 2021/1/4 16:32 - */ - @GetResource(name = "日志监控页面", path = "/view/monitor/logbackInfo") - public String logbackIndex() { - return "/modular/system/monitor/logbackInfo.html"; - } - - /** - * 日志监控数据 - * - * @author chenli - * @date 2021/1/4 16:32 - */ - @GetResource(name = "日志监控数据", path = "/view/monitor/getLogbackInfo") - @ResponseBody - public String logbackInfo(@RequestParam("level") String level, @RequestParam("timeInterval") String timeInterval, @RequestParam("isRate") String isRate, @RequestParam("rateMetric") String rateMetric) { - if (StrUtil.isEmpty(timeInterval)) { - timeInterval = "[5m]"; - } - Map metricMap = getMetricInfos(getIratePromQl(level, timeInterval), "logback_", isRate, rateMetric); - return JSON.toJSONString(metricMap); - } - - /** - * 组装prometheus查询sql - * - * @param id 同一指标不同分类的id号 - * @param area 查询区域jvm常用 - * @author chenli - * @date 2021/1/4 16:32 - */ - private String getPromQl(String id, String area) { - StringBuilder promql = new StringBuilder("{application=\""); - promql.append(name); - if (!StrUtil.isEmpty(id)) { - promql.append("\",id=\""); - promql.append(id); - } - if (!StrUtil.isEmpty(area)) { - promql.append("\",area=\""); - promql.append(area); - } - if (!StrUtil.isEmpty(prometheusInstance)) { - promql.append("\",instance=\""); - promql.append(prometheusInstance); - } - promql.append("\"}"); - return promql.toString(); - } - - /** - * 组装prometheus查询sql方法重写不带参数 - * - * @author chenli - * @date 2021/1/4 16:32 - */ - private String getPromQl() { - StringBuilder promql = new StringBuilder("{application=\""); - promql.append(name); - if (!StrUtil.isEmpty(prometheusInstance)) { - promql.append("\",instance=\""); - promql.append(prometheusInstance); - } - promql.append("\"}"); - return promql.toString(); - } - - /** - * 组装prometheus平均值查询sql方法重写不带参数 - * - * @param level 日志统计查询参数,info、warn、error、trace、debug - * @param timeInterval 统计时间区间单位通常为分钟(m) - * @author chenli - * @date 2021/1/4 16:32 - */ - private String getIratePromQl(String level, String timeInterval) { - StringBuilder promql = new StringBuilder("{application=\""); - promql.append(name); - if (!StrUtil.isEmpty(prometheusInstance)) { - promql.append("\",instance=\""); - promql.append(prometheusInstance); - } - if (!StrUtil.isEmpty(level)) { - promql.append("\",level=\""); - promql.append(level); - } - promql.append("\"}"); - promql.append(timeInterval); - return promql.toString(); - } - - /** - * 分别输出监控名称以及对应的值 - * - * @param promQL prometheus查询sql - * @param metric prometheus指标前缀,比如:"jvm_" - * @param isRate prometheus计算函数,不需要计算周期内值就直接为"",需要计算则写计算函数以及对应的指标 - * @author chenli - * @date 2021/1/4 16:32 - */ - private Map getMetricInfos(String promQL, String metric, String isRate, String rateMetric) { - Map metricMap = new HashMap<>(); - if (!StrUtil.isEmpty(prometheusUrl)) { - List promResultInfos = service.getMetricInfo(prometheusUrl.concat(MonitorConstants.PROMETHEUS_QUERY_RANGE), promQL, isRate, rateMetric); - if (Objects.isNull(promResultInfos)) { - return metricMap; - } - for (PromResultInfo promResultInfo : promResultInfos) { - String metricName = promResultInfo.getMetric().get__name__(); - JSONArray valueArray = JSONArray.parseArray(JSON.toJSONString(promResultInfo.getValues()).replaceAll("\\\\", "").replace("\"", "")); - if (!StrUtil.isEmpty(metricName)) { - if (metricName.contains(metric)) { - // 得到的数据为数组,需要转为json字符串去除双引号再转化为JSONArray,JSONArray是echarts时间序列图需要的数据格式 - metricMap.put(metricName, valueArray); - } - } else { - // 查询指定的指标 - metricMap.put(rateMetric, valueArray); - } - } - } - return metricMap; - } -} diff --git a/kernel-o-monitor/monitor-integration-beetl/src/main/resources/META-INF/spring.factories b/kernel-o-monitor/monitor-integration-beetl/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 3a9994383..000000000 --- a/kernel-o-monitor/monitor-integration-beetl/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - cn.stylefeng.roses.kernel.monitor.integration.config.PrometheusConfiguration diff --git a/kernel-o-monitor/monitor-integration-beetl/src/main/resources/assets/common/js/echartInit.js b/kernel-o-monitor/monitor-integration-beetl/src/main/resources/assets/common/js/echartInit.js deleted file mode 100644 index 6eb5e7e3b..000000000 --- a/kernel-o-monitor/monitor-integration-beetl/src/main/resources/assets/common/js/echartInit.js +++ /dev/null @@ -1,171 +0,0 @@ -function initGraph(params){ - const paramsId = echarts.init(document.getElementById(params.id), myEchartsTheme); - let metricData = params.metric; - const option = { - title: { - text: params.id, - x: 'center' - }, - tooltip: { - trigger: 'axis', - formatter: function (datas){ - let res; - datas.map(function (e,i) { - if (res == undefined){ - let datetime = new Date(e.value[0]*1000); - res = datetime.getUTCFullYear().toString()+'-'+datetime.getUTCMonth().toString()+'-'+datetime.getUTCDate().toString()+' '+datetime.getHours().toString()+':'+ datetime.getMinutes().toString() + ':' + datetime.getSeconds().toString() + '
' - } - if (params.unit === 'MB' && e.value[1]>0){ - res += e.marker +" " + e.seriesName + ' : ' + (e.value[1]/1000/1000).toFixed(2) + params.unit + '
' - } else { - res += e.marker +" " + e.seriesName + ' : ' + e.value[1] + '
' - } - }) - return res; - } - }, - xAxis: { - type: 'time', - axisLabel: { - formatter: function(value,index){ - let datetime = new Date(value*1000) - return datetime.getHours().toString()+':'+ datetime.getMinutes().toString() - } - } - }, - yAxis: { - name: params.unit, - type: 'value', - scale: true, - axisLabel: { - formatter: function(value,index){ - if (params.unit == 'MB' && value>0){ - return value/1000/1000 - } else { - return value - } - } - } - }, - series: [{type : 'line', - smooth: true, - animationDuration: 2000, - animationEasing: 'quadraticOut', - name : params.id, - data: metricData, - areaStyle: { // 折现下是否填充 - color: this.color, - opacity: 0.6 - }, - showSymbol: false}], - }; - paramsId.setOption(option); -} - -// 初始化三个数据指标 -function initMultiGraph(multiParams){ - const multiParamsId = echarts.init(document.getElementById(multiParams.id), myEchartsTheme); - let metricData = multiParams.metric; - const option = { - title: { text: multiParams.title, x: 'center' }, - tooltip: { - trigger: 'axis', - formatter: function (datas){ - let res; - datas.map(function (e,i) { - if (res == undefined){ - let datetime = new Date(e.value[0]*1000); - res = datetime.getUTCFullYear().toString()+'-'+datetime.getUTCMonth().toString()+'-'+datetime.getUTCDate().toString()+' '+datetime.getHours().toString()+':'+ datetime.getMinutes().toString() + ':' + datetime.getSeconds().toString() + '
' - } - if (multiParams.unit === 'MB' && e.value[1]>0){ - res += e.marker +" " + e.seriesName + ' : ' + (e.value[1]/1000/1000).toFixed(2) + multiParams.unit + '
' - } else { - res += e.marker +" " + e.seriesName + ' : ' + e.value[1] + '
' - } - }) - return res; - } - }, - legend: { - top:"8%", - formatter: function (name) { - return name; - } - }, - xAxis: { - type: 'time', - axisLabel: { - formatter: function(value,index){ - let datetime = new Date(value*1000) - return datetime.getHours().toString()+':'+ datetime.getMinutes().toString() - } - } - }, - yAxis: { - name: multiParams.unit, - type: 'value', - scale: true, - axisLabel: { - formatter: function(value,index){ - if (multiParams.unit == 'MB' && value>0){ - return value/1000/1000 - } else { - return value - } - } - } - }, - series: [{type : 'line', - smooth: true, - lineStyle : { - color: '#63BAC9', - width : 2, - type : 'solid', - }, - animationDuration: 2000, - animationEasing: 'quadraticOut', - name: metricData.metric1.name, - data: metricData.metric1.value, - areaStyle: { - color: '#1D292D', - opacity: 0.2 - }, - smoothMonotone: 'x', - showSymbol: false}, - {type : 'line', - smooth: true, - lineStyle : { - color: '#B29943', - width : 2, - type : 'solid', - }, - animationDuration: 2000, - animationEasing: 'quadraticOut', - name: metricData.metric2.name, - data: metricData.metric2.value, - areaStyle: { - color: '#313830', - opacity: 0.2 - }, - smoothMonotone: 'x', - showSymbol: false}, - {type : 'line', - smooth: true, - lineStyle : { - color: '#7CA76D', - width : 2, - type : 'solid', - }, - animationDuration: 2000, - animationEasing: 'quadraticOut', - name: metricData.metric3.name, - data: metricData.metric3.value, - areaStyle: { - color: '#394437', - opacity: 0.2 - }, - smoothMonotone: 'x', - showSymbol: false}] - }; - multiParamsId.setOption(option); -} \ No newline at end of file diff --git a/kernel-o-monitor/monitor-integration-beetl/src/main/resources/pages/modular/system/monitor/jvmInfo.html b/kernel-o-monitor/monitor-integration-beetl/src/main/resources/pages/modular/system/monitor/jvmInfo.html deleted file mode 100644 index b4897d42f..000000000 --- a/kernel-o-monitor/monitor-integration-beetl/src/main/resources/pages/modular/system/monitor/jvmInfo.html +++ /dev/null @@ -1,223 +0,0 @@ - - - - - - - ${constants.getSystemName()} - - - - - -

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -@/* 加入contextPath属性和session超时的配置 */ - - - - - - - - - \ No newline at end of file diff --git a/kernel-o-monitor/monitor-integration-beetl/src/main/resources/pages/modular/system/monitor/logbackInfo.html b/kernel-o-monitor/monitor-integration-beetl/src/main/resources/pages/modular/system/monitor/logbackInfo.html deleted file mode 100644 index 209a3dd29..000000000 --- a/kernel-o-monitor/monitor-integration-beetl/src/main/resources/pages/modular/system/monitor/logbackInfo.html +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - ${constants.getSystemName()} - - - - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -@/* 加入contextPath属性和session超时的配置 */ - - - - - - - - - \ No newline at end of file diff --git a/kernel-o-monitor/monitor-integration-beetl/src/main/resources/pages/modular/system/monitor/performanceInfo.html b/kernel-o-monitor/monitor-integration-beetl/src/main/resources/pages/modular/system/monitor/performanceInfo.html deleted file mode 100644 index 8bf2fe826..000000000 --- a/kernel-o-monitor/monitor-integration-beetl/src/main/resources/pages/modular/system/monitor/performanceInfo.html +++ /dev/null @@ -1,134 +0,0 @@ - - - - - - - ${constants.getSystemName()} - - - - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -@/* 加入contextPath属性和session超时的配置 */ - - - - - - - - - \ No newline at end of file diff --git a/kernel-o-monitor/monitor-integration-beetl/src/main/resources/pages/modular/system/monitor/tomcatInfo.html b/kernel-o-monitor/monitor-integration-beetl/src/main/resources/pages/modular/system/monitor/tomcatInfo.html deleted file mode 100644 index b45d0cc25..000000000 --- a/kernel-o-monitor/monitor-integration-beetl/src/main/resources/pages/modular/system/monitor/tomcatInfo.html +++ /dev/null @@ -1,187 +0,0 @@ - - - - - - - ${constants.getSystemName()} - - - - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- - @/* 加入contextPath属性和session超时的配置 */ - - - - - - - - - \ No newline at end of file diff --git a/kernel-o-monitor/monitor-sdk-prometheus/pom.xml b/kernel-o-monitor/monitor-sdk-prometheus/pom.xml deleted file mode 100644 index 1bf00a682..000000000 --- a/kernel-o-monitor/monitor-sdk-prometheus/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - 4.0.0 - - - cn.stylefeng.roses - kernel-o-monitor - 7.2.2 - - - monitor-sdk-prometheus - - - cn.stylefeng.roses - monitor-api - ${roses.version} - compile - - - - - org.springframework.boot - spring-boot-starter-actuator - - - - - io.micrometer - micrometer-registry-prometheus - - - org.springframework - spring-tx - - - - - 8 - 8 - - - \ No newline at end of file diff --git a/kernel-o-monitor/monitor-sdk-prometheus/src/main/java/cn/stylefeng/roses/kernel/monitor/prometheus/mapper/PrometheusMenuMapper.java b/kernel-o-monitor/monitor-sdk-prometheus/src/main/java/cn/stylefeng/roses/kernel/monitor/prometheus/mapper/PrometheusMenuMapper.java deleted file mode 100644 index f1435f208..000000000 --- a/kernel-o-monitor/monitor-sdk-prometheus/src/main/java/cn/stylefeng/roses/kernel/monitor/prometheus/mapper/PrometheusMenuMapper.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.monitor.prometheus.mapper; - - - -/** - * 关闭或者打开prometheus菜单接口 - * - * @author chenli - * @date 2021/3/3 16:12 - */ -public interface PrometheusMenuMapper { - - /*** - * 功能描述: 关闭或者打开prometheus菜单 - * 创建时间: 2021/3/3 16:12 - * @author chenli - */ - /** - * 关闭或者打开prometheus菜单 - * @param statusFlag 1启用2关闭 - * @author chenli - * @date 2021/3/3 16:12 - */ - void displayOrClosePrometheusMenu(int statusFlag); - -} diff --git a/kernel-o-monitor/monitor-sdk-prometheus/src/main/java/cn/stylefeng/roses/kernel/monitor/prometheus/mapper/mapping/PrometheusMenuMapper.xml b/kernel-o-monitor/monitor-sdk-prometheus/src/main/java/cn/stylefeng/roses/kernel/monitor/prometheus/mapper/mapping/PrometheusMenuMapper.xml deleted file mode 100644 index 489f97d44..000000000 --- a/kernel-o-monitor/monitor-sdk-prometheus/src/main/java/cn/stylefeng/roses/kernel/monitor/prometheus/mapper/mapping/PrometheusMenuMapper.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - update sys_menu set status_flag=#{statusFlag} where menu_code in ('monitor_quality','monitor_redis','monitor_tomcat','monitor_jvm','monitor_trace','monitor_disk') - - diff --git a/kernel-o-monitor/monitor-sdk-prometheus/src/main/java/cn/stylefeng/roses/kernel/monitor/prometheus/service/PrometheusService.java b/kernel-o-monitor/monitor-sdk-prometheus/src/main/java/cn/stylefeng/roses/kernel/monitor/prometheus/service/PrometheusService.java deleted file mode 100644 index 7e353ce31..000000000 --- a/kernel-o-monitor/monitor-sdk-prometheus/src/main/java/cn/stylefeng/roses/kernel/monitor/prometheus/service/PrometheusService.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.monitor.prometheus.service; - -import cn.stylefeng.roses.kernel.monitor.api.PrometheusApi; - -/** - * 监控管理prometheus - * - * @author chenli - * @date 2021/1/10 16:09 - */ -public interface PrometheusService extends PrometheusApi { - -} diff --git a/kernel-o-monitor/monitor-sdk-prometheus/src/main/java/cn/stylefeng/roses/kernel/monitor/prometheus/service/impl/PrometheusServiceImpl.java b/kernel-o-monitor/monitor-sdk-prometheus/src/main/java/cn/stylefeng/roses/kernel/monitor/prometheus/service/impl/PrometheusServiceImpl.java deleted file mode 100644 index c2f053b76..000000000 --- a/kernel-o-monitor/monitor-sdk-prometheus/src/main/java/cn/stylefeng/roses/kernel/monitor/prometheus/service/impl/PrometheusServiceImpl.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.monitor.prometheus.service.impl; - -import cn.hutool.core.io.IORuntimeException; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.http.HttpUtil; -import cn.stylefeng.roses.kernel.monitor.api.constants.MonitorConstants; -import cn.stylefeng.roses.kernel.monitor.api.exception.MonitorException; -import cn.stylefeng.roses.kernel.monitor.api.exception.enums.MonitorExceptionEnum; -import cn.stylefeng.roses.kernel.monitor.api.pojo.prometheus.PromResponseInfo; -import cn.stylefeng.roses.kernel.monitor.api.pojo.prometheus.PromResultInfo; -import cn.stylefeng.roses.kernel.monitor.prometheus.mapper.PrometheusMenuMapper; -import cn.stylefeng.roses.kernel.monitor.prometheus.service.PrometheusService; -import cn.stylefeng.roses.kernel.rule.enums.StatusEnum; -import com.alibaba.fastjson.JSON; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * 监控管理prometheus - * - * @author chenli - * @date 2021/1/10 16:09 - */ -@Service -@Slf4j -public class PrometheusServiceImpl implements PrometheusService { - - @Resource - private PrometheusMenuMapper mapper; - - /** - * prometheus采集监控指标 - * - * @author chenli - * @date 2021/1/10 16:09 - */ - @Override - public List getMetricInfo(String promURL, String promQL, String isRate, String rateMetric) { - Map paramMap = new HashMap<>(); - String httpRes = ""; - // prometheus查询命令 - if(!StrUtil.isEmpty(isRate)){ - paramMap.put(MonitorConstants.MONITOR_PROMETHEUS_QUERY, getRatePromQl(isRate,rateMetric,promQL)); - } else { - paramMap.put(MonitorConstants.MONITOR_PROMETHEUS_QUERY, promQL); - } - - // 查询5分钟数据 - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) - 5); - - // 查询开始时间 - paramMap.put(MonitorConstants.MONITOR_PROMETHEUS_START, (calendar.getTime().getTime()) / 1000L); - - // 查询结束时间 - paramMap.put(MonitorConstants.MONITOR_PROMETHEUS_END, (new Date().getTime()) / 1000L); - - // 查询步长 - paramMap.put(MonitorConstants.MONITOR_PROMETHEUS_STEP, 15); - // 获取查询结果 - try { - httpRes = HttpUtil.get(promURL, paramMap); - } catch (IORuntimeException e) { - log.error(MonitorExceptionEnum.PROMETHEUS_CONFIG_ERROR.getUserTip(),"",""); - //log.error("prometheus配置异常,具体信息为:{}", e.getMessage()); - // log.error(DictExceptionEnum.DICT_CODE_REPEAT.getUserTip(), "", dictCode); -// throw new MonitorException(MonitorExceptionEnum.PROMETHEUS_CONFIG_ERROR); - return null; - } - PromResponseInfo responseInfo = JSON.parseObject(httpRes, PromResponseInfo.class); - if (ObjectUtil.isEmpty(responseInfo)) { - // 监控指标未产生数据 - return null; - } - if (StrUtil.isEmpty(responseInfo.getStatus()) || !"success".equals(responseInfo.getStatus())) { - // prometheus查询失败 - log.error("prometheus配置异常,具体信息为:{}", responseInfo.getStatus()); - return null; - } - return responseInfo.getData().getResult(); - } - - /** - * 组装prometheus rate promql - * - * @author chenli - * @date 2021/1/10 16:10 - */ - private String getRatePromQl(String isRate,String rateMetric,String promQl){ - StringBuilder ratePromQlBuilder = new StringBuilder(isRate); - ratePromQlBuilder.append("(").append(rateMetric).append(promQl).append(")"); - return ratePromQlBuilder.toString(); - } - - /** - * 配置prometheus无效链接则关闭prometheus相关菜单 - * - * @author chenli - * @date 2021/3/3 16:08 - */ - @Override - @Transactional(rollbackFor = Exception.class) - public void closePrometheusMenu(){ mapper.displayOrClosePrometheusMenu(StatusEnum.DISABLE.getCode()); - } - - /** - * 配置prometheus有效链接无效则显示prometheus相关菜单 - * - * @author chenli - * @date 2021/3/3 16:08 - */ - @Override - @Transactional(rollbackFor = Exception.class) - public void displayPrometheusMenu(){ - mapper.displayOrClosePrometheusMenu(StatusEnum.ENABLE.getCode()); - } - -}