Procházet zdrojové kódy

拆分pp和pm 加入多线程,

wukai před 7 měsíci
rodič
revize
cb5fb40963

+ 1 - 1
jjt-biz/src/main/java/com/jjt/biz/controller/IndexController.java

@@ -73,7 +73,7 @@ public class IndexController extends BaseController {
     @GetMapping("/hl/curr")
     public AjaxResult hlCurr() {
         List<HlScoreVO> list = scoreService.selectHlScoreListLast();
-        list = list.stream().filter(vo -> vo.getModelId() <= 23).collect(Collectors.toList());
+        list = list.stream().collect(Collectors.toList());
 //        List<Map<String, Object>> result = new ArrayList<>();
 //        for (int i = 0; i < MODEL_NAMES.length; i++) {
 //            Map<String, Object> map = new HashMap<>(16);

+ 3 - 0
jjt-biz/src/main/java/com/jjt/biz/service/impl/BizObjMetricsServiceImpl.java

@@ -21,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSession;
 import org.apache.ibatis.session.SqlSessionFactory;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -340,6 +341,7 @@ public class BizObjMetricsServiceImpl implements IBizObjMetricsService {
      * @param date  数据时间
      */
     @Override
+    @Async("threadPoolTaskExecutor")
     public void pinpointMetricsValue(Long objId, Date date) {
         BizObj bizObj = objService.selectBizObjByObjId(objId);
 
@@ -404,6 +406,7 @@ public class BizObjMetricsServiceImpl implements IBizObjMetricsService {
      * @param date  时间
      */
     @Override
+    @Async("threadPoolTaskExecutor")
     public void prometheusMetricsValue(Long objId, Date date) {
         List<BizObjMetrics> mList = getAllMetricsForObjIdList(objId);
         List<BizObjMetrics> metricsToUpdate = new ArrayList<>();

+ 24 - 7
jjt-biz/src/main/java/com/jjt/push/service/impl/PushConfigServiceImpl.java

@@ -165,7 +165,7 @@ public class PushConfigServiceImpl implements IPushConfigService {
                         pr.setPushType("sms");
                         pr.setAlarmLevel(record.getAlarmLevel());
                         pr.setSendTitle(title);
-//                        pr.setSendContent(content);
+                        pr.setSendContent(content);
                         pr.setSendObj(p);
                         try {
                             smsService.send(uri, p, title);
@@ -185,13 +185,30 @@ public class PushConfigServiceImpl implements IPushConfigService {
 
         if (open.equals(pc.getFlagMail())) {
             //邮件开关打开
-            try {
-                if (StringUtils.isNotEmpty(mails)) {
-                    mails = mails.replace("\n", ",");
-                    mailService.send(mails, title, content);
+            if (StringUtils.isNotEmpty(mails)) {
+                try {
+                    String[] mail = mails.split("\n");
+                    for (String p : mail) {
+                        PushRecord pr = new PushRecord();
+                        pr.setPushType("mail");
+                        pr.setAlarmLevel(record.getAlarmLevel());
+                        pr.setSendTitle(title);
+                        pr.setSendContent(content);
+                        pr.setSendObj(p);
+                        try {
+                            mailService.send(p, title, content);
+                            pr.setSendSuccess("Y");
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                            pr.setSendSuccess("N");
+                            log.error("邮件发送失败:{}", e.getMessage());
+                            pr.setRemark(e.getMessage());
+                        }
+                        pushRecordService.insertPushRecord(pr);
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
                 }
-            } catch (Exception e) {
-                e.printStackTrace();
             }
         }
 //        String

+ 7 - 4
jjt-biz/src/main/java/com/jjt/push/service/impl/PushRecordServiceImpl.java

@@ -1,11 +1,13 @@
 package com.jjt.push.service.impl;
 
-import java.util.List;
-import org.springframework.stereotype.Service;
-import com.jjt.push.mapper.PushRecordMapper;
 import com.jjt.push.domain.PushRecord;
+import com.jjt.push.mapper.PushRecordMapper;
 import com.jjt.push.service.IPushRecordService;
+import org.springframework.stereotype.Service;
+
 import javax.annotation.Resource;
+import java.util.Date;
+import java.util.List;
 
 /**
  * 推送记录Service业务层处理
@@ -48,7 +50,8 @@ public class PushRecordServiceImpl implements IPushRecordService {
      */
     @Override
     public int insertPushRecord(PushRecord pushRecord) {
-            return pushRecordMapper.insertPushRecord(pushRecord);
+        pushRecord.setSendTime(new Date());
+        return pushRecordMapper.insertPushRecord(pushRecord);
     }
 
     /**

+ 11 - 3
jjt-biz/src/main/java/com/jjt/task/DataTask.java

@@ -11,7 +11,6 @@ import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.util.Date;
 import java.util.List;
-import java.util.concurrent.CountDownLatch;
 
 /**
  * 定时任务调度测试
@@ -28,12 +27,21 @@ public class DataTask {
     private JdbcTemplate jdbcTemplate;
 
     /**
-     * 正常获取指标
+     * 获取链路分析指标
      */
-    public void metrics() {
+    public void pp() {
         Date date = new Date();
         objService.selectBizObjList(new BizObj()).forEach(obj -> {
             metricsService.pinpointMetricsValue(obj.getObjId(), date);
+        });
+    }
+
+    /**
+     * 获取普罗米修斯指标
+     */
+    public void pm() {
+        Date date = new Date();
+        objService.selectBizObjList(new BizObj()).forEach(obj -> {
             metricsService.prometheusMetricsValue(obj.getObjId(), date);
         });
     }

+ 103 - 93
jjt-biz/src/main/resources/mapper/push/PushRecordMapper.xml

@@ -5,133 +5,143 @@
 <mapper namespace="com.jjt.push.mapper.PushRecordMapper">
 
     <resultMap type="PushRecord" id="PushRecordResult">
-            <result property="prId" column="PR_ID"/>
-            <result property="pushType" column="PUSH_TYPE"/>
-            <result property="alarmLevel" column="ALARM_LEVEL"/>
-            <result property="sendObj" column="SEND_OBJ"/>
-            <result property="sendTitle" column="SEND_TITLE"/>
-            <result property="sendContent" column="SEND_CONTENT"/>
-            <result property="sendSuccess" column="SEND_SUCCESS"/>
-            <result property="sendTime" column="SEND_TIME"/>
-            <result property="remark" column="REMARK"/>
+        <result property="prId" column="PR_ID"/>
+        <result property="pushType" column="PUSH_TYPE"/>
+        <result property="alarmLevel" column="ALARM_LEVEL"/>
+        <result property="sendObj" column="SEND_OBJ"/>
+        <result property="sendTitle" column="SEND_TITLE"/>
+        <result property="sendContent" column="SEND_CONTENT"/>
+        <result property="sendSuccess" column="SEND_SUCCESS"/>
+        <result property="sendTime" column="SEND_TIME"/>
+        <result property="remark" column="REMARK"/>
     </resultMap>
 
     <sql id="selectPushRecordVo">
-        select PR_ID, PUSH_TYPE, ALARM_LEVEL, SEND_OBJ, SEND_TITLE, SEND_CONTENT, SEND_SUCCESS, SEND_TIME, REMARK
+        select PR_ID,
+               PUSH_TYPE,
+               ALARM_LEVEL,
+               SEND_OBJ,
+               SEND_TITLE,
+               SEND_CONTENT,
+               SEND_SUCCESS,
+               SEND_TIME,
+               REMARK
         from push_record
     </sql>
 
     <select id="selectPushRecordList" parameterType="PushRecord" resultMap="PushRecordResult">
         <include refid="selectPushRecordVo"/>
         <where>
-                        <if test="pushType != null  and pushType != ''">
-                            and PUSH_TYPE = #{pushType}
-                        </if>
-                        <if test="alarmLevel != null  and alarmLevel != ''">
-                            and ALARM_LEVEL = #{alarmLevel}
-                        </if>
-                        <if test="sendObj != null  and sendObj != ''">
-                            and SEND_OBJ like concat('%', #{sendObj}, '%')
-                        </if>
-                        <if test="sendTitle != null  and sendTitle != ''">
-                            and SEND_TITLE like concat('%', #{sendTitle}, '%')
-                        </if>
-                        <if test="sendContent != null  and sendContent != ''">
-                            and SEND_CONTENT like concat('%', #{sendContent}, '%')
-                        </if>
-                        <if test="sendSuccess != null  and sendSuccess != ''">
-                            and SEND_SUCCESS = #{sendSuccess}
-                        </if>
-                        <if test="params.beginSendTime != null and params.beginSendTime != '' and params.endSendTime != null and params.endSendTime != ''">
-                            and SEND_TIME between #{params.beginSendTime} and #{params.endSendTime}
-                        </if>
-                        <if test="remark != null  and remark != ''">
-                            and REMARK = #{remark}
-                        </if>
+            <if test="pushType != null  and pushType != ''">
+                and PUSH_TYPE = #{pushType}
+            </if>
+            <if test="alarmLevel != null  and alarmLevel != ''">
+                and ALARM_LEVEL = #{alarmLevel}
+            </if>
+            <if test="sendObj != null  and sendObj != ''">
+                and SEND_OBJ like concat('%', #{sendObj}, '%')
+            </if>
+            <if test="sendTitle != null  and sendTitle != ''">
+                and SEND_TITLE like concat('%', #{sendTitle}, '%')
+            </if>
+            <if test="sendContent != null  and sendContent != ''">
+                and SEND_CONTENT like concat('%', #{sendContent}, '%')
+            </if>
+            <if test="sendSuccess != null  and sendSuccess != ''">
+                and SEND_SUCCESS = #{sendSuccess}
+            </if>
+            <if test="params.beginSendTime != null and params.beginSendTime != '' and params.endSendTime != null and params.endSendTime != ''">
+                and SEND_TIME between #{params.beginSendTime} and #{params.endSendTime}
+            </if>
+            <if test="remark != null  and remark != ''">
+                and REMARK = #{remark}
+            </if>
         </where>
+        order by send_time desc
     </select>
 
     <select id="selectPushRecordByPrId" parameterType="Long"
             resultMap="PushRecordResult">
-            <include refid="selectPushRecordVo"/>
-            where PR_ID = #{prId}
+        <include refid="selectPushRecordVo"/>
+        where PR_ID = #{prId}
     </select>
 
     <insert id="insertPushRecord" parameterType="PushRecord" useGeneratedKeys="true"
             keyProperty="prId">
         insert into push_record
         <trim prefix="(" suffix=")" suffixOverrides=",">
-                    <if test="pushType != null">PUSH_TYPE,
-                    </if>
-                    <if test="alarmLevel != null">ALARM_LEVEL,
-                    </if>
-                    <if test="sendObj != null">SEND_OBJ,
-                    </if>
-                    <if test="sendTitle != null">SEND_TITLE,
-                    </if>
-                    <if test="sendContent != null">SEND_CONTENT,
-                    </if>
-                    <if test="sendSuccess != null">SEND_SUCCESS,
-                    </if>
-                    <if test="sendTime != null">SEND_TIME,
-                    </if>
-                    <if test="remark != null">REMARK,
-                    </if>
+            <if test="pushType != null">PUSH_TYPE,
+            </if>
+            <if test="alarmLevel != null">ALARM_LEVEL,
+            </if>
+            <if test="sendObj != null">SEND_OBJ,
+            </if>
+            <if test="sendTitle != null">SEND_TITLE,
+            </if>
+            <if test="sendContent != null">SEND_CONTENT,
+            </if>
+            <if test="sendSuccess != null">SEND_SUCCESS,
+            </if>
+            <if test="sendTime != null">SEND_TIME,
+            </if>
+            <if test="remark != null">REMARK,
+            </if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
-                    <if test="pushType != null">#{pushType},
-                    </if>
-                    <if test="alarmLevel != null">#{alarmLevel},
-                    </if>
-                    <if test="sendObj != null">#{sendObj},
-                    </if>
-                    <if test="sendTitle != null">#{sendTitle},
-                    </if>
-                    <if test="sendContent != null">#{sendContent},
-                    </if>
-                    <if test="sendSuccess != null">#{sendSuccess},
-                    </if>
-                    <if test="sendTime != null">#{sendTime},
-                    </if>
-                    <if test="remark != null">#{remark},
-                    </if>
+            <if test="pushType != null">#{pushType},
+            </if>
+            <if test="alarmLevel != null">#{alarmLevel},
+            </if>
+            <if test="sendObj != null">#{sendObj},
+            </if>
+            <if test="sendTitle != null">#{sendTitle},
+            </if>
+            <if test="sendContent != null">#{sendContent},
+            </if>
+            <if test="sendSuccess != null">#{sendSuccess},
+            </if>
+            <if test="sendTime != null">#{sendTime},
+            </if>
+            <if test="remark != null">#{remark},
+            </if>
         </trim>
     </insert>
 
     <update id="updatePushRecord" parameterType="PushRecord">
         update push_record
         <trim prefix="SET" suffixOverrides=",">
-                    <if test="pushType != null">PUSH_TYPE =
-                        #{pushType},
-                    </if>
-                    <if test="alarmLevel != null">ALARM_LEVEL =
-                        #{alarmLevel},
-                    </if>
-                    <if test="sendObj != null">SEND_OBJ =
-                        #{sendObj},
-                    </if>
-                    <if test="sendTitle != null">SEND_TITLE =
-                        #{sendTitle},
-                    </if>
-                    <if test="sendContent != null">SEND_CONTENT =
-                        #{sendContent},
-                    </if>
-                    <if test="sendSuccess != null">SEND_SUCCESS =
-                        #{sendSuccess},
-                    </if>
-                    <if test="sendTime != null">SEND_TIME =
-                        #{sendTime},
-                    </if>
-                    <if test="remark != null">REMARK =
-                        #{remark},
-                    </if>
+            <if test="pushType != null">PUSH_TYPE =
+                #{pushType},
+            </if>
+            <if test="alarmLevel != null">ALARM_LEVEL =
+                #{alarmLevel},
+            </if>
+            <if test="sendObj != null">SEND_OBJ =
+                #{sendObj},
+            </if>
+            <if test="sendTitle != null">SEND_TITLE =
+                #{sendTitle},
+            </if>
+            <if test="sendContent != null">SEND_CONTENT =
+                #{sendContent},
+            </if>
+            <if test="sendSuccess != null">SEND_SUCCESS =
+                #{sendSuccess},
+            </if>
+            <if test="sendTime != null">SEND_TIME =
+                #{sendTime},
+            </if>
+            <if test="remark != null">REMARK =
+                #{remark},
+            </if>
         </trim>
         where PR_ID = #{prId}
     </update>
 
     <delete id="deletePushRecordByPrId" parameterType="Long">
         delete
-        from push_record where PR_ID = #{prId}
+        from push_record
+        where PR_ID = #{prId}
     </delete>
 
     <delete id="deletePushRecordByPrIds" parameterType="String">

+ 58 - 58
jjt-quartz/src/main/java/com/jjt/quartz/config/ScheduleConfig.java

@@ -1,58 +1,58 @@
-package com.jjt.quartz.config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Profile;
-import org.springframework.scheduling.quartz.SchedulerFactoryBean;
-
-import javax.sql.DataSource;
-import java.util.Properties;
-
-/**
- * 定时任务配置(单机部署建议删除此类和qrtz数据库表,默认走内存会最高效)
- *
- * @author jjt
- */
-@Configuration
-@Profile({"!junit","!jt"})
-public class ScheduleConfig {
-    @Bean
-    public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
-        SchedulerFactoryBean factory = new SchedulerFactoryBean();
-        factory.setDataSource(dataSource);
-
-        // quartz参数
-        Properties prop = new Properties();
-        prop.put("org.quartz.scheduler.instanceName", "JjtScheduler");
-        prop.put("org.quartz.scheduler.instanceId", "AUTO");
-        // 线程池配置
-        prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
-        prop.put("org.quartz.threadPool.threadCount", "20");
-        prop.put("org.quartz.threadPool.threadPriority", "5");
-        // JobStore配置
-        prop.put("org.quartz.jobStore.class", "org.springframework.scheduling.quartz.LocalDataSourceJobStore");
-        // 集群配置
-        prop.put("org.quartz.jobStore.isClustered", "true");
-        prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
-        prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "10");
-        prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true");
-
-        // sqlserver 启用
-        // prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
-        prop.put("org.quartz.jobStore.misfireThreshold", "12000");
-        prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
-        factory.setQuartzProperties(prop);
-
-        factory.setSchedulerName("JjtScheduler");
-        // 延时启动
-        factory.setStartupDelay(1);
-        factory.setApplicationContextSchedulerContextKey("applicationContextKey");
-        // 可选,QuartzScheduler
-        // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
-        factory.setOverwriteExistingJobs(true);
-        // 设置自动启动,默认为true
-        factory.setAutoStartup(true);
-
-        return factory;
-    }
-}
+//package com.jjt.quartz.config;
+//
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.context.annotation.Profile;
+//import org.springframework.scheduling.quartz.SchedulerFactoryBean;
+//
+//import javax.sql.DataSource;
+//import java.util.Properties;
+//
+///**
+// * 定时任务配置(单机部署建议删除此类和qrtz数据库表,默认走内存会最高效)
+// *
+// * @author jjt
+// */
+//@Configuration
+//@Profile({"!junit","!jt"})
+//public class ScheduleConfig {
+//    @Bean
+//    public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
+//        SchedulerFactoryBean factory = new SchedulerFactoryBean();
+//        factory.setDataSource(dataSource);
+//
+//        // quartz参数
+//        Properties prop = new Properties();
+//        prop.put("org.quartz.scheduler.instanceName", "JjtScheduler");
+//        prop.put("org.quartz.scheduler.instanceId", "AUTO");
+//        // 线程池配置
+//        prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
+//        prop.put("org.quartz.threadPool.threadCount", "20");
+//        prop.put("org.quartz.threadPool.threadPriority", "5");
+//        // JobStore配置
+//        prop.put("org.quartz.jobStore.class", "org.springframework.scheduling.quartz.LocalDataSourceJobStore");
+//        // 集群配置
+//        prop.put("org.quartz.jobStore.isClustered", "true");
+//        prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
+//        prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "10");
+//        prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true");
+//
+//        // sqlserver 启用
+//        // prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
+//        prop.put("org.quartz.jobStore.misfireThreshold", "12000");
+//        prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
+//        factory.setQuartzProperties(prop);
+//
+//        factory.setSchedulerName("JjtScheduler");
+//        // 延时启动
+//        factory.setStartupDelay(1);
+//        factory.setApplicationContextSchedulerContextKey("applicationContextKey");
+//        // 可选,QuartzScheduler
+//        // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
+//        factory.setOverwriteExistingJobs(true);
+//        // 设置自动启动,默认为true
+//        factory.setAutoStartup(true);
+//
+//        return factory;
+//    }
+//}