wukai 9 сар өмнө
parent
commit
36fe8d7ebd
26 өөрчлөгдсөн 1210 нэмэгдсэн , 410 устгасан
  1. 1 1
      jjt-admin/src/main/resources/application-test.yml
  2. 1 1
      jjt-admin/src/main/resources/application.yml
  3. 128 0
      jjt-admin/src/test/java/com/test/HttpTest.java
  4. 18 13
      jjt-biz/src/main/java/com/jjt/biz/controller/BizObjController.java
  5. 20 34
      jjt-biz/src/main/java/com/jjt/biz/controller/BizObjMetricsController.java
  6. 25 83
      jjt-biz/src/main/java/com/jjt/biz/domain/BizObj.java
  7. 6 1
      jjt-biz/src/main/java/com/jjt/biz/domain/BizObjMetrics.java
  8. 101 0
      jjt-biz/src/main/java/com/jjt/biz/domain/PinpointVO.java
  9. 1 1
      jjt-biz/src/main/java/com/jjt/biz/mapper/BizObjMetricsMapper.java
  10. 7 0
      jjt-biz/src/main/java/com/jjt/biz/service/IBizObjMetricsService.java
  11. 12 3
      jjt-biz/src/main/java/com/jjt/biz/service/IBizObjPpService.java
  12. 7 0
      jjt-biz/src/main/java/com/jjt/biz/service/IBizObjTplService.java
  13. 62 0
      jjt-biz/src/main/java/com/jjt/biz/service/IPinpointService.java
  14. 25 0
      jjt-biz/src/main/java/com/jjt/biz/service/IPrometheusService.java
  15. 155 19
      jjt-biz/src/main/java/com/jjt/biz/service/impl/BizObjMetricsServiceImpl.java
  16. 13 0
      jjt-biz/src/main/java/com/jjt/biz/service/impl/BizObjPpServiceImpl.java
  17. 16 3
      jjt-biz/src/main/java/com/jjt/biz/service/impl/BizObjTplServiceImpl.java
  18. 185 0
      jjt-biz/src/main/java/com/jjt/biz/service/impl/PinpointServiceImpl.java
  19. 39 0
      jjt-biz/src/main/java/com/jjt/biz/service/impl/PrometheusServiceImpl.java
  20. 34 0
      jjt-biz/src/main/java/com/jjt/task/AlarmTask.java
  21. 102 93
      jjt-biz/src/main/resources/mapper/obj/BizObjDataMapper.xml
  22. 135 115
      jjt-biz/src/main/resources/mapper/obj/BizObjMapper.xml
  23. 33 42
      jjt-biz/src/main/resources/mapper/obj/BizObjMetricsMapper.xml
  24. 6 0
      jjt-common/src/main/java/com/jjt/common/constant/CacheConstants.java
  25. 1 1
      jjt-common/src/main/java/com/jjt/common/constant/Constants.java
  26. 77 0
      jjt-common/src/main/java/com/jjt/common/utils/IntervalUtil.java

+ 1 - 1
jjt-admin/src/main/resources/application-test.yml

@@ -54,7 +54,7 @@ spring:
     druid:
       # 主库数据源
       master:
-        url: jdbc:mysql://localhost:33306/jy2024?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+        url: jdbc:mysql://localhost:33306/jy2024?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true
         username: root
         password: 123456
       # 从库数据源

+ 1 - 1
jjt-admin/src/main/resources/application.yml

@@ -54,7 +54,7 @@ spring:
     druid:
       # 主库数据源
       master:
-        url: jdbc:mysql://192.168.188.66:3306/jy2024?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+        url: jdbc:mysql://192.168.188.66:3306/jy2024?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true
         username: root
         password: 123456
       # 从库数据源

+ 128 - 0
jjt-admin/src/test/java/com/test/HttpTest.java

@@ -0,0 +1,128 @@
+package com.test;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.jjt.common.utils.http.HttpUtils;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+
+/**
+ * HttpTest$
+ *
+ * @author wukai
+ * @date 2024/8/19 15:18
+ */
+public class HttpTest {
+    public static void main(String[] args) {
+//        float f=0.0f;
+//        float ff=0.00f;
+//
+//        System.err.println(f==0f);
+////        apps();
+        link();
+//        tps();
+//        jvmGC();
+//        fileDesc();
+//        System.err.println(array);
+    }
+
+    public static void apps() {
+        String uri = "http://192.168.188.66:8080/applications.pinpoint";
+        String result = HttpUtils.sendGet(uri);
+        JSONArray jsonArray = JSONArray.parseArray(result);
+        System.err.println(jsonArray);
+    }
+
+    public static void link() {
+        String name = "doc-gateway";
+        String type = "SPRING_BOOT";
+        LocalDateTime ldt = LocalDateTime.now();
+        long end = ldt.toEpochSecond(ZoneOffset.ofHours(8)) * 1000;
+        long start = ldt.minusMinutes(5).toEpochSecond(ZoneOffset.ofHours(8)) * 1000;
+        //需要除去自身和USER
+        String[] keys = {"key", "applicationName", "category", "responseStatistics.Tot", "responseStatistics.Sum", "responseStatistics.Avg", "responseStatistics.Max", "histogram.1s", "histogram.3s", "histogram.5s", "histogram.Slow", "histogram.Error"};
+        String uri = "http://192.168.188.66:8080/getServerMapDataV2.pinpoint?applicationName=%s&serviceTypeName=%s&from=%s&to=%s&calleeRange=1&callerRange=1&wasOnly=false&bidirectional=false&useStatisticsAgentState=false";
+        uri = String.format(uri, name, type, start, end);
+        System.err.println(uri);
+        String result = HttpUtils.sendGet(uri);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        JSONArray array = jsonObject.getJSONObject("applicationMapData").getJSONArray("nodeDataArray");
+        for (int i = 0; i < array.size(); i++) {
+            JSONObject obj = array.getJSONObject(i);
+            StringBuilder out = new StringBuilder();
+            for (String s : keys) {
+                String[] ss = s.split("\\.");
+                if (ss.length == 2) {
+                    out.append(ss[1]).append(":").append(obj.getJSONObject(ss[0]).getInteger(ss[1])).append("\t");
+                } else {
+                    out.append(s).append(":").append(obj.getString(s)).append("\t");
+                }
+            }
+            System.err.println(out);
+        }
+    }
+
+    /**
+     * "min",
+     * "max",
+     * "avg",
+     * "sum"
+     */
+    public static void tps() {
+        String uri = "http://192.168.188.66:8080/getAgentStat/transaction/chart.pinpoint?agentId=doc-system&from=1724053700000&to=1724054000000&sampleRate=1";
+        String result = HttpUtils.sendGet(uri);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        JSONArray array = jsonObject.getJSONObject("charts").getJSONObject("y").getJSONArray("TPS_TOTAL");
+        for (int i = 0; i < array.size(); i++) {
+            JSONArray arr = array.getJSONArray(i);
+            float v = arr.getFloat(1);
+            if (v != 0f) {
+                System.err.println(v);
+            }
+        }
+    }
+
+    public static void jvmGC() {
+        String uri = "http://192.168.188.66:8080/getAgentStat/jvmGc/chart.pinpoint?agentId=doc-gateway&from=1723963207000&to=1724136007000&sampleRate=1";
+        String result = HttpUtils.sendGet(uri);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        System.err.println(jsonObject);
+        JSONArray heapUsed = jsonObject.getJSONObject("charts").getJSONObject("y").getJSONArray("JVM_MEMORY_HEAP_USED");
+        JSONArray heapMax = jsonObject.getJSONObject("charts").getJSONObject("y").getJSONArray("JVM_MEMORY_HEAP_MAX");
+        JSONArray noHeapUsed = jsonObject.getJSONObject("charts").getJSONObject("y").getJSONArray("JVM_MEMORY_HEAP_MAX");
+        JSONArray noHeapMax = jsonObject.getJSONObject("charts").getJSONObject("y").getJSONArray("JVM_MEMORY_HEAP_MAX");
+        JSONArray gc = jsonObject.getJSONObject("charts").getJSONObject("y").getJSONArray("JVM_GC_OLD_COUNT");
+        Float used = 0F;
+        Float max = 0F;
+        int gcTimes = 0;
+        for (int i = 0; i < heapUsed.size(); i++) {
+            float v = heapUsed.getJSONArray(i).getFloat(1);
+            int gcV = gc.getJSONArray(i).getInteger(1);
+            gcTimes += gcV;
+            if (v != 0f && v > used) {
+                used = v;
+                max = heapMax.getJSONArray(i).getFloat(1);
+            }
+        }
+
+        float usage = BigDecimal.valueOf(used).divide(BigDecimal.valueOf(max), 2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(1000)).floatValue();
+    }
+
+    public static void fileDesc() {
+        String uri = "http://192.168.188.66:8080/getAgentStat/fileDescriptor/chart.pinpoint?agentId=doc-gateway&from=1723963207000&to=1724136007000&sampleRate=1";
+        String result = HttpUtils.sendGet(uri);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        System.err.println(jsonObject);
+        JSONArray array = jsonObject.getJSONObject("charts").getJSONObject("y").getJSONArray("TPS_TOTAL");
+//        for (int i = 0; i < array.size(); i++) {
+//            JSONArray arr = array.getJSONArray(i);
+//            float v = arr.getFloat(2);
+//            if (v != 0f) {
+//                System.err.println(v);
+//            }
+//        }
+    }
+}

+ 18 - 13
jjt-biz/src/main/java/com/jjt/biz/controller/BizObjController.java

@@ -1,8 +1,10 @@
 package com.jjt.biz.controller;
 
 import com.jjt.biz.domain.BizObj;
+import com.jjt.biz.domain.BizObjMetrics;
 import com.jjt.biz.domain.MetricsDef;
 import com.jjt.biz.domain.MetricsTpl;
+import com.jjt.biz.service.IBizObjMetricsService;
 import com.jjt.biz.service.IBizObjPpService;
 import com.jjt.biz.service.IBizObjService;
 import com.jjt.biz.service.IBizObjTplService;
@@ -13,8 +15,6 @@ import com.jjt.common.core.page.TableDataInfo;
 import com.jjt.common.enums.BusinessType;
 import com.jjt.common.utils.SecurityUtils;
 import com.jjt.common.utils.poi.ExcelUtil;
-import com.jjt.biz.domain.BizObjMetrics;
-import com.jjt.biz.service.IBizObjMetricsService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
@@ -48,7 +48,7 @@ public class BizObjController extends BaseController {
 
     @ApiOperation("选择模板")
     @GetMapping("/tpl/select/{objId}")
-    public TableDataInfo select(@ApiParam(value = "对象ID" , required = true) @PathVariable("objId") Long objId) {
+    public TableDataInfo select(@ApiParam(value = "对象ID", required = true) @PathVariable("objId") Long objId) {
         startPage();
         List<MetricsTpl> list = bizObjTplService.selectTplList(objId);
         return getDataTable(list);
@@ -56,35 +56,40 @@ public class BizObjController extends BaseController {
 
     @ApiOperation("添加模板")
     @GetMapping("/tpl/add/{objId}")
-    public AjaxResult add(@ApiParam(value = "对象ID" , required = true) @PathVariable("objId") Long objId, @ApiParam(value = "指标ID数组" , required = true) Long[] tplIds) {
+    public AjaxResult add(@ApiParam(value = "对象ID", required = true) @PathVariable("objId") Long objId, @ApiParam(value = "指标ID数组", required = true) Long[] tplIds) {
         return success(bizObjTplService.insertTplDetails(objId, tplIds));
     }
 
     @ApiOperation("删除模板")
     @GetMapping("/tpl/del/{objId}/{tplId}")
-    public AjaxResult del(@ApiParam(value = "对象ID" , required = true) @PathVariable("objId") Long objId, @ApiParam(value = "模板ID" , required = true) @PathVariable("tplId") Long tplId) {
+    public AjaxResult del(@ApiParam(value = "对象ID", required = true) @PathVariable("objId") Long objId, @ApiParam(value = "模板ID", required = true) @PathVariable("tplId") Long tplId) {
         return success(bizObjTplService.del(objId, tplId));
     }
 
     @ApiOperation("选择指标")
     @GetMapping("/metrics/select/{objId}")
-    public TableDataInfo metricsSelect(@ApiParam(value = "对象ID" , required = true) @PathVariable("objId") Long objId) {
+    public TableDataInfo metricsSelect(@ApiParam(value = "对象ID", required = true) @PathVariable("objId") Long objId) {
         startPage();
+        //只能选择prometheus的指标
         List<MetricsDef> list = metricsService.selectMetricsDefList(objId);
         return getDataTable(list);
     }
 
     @ApiOperation("根据对象获取指标")
     @GetMapping("/getMetrics/{objId}")
-    public List<BizObjMetrics> getMetrics(@ApiParam(value = "对象ID" , required = true) @PathVariable("objId") Long objId) {
+    public List<BizObjMetrics> getMetrics(@ApiParam(value = "对象ID", required = true) @PathVariable("objId") Long objId) {
         BizObjMetrics om = new BizObjMetrics();
         om.setObjId(objId);
-        return metricsService.selectBizObjMetricsList(om);
+        List<BizObjMetrics> list = metricsService.selectBizObjMetricsList(om);
+        list.forEach(m -> {
+//            m.getMetricsDef().getMetricsType().equals();
+        });
+        return list;
     }
 
     @ApiOperation("添加指标")
     @GetMapping("/metrics/add/{objId}")
-    public AjaxResult metricsAdd(@ApiParam(value = "对象ID" , required = true) @PathVariable("objId") Long objId, @ApiParam(value = "指标ID数组" , required = true) Long[] metricsIds) {
+    public AjaxResult metricsAdd(@ApiParam(value = "对象ID", required = true) @PathVariable("objId") Long objId, @ApiParam(value = "指标ID数组", required = true) Long[] metricsIds) {
         return success(metricsService.insertMetricsDetails(objId, metricsIds));
     }
 
@@ -105,7 +110,7 @@ public class BizObjController extends BaseController {
      */
     @ApiOperation("导出业务对象列表")
     @PreAuthorize("@ss.hasPermi('obj:obj:export')")
-    @Log(title = "业务对象" , businessType = BusinessType.EXPORT)
+    @Log(title = "业务对象", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, BizObj bizObj) {
         List<BizObj> list = bizObjService.selectBizObjList(bizObj);
@@ -128,7 +133,7 @@ public class BizObjController extends BaseController {
      */
     @ApiOperation("新增业务对象")
     @PreAuthorize("@ss.hasPermi('obj:obj:add')")
-    @Log(title = "业务对象" , businessType = BusinessType.INSERT)
+    @Log(title = "业务对象", businessType = BusinessType.INSERT)
     @PostMapping
     public AjaxResult add(@RequestBody BizObj bizObj) {
         bizObj.setCreateBy(SecurityUtils.getUsername());
@@ -140,7 +145,7 @@ public class BizObjController extends BaseController {
      */
     @ApiOperation("修改业务对象")
     @PreAuthorize("@ss.hasPermi('obj:obj:edit')")
-    @Log(title = "业务对象" , businessType = BusinessType.UPDATE)
+    @Log(title = "业务对象", businessType = BusinessType.UPDATE)
     @PutMapping
     public AjaxResult edit(@RequestBody BizObj bizObj) {
         bizObj.setUpdateBy(SecurityUtils.getUsername());
@@ -152,7 +157,7 @@ public class BizObjController extends BaseController {
      */
     @ApiOperation("删除业务对象")
     @PreAuthorize("@ss.hasPermi('obj:obj:remove')")
-    @Log(title = "业务对象" , businessType = BusinessType.DELETE)
+    @Log(title = "业务对象", businessType = BusinessType.DELETE)
     @DeleteMapping("/{objIds}")
     public AjaxResult remove(@PathVariable Long[] objIds) {
         return toAjax(bizObjService.deleteBizObjByObjIds(objIds));

+ 20 - 34
jjt-biz/src/main/java/com/jjt/biz/controller/BizObjMetricsController.java

@@ -1,28 +1,21 @@
 package com.jjt.biz.controller;
 
-import java.util.List;
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletResponse;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import com.jjt.biz.domain.BizObjMetrics;
+import com.jjt.biz.service.IBizObjMetricsService;
 import com.jjt.common.annotation.Log;
 import com.jjt.common.core.controller.BaseController;
 import com.jjt.common.core.domain.AjaxResult;
+import com.jjt.common.core.page.TableDataInfo;
 import com.jjt.common.enums.BusinessType;
-import com.jjt.biz.domain.BizObjMetrics;
-import com.jjt.biz.service.IBizObjMetricsService;
 import com.jjt.common.utils.poi.ExcelUtil;
-import com.jjt.common.core.page.TableDataInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
 
 /**
  * 业务对象指标Controller
@@ -30,11 +23,10 @@ import com.jjt.common.core.page.TableDataInfo;
  * @author jjt
  * @date 2024-08-09
  */
-@Api(tags="业务对象指标")
+@Api(tags = "业务对象指标")
 @RestController
 @RequestMapping("/obj/metrics")
-public class BizObjMetricsController extends BaseController
-{
+public class BizObjMetricsController extends BaseController {
     @Resource
     private IBizObjMetricsService bizObjMetricsService;
 
@@ -44,8 +36,7 @@ public class BizObjMetricsController extends BaseController
     @ApiOperation("查询业务对象指标列表")
     @PreAuthorize("@ss.hasPermi('obj:metrics:list')")
     @GetMapping("/list")
-    public TableDataInfo list(BizObjMetrics bizObjMetrics)
-    {
+    public TableDataInfo list(BizObjMetrics bizObjMetrics) {
         startPage();
         List<BizObjMetrics> list = bizObjMetricsService.selectBizObjMetricsList(bizObjMetrics);
         return getDataTable(list);
@@ -58,8 +49,7 @@ public class BizObjMetricsController extends BaseController
     @PreAuthorize("@ss.hasPermi('obj:metrics:export')")
     @Log(title = "业务对象指标", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
-    public void export(HttpServletResponse response, BizObjMetrics bizObjMetrics)
-    {
+    public void export(HttpServletResponse response, BizObjMetrics bizObjMetrics) {
         List<BizObjMetrics> list = bizObjMetricsService.selectBizObjMetricsList(bizObjMetrics);
         ExcelUtil<BizObjMetrics> util = new ExcelUtil<BizObjMetrics>(BizObjMetrics.class);
         util.exportExcel(response, list, "业务对象指标数据");
@@ -71,8 +61,7 @@ public class BizObjMetricsController extends BaseController
     @ApiOperation("获取业务对象指标详细信息")
     @PreAuthorize("@ss.hasPermi('obj:metrics:query')")
     @GetMapping(value = "/{objMetricsId}")
-    public AjaxResult getInfo(@PathVariable("objMetricsId") Long objMetricsId)
-    {
+    public AjaxResult getInfo(@PathVariable("objMetricsId") Long objMetricsId) {
         return success(bizObjMetricsService.selectBizObjMetricsByObjMetricsId(objMetricsId));
     }
 
@@ -83,8 +72,7 @@ public class BizObjMetricsController extends BaseController
     @PreAuthorize("@ss.hasPermi('obj:metrics:add')")
     @Log(title = "业务对象指标", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody BizObjMetrics bizObjMetrics)
-    {
+    public AjaxResult add(@RequestBody BizObjMetrics bizObjMetrics) {
         return toAjax(bizObjMetricsService.insertBizObjMetrics(bizObjMetrics));
     }
 
@@ -95,8 +83,7 @@ public class BizObjMetricsController extends BaseController
     @PreAuthorize("@ss.hasPermi('obj:metrics:edit')")
     @Log(title = "业务对象指标", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody BizObjMetrics bizObjMetrics)
-    {
+    public AjaxResult edit(@RequestBody BizObjMetrics bizObjMetrics) {
         return toAjax(bizObjMetricsService.updateBizObjMetrics(bizObjMetrics));
     }
 
@@ -106,9 +93,8 @@ public class BizObjMetricsController extends BaseController
     @ApiOperation("删除业务对象指标")
     @PreAuthorize("@ss.hasPermi('obj:metrics:remove')")
     @Log(title = "业务对象指标", businessType = BusinessType.DELETE)
-	@DeleteMapping("/{objMetricsIds}")
-    public AjaxResult remove(@PathVariable Long[] objMetricsIds)
-    {
+    @DeleteMapping("/{objMetricsIds}")
+    public AjaxResult remove(@PathVariable Long[] objMetricsIds) {
         return toAjax(bizObjMetricsService.deleteBizObjMetricsByObjMetricsIds(objMetricsIds));
     }
 }

+ 25 - 83
jjt-biz/src/main/java/com/jjt/biz/domain/BizObj.java

@@ -1,12 +1,11 @@
 package com.jjt.biz.domain;
 
 import com.baomidou.mybatisplus.annotation.TableId;
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
 import com.jjt.common.annotation.Excel;
 import com.jjt.common.core.domain.BaseEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
 
 /**
  * 业务对象对象 biz_obj
@@ -15,109 +14,52 @@ import com.jjt.common.core.domain.BaseEntity;
  * @date 2024-08-09
  */
 @ApiModel(value = "BizObj", description = "业务对象")
-public class BizObj extends BaseEntity
-{
+@Data
+public class BizObj extends BaseEntity {
     private static final long serialVersionUID = 1L;
 
-    /** 对象ID */
+    /**
+     * 对象ID
+     */
     @ApiModelProperty("对象ID")
     @TableId
     private Long objId;
 
-    /** 业务类型 */
+    /**
+     * 业务类型
+     */
     @ApiModelProperty("业务类型")
     @Excel(name = "业务类型")
     private String objType;
 
-    /** 应用ID */
+    /**
+     * 应用ID
+     */
     @ApiModelProperty("应用ID")
     @Excel(name = "应用ID")
     private Long appId;
 
-    /** 对象名称 */
+    /**
+     * 对象名称
+     */
     @ApiModelProperty("对象名称")
     @Excel(name = "对象名称")
     private String objName;
 
-    /** IP地址 */
+    /**
+     * IP地址
+     */
     @ApiModelProperty("IP地址")
     @Excel(name = "IP地址")
     private String objAddr;
 
-    /** 端口 */
+    /**
+     * 端口
+     */
     @ApiModelProperty("端口")
     @Excel(name = "端口")
     private Long objPort;
 
-    public void setObjId(Long objId)
-    {
-        this.objId = objId;
-    }
-
-    public Long getObjId()
-    {
-        return objId;
-    }
-    public void setObjType(String objType)
-    {
-        this.objType = objType;
-    }
-
-    public String getObjType()
-    {
-        return objType;
-    }
-    public void setAppId(Long appId)
-    {
-        this.appId = appId;
-    }
-
-    public Long getAppId()
-    {
-        return appId;
-    }
-    public void setObjName(String objName)
-    {
-        this.objName = objName;
-    }
-
-    public String getObjName()
-    {
-        return objName;
-    }
-    public void setObjAddr(String objAddr)
-    {
-        this.objAddr = objAddr;
-    }
-
-    public String getObjAddr()
-    {
-        return objAddr;
-    }
-    public void setObjPort(Long objPort)
-    {
-        this.objPort = objPort;
-    }
-
-    public Long getObjPort()
-    {
-        return objPort;
-    }
-
-    @Override
-    public String toString() {
-        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("objId", getObjId())
-            .append("objType", getObjType())
-            .append("appId", getAppId())
-            .append("objName", getObjName())
-            .append("objAddr", getObjAddr())
-            .append("objPort", getObjPort())
-            .append("createBy", getCreateBy())
-            .append("createTime", getCreateTime())
-            .append("updateBy", getUpdateBy())
-            .append("updateTime", getUpdateTime())
-            .append("remark", getRemark())
-            .toString();
-    }
+    @ApiModelProperty("系统压力")
+    private Integer accessTimes;
 }

+ 6 - 1
jjt-biz/src/main/java/com/jjt/biz/domain/BizObjMetrics.java

@@ -7,6 +7,8 @@ import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
+import java.math.BigDecimal;
+
 /**
  * 业务对象指标对象 biz_obj_metrics
  *
@@ -21,7 +23,7 @@ public class BizObjMetrics extends BaseEntity {
     /**
      * ID
      */
-    @ApiModelProperty("ID")
+    @ApiModelProperty("指标对象ID")
     @TableId
     private Long objMetricsId;
 
@@ -69,4 +71,7 @@ public class BizObjMetrics extends BaseEntity {
 
     @ApiModelProperty("指标定义")
     private MetricsDef metricsDef;
+    @ApiModelProperty("指标当前值")
+    @Excel(name = "指标当前值")
+    private BigDecimal dValue;
 }

+ 101 - 0
jjt-biz/src/main/java/com/jjt/biz/domain/PinpointVO.java

@@ -0,0 +1,101 @@
+package com.jjt.biz.domain;
+
+import com.alibaba.fastjson2.JSONObject;
+import lombok.Data;
+
+/**
+ * PinpointVO$
+ *
+ * @author wukai
+ * @date 2024/8/21 10:16
+ */
+
+@Data
+public class PinpointVO {
+    /**
+     * key值
+     */
+    private String key;
+    /**
+     * 应用名称
+     */
+    private String applicationName;
+    /**
+     * 应用分类
+     */
+    private String category;
+    /**
+     * 总访问次数
+     */
+    private Integer tot;
+    /**
+     * 总时延
+     */
+    private Integer sum;
+    /**
+     * 平均时延
+     */
+    private Integer avg;
+    /**
+     * 最大时延
+     */
+    private Integer max;
+    /**
+     * 1秒内访问次数
+     */
+    private Integer time1s;
+    /**
+     * 3秒内访问次数
+     */
+    private Integer time3s;
+    /**
+     * 5秒内响应次数
+     */
+    private Integer time5s;
+    /**
+     * 100ms内响应次数
+     */
+    private Integer time100ms;
+    /**
+     * 300ms内响应次数
+     */
+    private Integer time300ms;
+    /**
+     * 500ms内响应次数
+     */
+    private Integer time500ms;
+    /**
+     * 慢访问次数
+     */
+    private Integer slow;
+    /**
+     * 错误访问次数
+     */
+    private Integer error;
+
+    public PinpointVO(JSONObject obj) {
+        this.key = obj.getString("key");
+        this.category = obj.getString("category");
+        this.applicationName = obj.getString("applicationName");
+        this.tot = obj.getInteger("totalCount");
+        this.slow = obj.getInteger("slowCount");
+        this.error = obj.getInteger("errorCount");
+
+        JSONObject responseStatistics = obj.getJSONObject("responseStatistics");
+        this.sum = responseStatistics.getInteger("Sum");
+        this.avg = responseStatistics.getInteger("Avg");
+        this.max = responseStatistics.getInteger("Max");
+
+        JSONObject histogram = obj.getJSONObject("histogram");
+        String redis = "REDIS";
+        if (redis.equals(category)) {
+            this.time100ms = histogram.getInteger("100ms");
+            this.time300ms = histogram.getInteger("300ms");
+            this.time500ms = histogram.getInteger("500ms");
+        } else {
+            this.time1s = histogram.getInteger("1s");
+            this.time3s = histogram.getInteger("3s");
+            this.time5s = histogram.getInteger("5s");
+        }
+    }
+}

+ 1 - 1
jjt-biz/src/main/java/com/jjt/biz/mapper/BizObjMetricsMapper.java

@@ -84,5 +84,5 @@ public interface BizObjMetricsMapper extends BaseMapper<BizObjMetrics> {
      *
      * @param objMetrics 指标列表
      */
-    void batchInsert(List<BizObjMetrics> objMetrics);
+    void batchInsert(@Param("objMetrics") List<BizObjMetrics> objMetrics);
 }

+ 7 - 0
jjt-biz/src/main/java/com/jjt/biz/service/IBizObjMetricsService.java

@@ -115,4 +115,11 @@ public interface IBizObjMetricsService {
      * @param detail
      */
     void del(MetricsTplDetail detail);
+
+    /**
+     * 根据objId获取指标值
+     *
+     * @param objId 对象ID
+     */
+    void getMetricsValue(Long objId);
 }

+ 12 - 3
jjt-biz/src/main/java/com/jjt/biz/service/IBizObjPpService.java

@@ -1,16 +1,16 @@
 package com.jjt.biz.service;
 
-import java.util.List;
 import com.jjt.biz.domain.BizObjPp;
 
+import java.util.List;
+
 /**
  * 业务对象pinpoint组成Service接口
  *
  * @author jjt
  * @date 2024-08-09
  */
-public interface IBizObjPpService
-{
+public interface IBizObjPpService {
     /**
      * 查询业务对象pinpoint组成
      *
@@ -36,6 +36,14 @@ public interface IBizObjPpService
     public int insertBizObjPp(BizObjPp bizObjPp);
 
     /**
+     * 保存或更新
+     *
+     * @param bizObjPp 业务对象pinpoint组成
+     * @return 结果
+     */
+    int saveOrUpdate(BizObjPp bizObjPp);
+
+    /**
      * 修改业务对象pinpoint组成
      *
      * @param bizObjPp 业务对象pinpoint组成
@@ -61,6 +69,7 @@ public interface IBizObjPpService
 
     /**
      * 通过objId查询列表
+     *
      * @param objId 对象ID
      * @return 结果
      */

+ 7 - 0
jjt-biz/src/main/java/com/jjt/biz/service/IBizObjTplService.java

@@ -67,6 +67,13 @@ public interface IBizObjTplService
      * @return 结果
      */
     List<MetricsTpl> selectTplList(Long objId);
+    /**
+     * 查询当前对象已选择的模板
+     *
+     * @param objId 对象ID
+     * @return 结果
+     */
+    List<BizObjTpl> selectTplList4objId(Long objId);
 
     /**
      * 添加模板

+ 62 - 0
jjt-biz/src/main/java/com/jjt/biz/service/IPinpointService.java

@@ -0,0 +1,62 @@
+package com.jjt.biz.service;
+
+import com.alibaba.fastjson2.JSONObject;
+
+import java.time.LocalDateTime;
+import java.util.Map;
+
+/**
+ * API接口
+ *
+ * @author jjt
+ * @date 2024-08-08
+ */
+public interface IPinpointService {
+    /**
+     * 获取所有应用列表
+     *
+     * @return 结果
+     */
+    Map<String, String> getApps();
+
+    /**
+     * 链路查询
+     *
+     * @param name appName
+     * @param type serviceType
+     * @param st   开始时间
+     * @param ed   结束时间
+     * @return 结果
+     */
+    JSONObject link(String name, String type, LocalDateTime st, LocalDateTime ed);
+
+    /**
+     * tps查询
+     *
+     * @param agentId appName
+     * @param st      开始时间
+     * @param ed      结束时间
+     * @return 结果
+     */
+    Float tps(String agentId, LocalDateTime st, LocalDateTime ed);
+
+    /**
+     * 打开文件数量查询
+     *
+     * @param agentId appName
+     * @param st      开始时间
+     * @param ed      结束时间
+     * @return 结果
+     */
+    int openFile(String agentId, LocalDateTime st, LocalDateTime ed);
+
+    /**
+     * jvm内存使用情况
+     *
+     * @param agentId appName
+     * @param st      开始时间
+     * @param ed      结束时间
+     * @return 结果
+     */
+    Map<String, Object> jvmMemory(String agentId, LocalDateTime st, LocalDateTime ed);
+}

+ 25 - 0
jjt-biz/src/main/java/com/jjt/biz/service/IPrometheusService.java

@@ -0,0 +1,25 @@
+package com.jjt.biz.service;
+
+import com.alibaba.fastjson2.JSONObject;
+
+/**
+ * API接口
+ *
+ * @author jjt
+ * @date 2024-08-08
+ */
+public interface IPrometheusService {
+    /**
+     * pinpoint接口查询
+     *
+     * @return 结果
+     */
+    public JSONObject pinpoint();
+
+    /**
+     * 普罗米修斯接口
+     *
+     * @return 结果
+     */
+    public JSONObject prometheus();
+}

+ 155 - 19
jjt-biz/src/main/java/com/jjt/biz/service/impl/BizObjMetricsServiceImpl.java

@@ -1,19 +1,25 @@
 package com.jjt.biz.service.impl;
 
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.jjt.biz.domain.*;
 import com.jjt.biz.mapper.BizObjMetricsMapper;
-import com.jjt.biz.service.IBizObjMetricsService;
-import com.jjt.biz.service.IBizObjPpService;
-import com.jjt.biz.service.IBizObjService;
-import com.jjt.biz.service.IMetricsTplDetailService;
+import com.jjt.biz.service.*;
 import com.jjt.common.utils.DateUtils;
+import org.apache.ibatis.session.ExecutorType;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * 业务对象指标Service业务层处理
@@ -31,6 +37,14 @@ public class BizObjMetricsServiceImpl implements IBizObjMetricsService {
     private IBizObjPpService ppService;
     @Resource
     private IBizObjService objService;
+    @Resource
+    private IBizObjAppService appService;
+    @Resource
+    private IPinpointService pinpointService;
+    @Resource
+    private IBizObjTplService objTplService;
+    @Resource
+    private SqlSessionFactory factory;
 
     /**
      * 查询业务对象指标
@@ -145,8 +159,8 @@ public class BizObjMetricsServiceImpl implements IBizObjMetricsService {
     @Override
     public void delete(Long objId, Long tplId) {
         QueryWrapper<BizObjMetrics> wrapper = new QueryWrapper<>();
-        wrapper.eq("obj_id" , objId);
-        wrapper.eq("tpl_id" , tplId);
+        wrapper.eq("obj_id", objId);
+        wrapper.eq("tpl_id", tplId);
         bizObjMetricsMapper.delete(wrapper);
     }
 
@@ -163,39 +177,40 @@ public class BizObjMetricsServiceImpl implements IBizObjMetricsService {
         List<MetricsTplDetail> list = detailService.selectMetricsTplDetailList(query);
         List<BizObjMetrics> objMetrics = new ArrayList<>();
         list.forEach(d -> {
-            BizObjMetrics ms;
             if ("1".equals(d.getMetricsDef().getMetricsType())) {
                 //如果是pinpoint,需要
                 // 1.获取对象pinpoint组成
                 List<BizObjPp> pps = ppService.selectBizObjPpListByObjId(objId);
                 for (BizObjPp pp : pps) {
-                    ms = new BizObjMetrics();
+                    BizObjMetrics ms = new BizObjMetrics();
                     ms.setObjId(objId);
                     ms.setTplId(tplId);
                     ms.setMetricsId(d.getMetricsId());
-                    ms.setMetricsName(pp.getPpType() + "/" + d.getMetricsDef().getMetricsName() + "/" + pp.getPpAddr());
+                    ms.setMetricsName(pp.getPpType() + "/" + d.getMetricsDef().getMetricsName());
                     ms.setMetricsCode(pp.getPpName() + "/" + d.getMetricsCode());
                     ms.setAlarmLow(d.getAlarmLow());
                     ms.setAlarmMid(d.getAlarmMid());
                     ms.setAlarmHigh(d.getAlarmHigh());
-//                    ms.setAlarmRule(d.getAlarmRule());
                     objMetrics.add(ms);
                 }
             } else {
-                ms = new BizObjMetrics();
+                BizObjMetrics ms = new BizObjMetrics();
                 ms.setObjId(objId);
                 ms.setTplId(tplId);
                 ms.setMetricsId(d.getMetricsId());
                 ms.setMetricsName(d.getMetricsDef().getMetricsName() + "/" + obj.getObjAddr() + ":" + obj.getObjPort());
                 ms.setMetricsCode(d.getMetricsCode());
-                  ms.setAlarmLow(d.getAlarmLow());
+                ms.setAlarmLow(d.getAlarmLow());
                 ms.setAlarmMid(d.getAlarmMid());
                 ms.setAlarmHigh(d.getAlarmHigh());
                 objMetrics.add(ms);
             }
         });
-
-        bizObjMetricsMapper.batchInsert(objMetrics);
+        try (SqlSession sqlSession = factory.openSession(ExecutorType.BATCH, false)) {
+            BizObjMetricsMapper mapper = sqlSession.getMapper(BizObjMetricsMapper.class);
+            objMetrics.forEach(mapper::insertBizObjMetrics);
+            sqlSession.commit();
+        }
     }
 
     /**
@@ -213,9 +228,9 @@ public class BizObjMetricsServiceImpl implements IBizObjMetricsService {
         if (list.size() > 0) {
             //如果有则更新,没有则插入
             UpdateWrapper<BizObjMetrics> updateWrapper = new UpdateWrapper<>();
-            updateWrapper.set("alarm_low" , detail.getAlarmLow());
-            updateWrapper.set("alarm_mid" , detail.getAlarmMid());
-            updateWrapper.set("alarm_high" , detail.getAlarmHigh());
+            updateWrapper.set("alarm_low", detail.getAlarmLow());
+            updateWrapper.set("alarm_mid", detail.getAlarmMid());
+            updateWrapper.set("alarm_high", detail.getAlarmHigh());
             bizObjMetricsMapper.update(om, updateWrapper);
         } else {
             om.setAlarmLow(detail.getAlarmLow());
@@ -234,8 +249,129 @@ public class BizObjMetricsServiceImpl implements IBizObjMetricsService {
     @Override
     public void del(MetricsTplDetail detail) {
         QueryWrapper<BizObjMetrics> wrapper = new QueryWrapper<>();
-        wrapper.eq("metrics_id" , detail.getMetricsId());
-        wrapper.eq("tpl_id" , detail.getTplId());
+        wrapper.eq("metrics_id", detail.getMetricsId());
+        wrapper.eq("tpl_id", detail.getTplId());
         bizObjMetricsMapper.delete(wrapper);
     }
+
+    /**
+     * 根据objId获取指标值
+     *
+     * @param objId 对象ID
+     */
+    @Override
+    public void getMetricsValue(Long objId) {
+        BizObj bizObj = objService.selectBizObjByObjId(objId);
+        if ("1".equals(bizObj.getObjType())) {
+            //如果是java应用,则需要获取应用程序的code传给pinpoint
+            BizObjApp app = appService.selectBizObjAppByAppId(bizObj.getAppId());
+            String name = app.getAppCode();
+            LocalDateTime ed = LocalDateTime.now();
+//            LocalDateTime st = ed.minusMinutes(5);
+            //TODO 暂时取2天的值,不然难得搞
+            LocalDateTime st = ed.minusDays(2);
+
+            Map<String, String> appMap = pinpointService.getApps();
+            String type = appMap.get(name);
+            //获取tps
+            Float tps = pinpointService.tps(name, st, ed);
+            //获取打开文件数量
+//            int opens = pinpointService.openFile(name, st, ed);
+            //获取jvm信息
+            Map<String, Object> jvm = pinpointService.jvmMemory(name, st, ed);
+            //获取链路数据
+            JSONObject linkObj = pinpointService.link(name, type, st, ed);
+            JSONArray array = linkObj.getJSONObject("applicationMapData").getJSONArray("nodeDataArray");
+            List<PinpointVO> pinpointVOList = new ArrayList<>();
+            for (int i = 0; i < array.size(); i++) {
+                JSONObject obj = array.getJSONObject(i);
+                PinpointVO vo = new PinpointVO(obj);
+                if (vo.getApplicationName().equals(name)) {
+                    //设置系统压力
+                    bizObj.setAccessTimes(vo.getTot());
+                    objService.updateBizObj(bizObj);
+                } else {
+                    pinpointVOList.add(vo);
+                }
+            }
+            //pinpointVOList
+            //1.更新BIZ_OBJ_PP 表
+            List<BizObjPp> ppList = ppService.selectBizObjPpListByObjId(objId);
+            Set<String> nameSet = ppList.stream().map(BizObjPp::getPpName).collect(Collectors.toSet());
+            pinpointVOList.forEach(vo -> {
+                if (!nameSet.contains(vo.getApplicationName())) {
+                    BizObjPp pp = new BizObjPp();
+                    pp.setObjId(objId);
+                    pp.setPpKey(vo.getKey());
+                    pp.setPpName(vo.getApplicationName());
+                    pp.setPpType(vo.getCategory());
+                    ppService.insertBizObjPp(pp);
+
+                    //2.更新业务对象指标表。
+                    //2.1查询模板列表
+                    List<BizObjTpl> tplList = objTplService.selectTplList4objId(objId);
+                    tplList.forEach(tpl -> {
+                        //2.2 根据模板添加指标
+                        insert(objId, tpl.getTplId(), pp);
+                    });
+
+                }
+            });
+
+            //3.更新数据,需要增加最近值和更新时间
+            //查询所有指标
+            BizObjMetrics om = new BizObjMetrics();
+            om.setObjId(objId);
+            List<BizObjMetrics> list = selectBizObjMetricsList(om);
+//            selectBizObjMetricsList()
+
+
+        }
+        BizObjMetrics om = new BizObjMetrics();
+        om.setObjId(objId);
+        List<BizObjMetrics> list = selectBizObjMetricsList(om);
+//        //根据指标类型进行分组
+//        Map<String, List<BizObjMetrics>> typeMap = list.stream().collect(Collectors.groupingBy(m -> m.getMetricsDef().getMetricsType()));
+//        for (String s : typeMap.keySet()) {
+//
+//        }
+//
+//        if (typeMap.containsKey("pinpoint")) {
+//            //如果有pinpoint,查询pinpoint所有指标
+//
+//        }
+
+    }
+
+    /**
+     * 更新模板中的pinpoint指标到业务对象指标
+     *
+     * @param objId 对象ID
+     * @param tplId 模板ID
+     * @param pp    pinpoint组成
+     */
+    private void insert(Long objId, Long tplId, BizObjPp pp) {
+        MetricsTplDetail query = new MetricsTplDetail();
+        query.setTplId(tplId);
+        List<MetricsTplDetail> list = detailService.selectMetricsTplDetailList(query);
+        List<BizObjMetrics> objMetrics = new ArrayList<>();
+        list.forEach(d -> {
+            if ("1".equals(d.getMetricsDef().getMetricsType())) {
+                //如果是pinpoint,需要
+                // 1.获取对象pinpoint组成
+                BizObjMetrics ms = new BizObjMetrics();
+                ms.setObjId(objId);
+                ms.setTplId(tplId);
+                ms.setMetricsId(d.getMetricsId());
+                ms.setMetricsName(pp.getPpName() + "/" + d.getMetricsDef().getMetricsName());
+                ms.setMetricsCode(pp.getPpName() + "/" + d.getMetricsCode());
+                ms.setAlarmLow(d.getAlarmLow());
+                ms.setAlarmMid(d.getAlarmMid());
+                ms.setAlarmHigh(d.getAlarmHigh());
+                objMetrics.add(ms);
+            }
+        });
+
+        bizObjMetricsMapper.batchInsert(objMetrics);
+    }
 }

+ 13 - 0
jjt-biz/src/main/java/com/jjt/biz/service/impl/BizObjPpServiceImpl.java

@@ -55,6 +55,19 @@ public class BizObjPpServiceImpl implements IBizObjPpService {
     }
 
     /**
+     * 保存或更新
+     *
+     * @param bizObjPp 业务对象pinpoint组成
+     * @return 结果
+     */
+    @Override
+    public int saveOrUpdate(BizObjPp bizObjPp) {
+        List<BizObjPp> list = selectBizObjPpListByObjId(bizObjPp.getObjId());
+
+        return 0;
+    }
+
+    /**
      * 修改业务对象pinpoint组成
      *
      * @param bizObjPp 业务对象pinpoint组成

+ 16 - 3
jjt-biz/src/main/java/com/jjt/biz/service/impl/BizObjTplServiceImpl.java

@@ -4,10 +4,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.jjt.biz.domain.BizObjTpl;
 import com.jjt.biz.domain.MetricsTpl;
 import com.jjt.biz.mapper.BizObjTplMapper;
+import com.jjt.biz.service.IBizObjMetricsService;
 import com.jjt.biz.service.IBizObjTplService;
 import com.jjt.biz.service.IMetricsTplDetailService;
 import com.jjt.common.utils.DateUtils;
-import com.jjt.biz.service.IBizObjMetricsService;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -108,6 +108,19 @@ public class BizObjTplServiceImpl implements IBizObjTplService {
     }
 
     /**
+     * 查询当前对象已选择的模板
+     *
+     * @param objId 对象ID
+     * @return 结果
+     */
+    @Override
+    public List<BizObjTpl> selectTplList4objId(Long objId) {
+        BizObjTpl objTpl = new BizObjTpl();
+        objTpl.setObjTplId(objId);
+        return selectBizObjTplList(objTpl);
+    }
+
+    /**
      * 添加模板
      *
      * @param objId  对象id
@@ -153,8 +166,8 @@ public class BizObjTplServiceImpl implements IBizObjTplService {
         metricsService.delete(objId, tplId);
         //2.再删除模板
         QueryWrapper<BizObjTpl> wrapper = new QueryWrapper<>();
-        wrapper.eq("obj_id" , objId);
-        wrapper.eq("tpl_id" , tplId);
+        wrapper.eq("obj_id", objId);
+        wrapper.eq("tpl_id", tplId);
         return bizObjTplMapper.delete(wrapper);
     }
 }

+ 185 - 0
jjt-biz/src/main/java/com/jjt/biz/service/impl/PinpointServiceImpl.java

@@ -0,0 +1,185 @@
+package com.jjt.biz.service.impl;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.jjt.biz.service.IPinpointService;
+import com.jjt.common.constant.CacheConstants;
+import com.jjt.common.core.redis.RedisCache;
+import com.jjt.common.utils.http.HttpUtils;
+import com.jjt.system.service.ISysConfigService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 告警记录Service业务层处理
+ *
+ * @author jjt
+ * @date 2024-08-08
+ */
+@Service
+public class PinpointServiceImpl implements IPinpointService {
+    @Resource
+    private ISysConfigService configService;
+    @Resource
+    private RedisCache redisCache;
+
+    /**
+     * 获取接口地址
+     *
+     * @return 接口地址
+     */
+    private String baseUri() {
+        return configService.selectConfigByKey("pp.url");
+    }
+
+    /**
+     * 获取所有应用列表
+     *
+     * @return 结果
+     */
+    @Override
+    public Map<String, String> getApps() {
+        Map<String, String> appsMap = redisCache.getCacheMap(CacheConstants.PP_APPS_MAP);
+        if (appsMap == null || appsMap.isEmpty()) {
+            appsMap = new HashMap<>(16);
+            String uri = baseUri() + "/applications.pinpoint";
+            String result = HttpUtils.sendGet(uri);
+            JSONArray jsonArray = JSONArray.parseArray(result);
+            for (int i = 0; i < jsonArray.size(); i++) {
+                JSONObject obj = jsonArray.getJSONObject(i);
+                appsMap.put(obj.getString("applicationName"), obj.getString("serviceType"));
+            }
+            redisCache.setCacheMap(CacheConstants.PP_APPS_MAP, appsMap);
+        }
+        return appsMap;
+    }
+
+    /**
+     * 链路查询
+     *
+     * @param name appName
+     * @param type serviceType
+     * @param st   开始时间
+     * @param ed   结束时间
+     * @return 结果
+     */
+    @Override
+    public JSONObject link(String name, String type, LocalDateTime st, LocalDateTime ed) {
+        long end = ed.toEpochSecond(ZoneOffset.ofHours(8)) * 1000;
+        long start = st.toEpochSecond(ZoneOffset.ofHours(8)) * 1000;
+        String uri = baseUri() + "/getServerMapDataV2.pinpoint?applicationName=%s&serviceTypeName=%s&from=%s&to=%s&calleeRange=1&callerRange=1&wasOnly=false&bidirectional=false&useStatisticsAgentState=false";
+        uri = String.format(uri, name, type, start, end);
+        String result = HttpUtils.sendGet(uri);
+        return JSONObject.parseObject(result);
+    }
+
+    /**
+     * tps查询
+     * "min","max", "avg", "sum" 取max
+     * 返回的一组数据,取最大的一条数据
+     *
+     * @param agentId appName
+     * @param st      开始时间
+     * @param ed      结束时间
+     * @return 结果
+     */
+    @Override
+    public Float tps(String agentId, LocalDateTime st, LocalDateTime ed) {
+        long end = ed.toEpochSecond(ZoneOffset.ofHours(8)) * 1000;
+        long start = st.toEpochSecond(ZoneOffset.ofHours(8)) * 1000;
+        String uri = baseUri() + "/getAgentStat/transaction/chart.pinpoint?agentId=%s&from=%s&to=%s&sampleRate=1";
+        uri = String.format(uri, agentId, start, end);
+
+        String result = HttpUtils.sendGet(uri);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        JSONArray array = jsonObject.getJSONObject("charts").getJSONObject("y").getJSONArray("TPS_TOTAL");
+        Float tps = 0F;
+        for (int i = 0; i < array.size(); i++) {
+            JSONArray arr = array.getJSONArray(i);
+            Float v = arr.getFloat(1);
+            if (v != 0F && v > tps) {
+                tps = v;
+            }
+        }
+        return tps;
+    }
+
+    /**
+     * 打开文件数量查询
+     *
+     * @param agentId appName
+     * @param st      开始时间
+     * @param ed      结束时间
+     * @return 结果
+     */
+    @Override
+    public int openFile(String agentId, LocalDateTime st, LocalDateTime ed) {
+        long end = ed.toEpochSecond(ZoneOffset.ofHours(8)) * 1000;
+        long start = st.toEpochSecond(ZoneOffset.ofHours(8)) * 1000;
+        String uri = baseUri() + "/getAgentStat/fileDescriptor/chart.pinpoint?agentId=%s&from=%s&to=%s&sampleRate=1";
+        uri = String.format(uri, agentId, start, end);
+
+        String result = HttpUtils.sendGet(uri);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        JSONArray array = jsonObject.getJSONObject("charts").getJSONObject("y").getJSONArray("TPS_TOTAL");
+        int num = 0;
+        for (int i = 0; i < array.size(); i++) {
+            JSONArray arr = array.getJSONArray(i);
+            int v = arr.getInteger(1);
+            if (v != 0 && v > num) {
+                num = v;
+            }
+        }
+        return num;
+    }
+
+    /**
+     * jvm内存使用情况
+     *
+     * @param agentId appName
+     * @param st      开始时间
+     * @param ed      结束时间
+     * @return 结果
+     */
+    @Override
+    public Map<String, Object> jvmMemory(String agentId, LocalDateTime st, LocalDateTime ed) {
+        long end = ed.toEpochSecond(ZoneOffset.ofHours(8)) * 1000;
+        long start = st.toEpochSecond(ZoneOffset.ofHours(8)) * 1000;
+        String uri = baseUri() + "/getAgentStat/jvmGc/chart.pinpoint?agentId=%s&from=%s&to=%s&sampleRate=1";
+        uri = String.format(uri, agentId, start, end);
+
+        String result = HttpUtils.sendGet(uri);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        JSONArray heapUsed = jsonObject.getJSONObject("charts").getJSONObject("y").getJSONArray("JVM_MEMORY_HEAP_USED");
+        JSONArray heapMax = jsonObject.getJSONObject("charts").getJSONObject("y").getJSONArray("JVM_MEMORY_HEAP_MAX");
+        JSONArray noHeapUsed = jsonObject.getJSONObject("charts").getJSONObject("y").getJSONArray("JVM_MEMORY_HEAP_MAX");
+        JSONArray noHeapMax = jsonObject.getJSONObject("charts").getJSONObject("y").getJSONArray("JVM_MEMORY_HEAP_MAX");
+        JSONArray gc = jsonObject.getJSONObject("charts").getJSONObject("y").getJSONArray("JVM_GC_OLD_COUNT");
+        Float used = 0F;
+        Float max = 0F;
+        int gcTimes = 0;
+        for (int i = 0; i < heapUsed.size(); i++) {
+            float v = heapUsed.getJSONArray(i).getFloat(1);
+            int gcV = gc.getJSONArray(i).getInteger(1);
+            gcTimes += gcV;
+            if (v != 0f && v > used) {
+                used = v;
+                max = heapMax.getJSONArray(i).getFloat(1);
+            }
+        }
+
+        float usage = BigDecimal.valueOf(used).divide(BigDecimal.valueOf(max), 2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(1000)).floatValue();
+        Map<String, Object> map = new HashMap<>(16);
+        map.put("usage", usage);
+        map.put("gc", gcTimes);
+        return map;
+    }
+
+}

+ 39 - 0
jjt-biz/src/main/java/com/jjt/biz/service/impl/PrometheusServiceImpl.java

@@ -0,0 +1,39 @@
+package com.jjt.biz.service.impl;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.jjt.biz.service.IPinpointService;
+import com.jjt.biz.service.IPrometheusService;
+import com.jjt.system.service.ISysConfigService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+/**
+ * 告警记录Service业务层处理
+ *
+ * @author jjt
+ * @date 2024-08-08
+ */
+@Service
+public class PrometheusServiceImpl implements IPrometheusService {
+
+    /**
+     * pinpoint接口查询
+     *
+     * @return 结果
+     */
+    @Override
+    public JSONObject pinpoint() {
+        return null;
+    }
+
+    /**
+     * 普罗米修斯接口
+     *
+     * @return 结果
+     */
+    @Override
+    public JSONObject prometheus() {
+        return null;
+    }
+}

+ 34 - 0
jjt-biz/src/main/java/com/jjt/task/AlarmTask.java

@@ -0,0 +1,34 @@
+package com.jjt.task;
+
+import com.jjt.biz.service.IBizObjMetricsService;
+import com.jjt.common.utils.StringUtils;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+
+/**
+ * 定时任务调度测试
+ *
+ * @author jjt
+ */
+@Component("alarmTask")
+public class AlarmTask {
+    @Resource
+    private IBizObjMetricsService metricsService;
+
+    public void metrics() {
+        metricsService.getMetricsValue(2L);
+    }
+
+    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) {
+        System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i));
+    }
+
+    public void ryParams(String params) {
+        System.out.println("执行有参方法:" + params);
+    }
+
+    public void ryNoParams() {
+        System.out.println("执行无参方法");
+    }
+}

+ 102 - 93
jjt-biz/src/main/resources/mapper/obj/BizObjDataMapper.xml

@@ -5,133 +5,142 @@
 <mapper namespace="com.jjt.biz.mapper.BizObjDataMapper">
 
     <resultMap type="BizObjData" id="BizObjDataResult">
-            <result property="dataId" column="DATA_ID"/>
-            <result property="objId" column="OBJ_ID"/>
-            <result property="metricsType" column="METRICS_TYPE"/>
-            <result property="apiAddr" column="API_ADDR"/>
-            <result property="createBy" column="CREATE_BY"/>
-            <result property="createTime" column="CREATE_TIME"/>
-            <result property="updateBy" column="UPDATE_BY"/>
-            <result property="updateTime" column="UPDATE_TIME"/>
-            <result property="remark" column="REMARK"/>
+        <result property="dataId" column="DATA_ID"/>
+        <result property="objId" column="OBJ_ID"/>
+        <result property="metricsType" column="METRICS_TYPE"/>
+        <result property="apiAddr" column="API_ADDR"/>
+        <result property="createBy" column="CREATE_BY"/>
+        <result property="createTime" column="CREATE_TIME"/>
+        <result property="updateBy" column="UPDATE_BY"/>
+        <result property="updateTime" column="UPDATE_TIME"/>
+        <result property="remark" column="REMARK"/>
     </resultMap>
 
     <sql id="selectBizObjDataVo">
-        select DATA_ID, OBJ_ID, METRICS_TYPE, API_ADDR, CREATE_BY, CREATE_TIME, UPDATE_BY, UPDATE_TIME, REMARK
+        select DATA_ID,
+               OBJ_ID,
+               METRICS_TYPE,
+               API_ADDR,
+               CREATE_BY,
+               CREATE_TIME,
+               UPDATE_BY,
+               UPDATE_TIME,
+               REMARK
         from biz_obj_data
     </sql>
 
     <select id="selectBizObjDataList" parameterType="BizObjData" resultMap="BizObjDataResult">
         <include refid="selectBizObjDataVo"/>
         <where>
-                        <if test="objId != null ">
-                            and OBJ_ID = #{objId}
-                        </if>
-                        <if test="metricsType != null  and metricsType != ''">
-                            and METRICS_TYPE = #{metricsType}
-                        </if>
-                        <if test="apiAddr != null  and apiAddr != ''">
-                            and API_ADDR = #{apiAddr}
-                        </if>
-                        <if test="createBy != null  and createBy != ''">
-                            and CREATE_BY = #{createBy}
-                        </if>
-                        <if test="createTime != null ">
-                            and CREATE_TIME = #{createTime}
-                        </if>
-                        <if test="updateBy != null  and updateBy != ''">
-                            and UPDATE_BY = #{updateBy}
-                        </if>
-                        <if test="updateTime != null ">
-                            and UPDATE_TIME = #{updateTime}
-                        </if>
-                        <if test="remark != null  and remark != ''">
-                            and REMARK = #{remark}
-                        </if>
+            <if test="objId != null ">
+                and OBJ_ID = #{objId}
+            </if>
+            <if test="metricsType != null  and metricsType != ''">
+                and METRICS_TYPE = #{metricsType}
+            </if>
+            <if test="apiAddr != null  and apiAddr != ''">
+                and API_ADDR = #{apiAddr}
+            </if>
+            <if test="createBy != null  and createBy != ''">
+                and CREATE_BY = #{createBy}
+            </if>
+            <if test="createTime != null ">
+                and CREATE_TIME = #{createTime}
+            </if>
+            <if test="updateBy != null  and updateBy != ''">
+                and UPDATE_BY = #{updateBy}
+            </if>
+            <if test="updateTime != null ">
+                and UPDATE_TIME = #{updateTime}
+            </if>
+            <if test="remark != null  and remark != ''">
+                and REMARK = #{remark}
+            </if>
         </where>
     </select>
 
     <select id="selectBizObjDataByDataId" parameterType="Long"
             resultMap="BizObjDataResult">
-            <include refid="selectBizObjDataVo"/>
-            where DATA_ID = #{dataId}
+        <include refid="selectBizObjDataVo"/>
+        where DATA_ID = #{dataId}
     </select>
 
     <insert id="insertBizObjData" parameterType="BizObjData" useGeneratedKeys="true"
             keyProperty="dataId">
         insert into biz_obj_data
         <trim prefix="(" suffix=")" suffixOverrides=",">
-                    <if test="objId != null">OBJ_ID,
-                    </if>
-                    <if test="metricsType != null and metricsType != ''">METRICS_TYPE,
-                    </if>
-                    <if test="apiAddr != null and apiAddr != ''">API_ADDR,
-                    </if>
-                    <if test="createBy != null">CREATE_BY,
-                    </if>
-                    <if test="createTime != null">CREATE_TIME,
-                    </if>
-                    <if test="updateBy != null">UPDATE_BY,
-                    </if>
-                    <if test="updateTime != null">UPDATE_TIME,
-                    </if>
-                    <if test="remark != null">REMARK,
-                    </if>
+            <if test="objId != null">OBJ_ID,
+            </if>
+            <if test="metricsType != null and metricsType != ''">METRICS_TYPE,
+            </if>
+            <if test="apiAddr != null and apiAddr != ''">API_ADDR,
+            </if>
+            <if test="createBy != null">CREATE_BY,
+            </if>
+            <if test="createTime != null">CREATE_TIME,
+            </if>
+            <if test="updateBy != null">UPDATE_BY,
+            </if>
+            <if test="updateTime != null">UPDATE_TIME,
+            </if>
+            <if test="remark != null">REMARK,
+            </if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
-                    <if test="objId != null">#{objId},
-                    </if>
-                    <if test="metricsType != null and metricsType != ''">#{metricsType},
-                    </if>
-                    <if test="apiAddr != null and apiAddr != ''">#{apiAddr},
-                    </if>
-                    <if test="createBy != null">#{createBy},
-                    </if>
-                    <if test="createTime != null">#{createTime},
-                    </if>
-                    <if test="updateBy != null">#{updateBy},
-                    </if>
-                    <if test="updateTime != null">#{updateTime},
-                    </if>
-                    <if test="remark != null">#{remark},
-                    </if>
+            <if test="objId != null">#{objId},
+            </if>
+            <if test="metricsType != null and metricsType != ''">#{metricsType},
+            </if>
+            <if test="apiAddr != null and apiAddr != ''">#{apiAddr},
+            </if>
+            <if test="createBy != null">#{createBy},
+            </if>
+            <if test="createTime != null">#{createTime},
+            </if>
+            <if test="updateBy != null">#{updateBy},
+            </if>
+            <if test="updateTime != null">#{updateTime},
+            </if>
+            <if test="remark != null">#{remark},
+            </if>
         </trim>
     </insert>
 
     <update id="updateBizObjData" parameterType="BizObjData">
         update biz_obj_data
         <trim prefix="SET" suffixOverrides=",">
-                    <if test="objId != null">OBJ_ID =
-                        #{objId},
-                    </if>
-                    <if test="metricsType != null and metricsType != ''">METRICS_TYPE =
-                        #{metricsType},
-                    </if>
-                    <if test="apiAddr != null and apiAddr != ''">API_ADDR =
-                        #{apiAddr},
-                    </if>
-                    <if test="createBy != null">CREATE_BY =
-                        #{createBy},
-                    </if>
-                    <if test="createTime != null">CREATE_TIME =
-                        #{createTime},
-                    </if>
-                    <if test="updateBy != null">UPDATE_BY =
-                        #{updateBy},
-                    </if>
-                    <if test="updateTime != null">UPDATE_TIME =
-                        #{updateTime},
-                    </if>
-                    <if test="remark != null">REMARK =
-                        #{remark},
-                    </if>
+            <if test="objId != null">OBJ_ID =
+                #{objId},
+            </if>
+            <if test="metricsType != null and metricsType != ''">METRICS_TYPE =
+                #{metricsType},
+            </if>
+            <if test="apiAddr != null and apiAddr != ''">API_ADDR =
+                #{apiAddr},
+            </if>
+            <if test="createBy != null">CREATE_BY =
+                #{createBy},
+            </if>
+            <if test="createTime != null">CREATE_TIME =
+                #{createTime},
+            </if>
+            <if test="updateBy != null">UPDATE_BY =
+                #{updateBy},
+            </if>
+            <if test="updateTime != null">UPDATE_TIME =
+                #{updateTime},
+            </if>
+            <if test="remark != null">REMARK =
+                #{remark},
+            </if>
         </trim>
         where DATA_ID = #{dataId}
     </update>
 
     <delete id="deleteBizObjDataByDataId" parameterType="Long">
         delete
-        from biz_obj_data where DATA_ID = #{dataId}
+        from biz_obj_data
+        where DATA_ID = #{dataId}
     </delete>
 
     <delete id="deleteBizObjDataByDataIds" parameterType="String">

+ 135 - 115
jjt-biz/src/main/resources/mapper/obj/BizObjMapper.xml

@@ -5,155 +5,175 @@
 <mapper namespace="com.jjt.biz.mapper.BizObjMapper">
 
     <resultMap type="BizObj" id="BizObjResult">
-            <result property="objId" column="OBJ_ID"/>
-            <result property="objType" column="OBJ_TYPE"/>
-            <result property="appId" column="APP_ID"/>
-            <result property="objName" column="OBJ_NAME"/>
-            <result property="objAddr" column="OBJ_ADDR"/>
-            <result property="objPort" column="OBJ_PORT"/>
-            <result property="createBy" column="CREATE_BY"/>
-            <result property="createTime" column="CREATE_TIME"/>
-            <result property="updateBy" column="UPDATE_BY"/>
-            <result property="updateTime" column="UPDATE_TIME"/>
-            <result property="remark" column="REMARK"/>
+        <result property="objId" column="OBJ_ID"/>
+        <result property="objType" column="OBJ_TYPE"/>
+        <result property="appId" column="APP_ID"/>
+        <result property="accessTimes" column="ACCESS_TIMES"/>
+        <result property="objName" column="OBJ_NAME"/>
+        <result property="objAddr" column="OBJ_ADDR"/>
+        <result property="objPort" column="OBJ_PORT"/>
+        <result property="createBy" column="CREATE_BY"/>
+        <result property="createTime" column="CREATE_TIME"/>
+        <result property="updateBy" column="UPDATE_BY"/>
+        <result property="updateTime" column="UPDATE_TIME"/>
+        <result property="remark" column="REMARK"/>
     </resultMap>
 
     <sql id="selectBizObjVo">
-        select OBJ_ID, OBJ_TYPE, APP_ID, OBJ_NAME, OBJ_ADDR, OBJ_PORT, CREATE_BY, CREATE_TIME, UPDATE_BY, UPDATE_TIME, REMARK
+        select OBJ_ID,
+               OBJ_TYPE,
+               APP_ID,
+               ACCESS_TIMES,
+               OBJ_NAME,
+               OBJ_ADDR,
+               OBJ_PORT,
+               CREATE_BY,
+               CREATE_TIME,
+               UPDATE_BY,
+               UPDATE_TIME,
+               REMARK
         from biz_obj
     </sql>
 
     <select id="selectBizObjList" parameterType="BizObj" resultMap="BizObjResult">
         <include refid="selectBizObjVo"/>
         <where>
-                        <if test="objType != null  and objType != ''">
-                            and OBJ_TYPE = #{objType}
-                        </if>
-                        <if test="appId != null ">
-                            and APP_ID = #{appId}
-                        </if>
-                        <if test="objName != null  and objName != ''">
-                            and OBJ_NAME like concat('%', #{objName}, '%')
-                        </if>
-                        <if test="objAddr != null  and objAddr != ''">
-                            and OBJ_ADDR = #{objAddr}
-                        </if>
-                        <if test="objPort != null ">
-                            and OBJ_PORT = #{objPort}
-                        </if>
-                        <if test="params.beginCreateBy != null and params.beginCreateBy != '' and params.endCreateBy != null and params.endCreateBy != ''">
-                            and CREATE_BY between #{params.beginCreateBy} and #{params.endCreateBy}
-                        </if>
-                        <if test="createTime != null ">
-                            and CREATE_TIME = #{createTime}
-                        </if>
-                        <if test="updateBy != null  and updateBy != ''">
-                            and UPDATE_BY = #{updateBy}
-                        </if>
-                        <if test="params.beginUpdateTime != null and params.beginUpdateTime != '' and params.endUpdateTime != null and params.endUpdateTime != ''">
-                            and UPDATE_TIME between #{params.beginUpdateTime} and #{params.endUpdateTime}
-                        </if>
-                        <if test="remark != null  and remark != ''">
-                            and REMARK = #{remark}
-                        </if>
+            <if test="objType != null  and objType != ''">
+                and OBJ_TYPE = #{objType}
+            </if>
+            <if test="appId != null ">
+                and APP_ID = #{appId}
+            </if>
+            <if test="objName != null  and objName != ''">
+                and OBJ_NAME like concat('%', #{objName}, '%')
+            </if>
+            <if test="objAddr != null  and objAddr != ''">
+                and OBJ_ADDR = #{objAddr}
+            </if>
+            <if test="objPort != null ">
+                and OBJ_PORT = #{objPort}
+            </if>
+            <if test="params.beginCreateBy != null and params.beginCreateBy != '' and params.endCreateBy != null and params.endCreateBy != ''">
+                and CREATE_BY between #{params.beginCreateBy} and #{params.endCreateBy}
+            </if>
+            <if test="createTime != null ">
+                and CREATE_TIME = #{createTime}
+            </if>
+            <if test="updateBy != null  and updateBy != ''">
+                and UPDATE_BY = #{updateBy}
+            </if>
+            <if test="params.beginUpdateTime != null and params.beginUpdateTime != '' and params.endUpdateTime != null and params.endUpdateTime != ''">
+                and UPDATE_TIME between #{params.beginUpdateTime} and #{params.endUpdateTime}
+            </if>
+            <if test="remark != null  and remark != ''">
+                and REMARK = #{remark}
+            </if>
         </where>
     </select>
 
     <select id="selectBizObjByObjId" parameterType="Long"
             resultMap="BizObjResult">
-            <include refid="selectBizObjVo"/>
-            where OBJ_ID = #{objId}
+        <include refid="selectBizObjVo"/>
+        where OBJ_ID = #{objId}
     </select>
 
     <insert id="insertBizObj" parameterType="BizObj" useGeneratedKeys="true"
             keyProperty="objId">
         insert into biz_obj
         <trim prefix="(" suffix=")" suffixOverrides=",">
-                    <if test="objType != null and objType != ''">OBJ_TYPE,
-                    </if>
-                    <if test="appId != null">APP_ID,
-                    </if>
-                    <if test="objName != null and objName != ''">OBJ_NAME,
-                    </if>
-                    <if test="objAddr != null and objAddr != ''">OBJ_ADDR,
-                    </if>
-                    <if test="objPort != null">OBJ_PORT,
-                    </if>
-                    <if test="createBy != null">CREATE_BY,
-                    </if>
-                    <if test="createTime != null">CREATE_TIME,
-                    </if>
-                    <if test="updateBy != null">UPDATE_BY,
-                    </if>
-                    <if test="updateTime != null">UPDATE_TIME,
-                    </if>
-                    <if test="remark != null">REMARK,
-                    </if>
+            <if test="objType != null and objType != ''">OBJ_TYPE,
+            </if>
+            <if test="appId != null">APP_ID,
+            </if>
+            <if test="accessTimes != null">ACCESS_TIMES,
+            </if>
+            <if test="objName != null and objName != ''">OBJ_NAME,
+            </if>
+            <if test="objAddr != null and objAddr != ''">OBJ_ADDR,
+            </if>
+            <if test="objPort != null">OBJ_PORT,
+            </if>
+            <if test="createBy != null">CREATE_BY,
+            </if>
+            <if test="createTime != null">CREATE_TIME,
+            </if>
+            <if test="updateBy != null">UPDATE_BY,
+            </if>
+            <if test="updateTime != null">UPDATE_TIME,
+            </if>
+            <if test="remark != null">REMARK,
+            </if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
-                    <if test="objType != null and objType != ''">#{objType},
-                    </if>
-                    <if test="appId != null">#{appId},
-                    </if>
-                    <if test="objName != null and objName != ''">#{objName},
-                    </if>
-                    <if test="objAddr != null and objAddr != ''">#{objAddr},
-                    </if>
-                    <if test="objPort != null">#{objPort},
-                    </if>
-                    <if test="createBy != null">#{createBy},
-                    </if>
-                    <if test="createTime != null">#{createTime},
-                    </if>
-                    <if test="updateBy != null">#{updateBy},
-                    </if>
-                    <if test="updateTime != null">#{updateTime},
-                    </if>
-                    <if test="remark != null">#{remark},
-                    </if>
+            <if test="objType != null and objType != ''">#{objType},
+            </if>
+            <if test="appId != null">#{appId},
+            </if>
+            <if test="accessTimes != null">#{accessTimes},
+            </if>
+            <if test="objName != null and objName != ''">#{objName},
+            </if>
+            <if test="objAddr != null and objAddr != ''">#{objAddr},
+            </if>
+            <if test="objPort != null">#{objPort},
+            </if>
+            <if test="createBy != null">#{createBy},
+            </if>
+            <if test="createTime != null">#{createTime},
+            </if>
+            <if test="updateBy != null">#{updateBy},
+            </if>
+            <if test="updateTime != null">#{updateTime},
+            </if>
+            <if test="remark != null">#{remark},
+            </if>
         </trim>
     </insert>
 
     <update id="updateBizObj" parameterType="BizObj">
         update biz_obj
         <trim prefix="SET" suffixOverrides=",">
-                    <if test="objType != null and objType != ''">OBJ_TYPE =
-                        #{objType},
-                    </if>
-                    <if test="appId != null">APP_ID =
-                        #{appId},
-                    </if>
-                    <if test="objName != null and objName != ''">OBJ_NAME =
-                        #{objName},
-                    </if>
-                    <if test="objAddr != null and objAddr != ''">OBJ_ADDR =
-                        #{objAddr},
-                    </if>
-                    <if test="objPort != null">OBJ_PORT =
-                        #{objPort},
-                    </if>
-                    <if test="createBy != null">CREATE_BY =
-                        #{createBy},
-                    </if>
-                    <if test="createTime != null">CREATE_TIME =
-                        #{createTime},
-                    </if>
-                    <if test="updateBy != null">UPDATE_BY =
-                        #{updateBy},
-                    </if>
-                    <if test="updateTime != null">UPDATE_TIME =
-                        #{updateTime},
-                    </if>
-                    <if test="remark != null">REMARK =
-                        #{remark},
-                    </if>
+            <if test="objType != null and objType != ''">OBJ_TYPE =
+                #{objType},
+            </if>
+            <if test="appId != null">APP_ID =
+                #{appId},
+            </if>
+            <if test="accessTimes != null">ACCESS_TIMES =
+                #{accessTimes},
+            </if>
+            <if test="objName != null and objName != ''">OBJ_NAME =
+                #{objName},
+            </if>
+            <if test="objAddr != null and objAddr != ''">OBJ_ADDR =
+                #{objAddr},
+            </if>
+            <if test="objPort != null">OBJ_PORT =
+                #{objPort},
+            </if>
+            <if test="createBy != null">CREATE_BY =
+                #{createBy},
+            </if>
+            <if test="createTime != null">CREATE_TIME =
+                #{createTime},
+            </if>
+            <if test="updateBy != null">UPDATE_BY =
+                #{updateBy},
+            </if>
+            <if test="updateTime != null">UPDATE_TIME =
+                #{updateTime},
+            </if>
+            <if test="remark != null">REMARK =
+                #{remark},
+            </if>
         </trim>
         where OBJ_ID = #{objId}
     </update>
 
     <delete id="deleteBizObjByObjId" parameterType="Long">
         delete
-        from biz_obj where OBJ_ID = #{objId}
+        from biz_obj
+        where OBJ_ID = #{objId}
     </delete>
 
     <delete id="deleteBizObjByObjIds" parameterType="String">

+ 33 - 42
jjt-biz/src/main/resources/mapper/obj/BizObjMetricsMapper.xml

@@ -14,6 +14,7 @@
         <result property="alarmLow" column="ALARM_LOW"/>
         <result property="alarmMid" column="ALARM_MID"/>
         <result property="alarmHigh" column="ALARM_HIGH"/>
+        <result property="dValue" column="D_VALUE"/>
         <result property="createBy" column="CREATE_BY"/>
         <result property="createTime" column="CREATE_TIME"/>
         <result property="updateBy" column="UPDATE_BY"/>
@@ -21,7 +22,7 @@
         <result property="remark" column="REMARK"/>
         <association property="metricsDef" javaType="MetricsDef">
             <result property="metricsId" column="METRICS_ID_b"/>
-            <result property="metricsName" column="METRICS_NAME"/>
+            <result property="metricsName" column="METRICS_NAME_b"/>
             <result property="metricsCode" column="METRICS_CODE_b"/>
             <result property="metricsExp" column="METRICS_EXP"/>
             <result property="metricsType" column="METRICS_TYPE"/>
@@ -37,10 +38,12 @@
                      a.OBJ_ID,
                      a.TPL_ID,
                      a.METRICS_ID,
+                     a.METRICS_NAME,
                      a.METRICS_CODE,
                      a.ALARM_LOW,
                      a.ALARM_MID,
                      a.ALARM_HIGH,
+                     a.D_VALUE,
                      a.CREATE_BY,
                      a.CREATE_TIME,
                      a.UPDATE_BY,
@@ -48,6 +51,7 @@
                      a.REMARK,
                      b.METRICS_ID   as METRICS_ID_b,
                      b.METRICS_CODE as METRICS_CODE_b,
+                     b.METRICS_NAME as METRICS_NAME_b,
                      b.METRICS_EXP,
                      b.METRICS_TYPE,
                      b.ALARM_LOW    as ALARM_LOW_b,
@@ -76,6 +80,18 @@
             <if test="metricsCode != null  and metricsCode != ''">
                 and METRICS_CODE = #{metricsCode}
             </if>
+            <if test="alarmLow != null  and alarmLow != ''">
+                and ALARM_LOW = #{alarmLow}
+            </if>
+            <if test="alarmMid != null  and alarmMid != ''">
+                and ALARM_MID = #{alarmMid}
+            </if>
+            <if test="alarmHigh != null  and alarmHigh != ''">
+                and ALARM_HIGH = #{alarmHigh}
+            </if>
+            <if test="dValue != null ">
+                and D_VALUE = #{dValue}
+            </if>
             <if test="createBy != null  and createBy != ''">
                 and CREATE_BY = #{createBy}
             </if>
@@ -102,7 +118,7 @@
     <select id="selectMetricsDefList" resultType="com.jjt.biz.domain.MetricsDef">
         select *
         from metrics_def
-        where METRICS_ID not in (select METRICS_ID from biz_obj_metrics where OBJ_ID = #{objId})
+        where METRICS_TYPE!='1' and METRICS_ID not in (select METRICS_ID from biz_obj_metrics where OBJ_ID = #{objId})
     </select>
     <insert id="insertMetricsDetails">
         insert into biz_obj_metrics(OBJ_ID,METRICS_ID) select #{objId}, METRICS_ID
@@ -131,6 +147,8 @@
             </if>
             <if test="alarmHigh != null">ALARM_HIGH,
             </if>
+            <if test="dValue != null">D_VALUE,
+            </if>
             <if test="createBy != null">CREATE_BY,
             </if>
             <if test="createTime != null">CREATE_TIME,
@@ -159,6 +177,8 @@
             </if>
             <if test="alarmHigh != null">#{alarmHigh},
             </if>
+            <if test="dValue != null">#{dValue},
+            </if>
             <if test="createBy != null">#{createBy},
             </if>
             <if test="createTime != null">#{createTime},
@@ -171,46 +191,14 @@
             </if>
         </trim>
     </insert>
-    <insert id="batchInsert">
-        insert into biz_obj_metrics
-        <trim prefix="(" suffix=")" suffixOverrides=",">
-            <if test="objId != null">OBJ_ID,
-            </if>
-            <if test="tplId != null">TPL_ID,
-            </if>
-            <if test="metricsId != null">METRICS_ID,
-            </if>
-            <if test="metricsName != null">METRICS_NAME,
-            </if>
-            <if test="metricsCode != null">METRICS_CODE,
-            </if>
-            <if test="alarmLow != null">ALARM_LOW,
-            </if>
-            <if test="alarmMid != null">ALARM_MID,
-            </if>
-            <if test="alarmHigh != null">ALARM_HIGH,
-            </if>
-        </trim>
-        values
-        <foreach collection="userList" item="item" separator=",">
-            <trim prefix="(" suffix=")" suffixOverrides=",">
-                <if test="item.objId != null">#{item.objId},
-                </if>
-                <if test="item.tplId != null">#{item.tplId},
-                </if>
-                <if test="item.metricsId != null">#{item.metricsId},
-                </if>
-                <if test="item.metricsName != null">#{item.metricsName},
-                </if>
-                <if test="item.metricsCode != null">#{item.metricsCode},
-                </if>
-                <if test="alarmLow != null">#{alarmLow},
-                </if>
-                <if test="alarmMid != null">#{alarmMid},
-                </if>
-                <if test="alarmHigh != null">#{alarmHigh},
-                </if>
-            </trim>
+    <insert id="batchInsert" parameterType="java.util.List">
+        insert into biz_obj_metrics (
+        OBJ_ID,TPL_ID,METRICS_ID,METRICS_NAME,METRICS_CODE,ALARM_LOW,ALARM_MID,ALARM_HIGH)
+        VALUES
+        <foreach collection="objMetrics" item="item" separator="," close="">
+            (#{item.objId}, #{item.tplId}, #{item.metricsId}, #{item.metricsName}, #{item.metricsCode},
+            #{item.alarmLow},
+            #{item.alarmMid}, #{item.alarmHigh})
         </foreach>
     </insert>
 
@@ -241,6 +229,9 @@
             <if test="alarmHigh != null">ALARM_HIGH =
                 #{alarmHigh},
             </if>
+            <if test="dValue != null">D_VALUE =
+                #{dValue},
+            </if>
             <if test="createBy != null">CREATE_BY =
                 #{createBy},
             </if>

+ 6 - 0
jjt-common/src/main/java/com/jjt/common/constant/CacheConstants.java

@@ -40,4 +40,10 @@ public class CacheConstants {
      * 登录账户密码错误次数 redis key
      */
     public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
+
+    /**
+     * pinpoint应用列表缓存
+     */
+
+    public static final String PP_APPS_MAP = "jy2024_pp_apps_map:";
 }

+ 1 - 1
jjt-common/src/main/java/com/jjt/common/constant/Constants.java

@@ -163,7 +163,7 @@ public class Constants {
     /**
      * 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加)
      */
-    public static final String[] JOB_WHITELIST_STR = {"com.jjt.quartz.task"};
+    public static final String[] JOB_WHITELIST_STR = {"com.jjt.quartz.task","com.jjt.task"};
 
     /**
      * 定时任务违规的字符

+ 77 - 0
jjt-common/src/main/java/com/jjt/common/utils/IntervalUtil.java

@@ -0,0 +1,77 @@
+package com.jjt.common.utils;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * 区间判断工具类
+ *
+ * @author wukai
+ * @date 2024/8/21 00:01
+ */
+public class IntervalUtil {
+    /**
+     * 开闭区间正则表达式
+     */
+    private static final Pattern NUM_RANGE_PATTERN = Pattern.compile("[\\[|\\(]\\s?\\d+\\s?,\\s?\\d+\\s?[\\)|\\]]");
+    /**
+     * 左半区间正则表达式
+     */
+    private static final Pattern LEFT_NUM_RANGE_PATTERN = Pattern.compile("[\\[|\\(]\\s?\\d+\\s?,\\s?[\\)|\\]]");
+    /**
+     * 右半区间正则表达式
+     */
+    private static final Pattern RIGHT_NUM_RANGE_PATTERN = Pattern.compile("[\\[|\\(],\\s?\\d+\\s?[\\)|\\]]");
+
+    /**
+     * 判断是否为有效的数字区间范围
+     *
+     * @param numRange 数字区间
+     * @return boolean
+     */
+    public static boolean isValidNumRange(String numRange) {
+        return NUM_RANGE_PATTERN.matcher(numRange).matches()
+                || LEFT_NUM_RANGE_PATTERN.matcher(numRange).matches()
+                || RIGHT_NUM_RANGE_PATTERN.matcher(numRange).matches();
+    }
+
+    /**
+     * 判断数值是否在区间范围内
+     *
+     * @param number   数值
+     * @param numRange 开闭区间
+     * @return boolean
+     */
+    public static boolean inNumRange(int number, String numRange) {
+        Objects.requireNonNull(numRange);
+
+        if (!isValidNumRange(numRange)) {
+            return false;
+        }
+
+        String[] pairs = numRange.split(",");
+
+        // 获取开闭区间的最小值和最大值
+        List<String> rangeNums = Arrays.stream(pairs).map(str -> str.replaceAll("[(|)|\\[|\\]]", "").trim()).collect(Collectors.toList());
+        Integer minValue = "".equals(rangeNums.get(0)) ? null : Integer.valueOf(rangeNums.get(0));
+        Integer maxValue = "".equals(rangeNums.get(1)) ? null : Integer.valueOf(rangeNums.get(1));
+
+        // 判定数值是否大于最小值
+        boolean minMatched = (minValue == null) || (pairs[0].startsWith("[") ? number >= minValue : number > minValue);
+        // 判定数值是否小于最大值
+        boolean maxMatched = (maxValue == null) || (pairs[1].endsWith("]") ? number <= maxValue : number < maxValue);
+
+        return minMatched && maxMatched;
+    }
+
+    public static void main(String[] args) {
+        System.out.println(inNumRange(1, "(0, 2]"));
+        System.out.println(inNumRange(1, "(, 2]"));
+        System.out.println(inNumRange(1, "(1, 4]"));
+        System.out.println(inNumRange(1, "(0, ]"));
+    }
+
+}