|
@@ -9,6 +9,8 @@ import com.jjt.biz.mapper.BizObjMetricsDataMapper;
|
|
|
import com.jjt.biz.mapper.BizObjMetricsMapper;
|
|
|
import com.jjt.biz.service.*;
|
|
|
import com.jjt.biz.vo.AgentVO;
|
|
|
+import com.jjt.common.constant.CacheConstants;
|
|
|
+import com.jjt.common.core.redis.RedisCache;
|
|
|
import com.jjt.common.exception.ServiceException;
|
|
|
import com.jjt.common.utils.DateUtils;
|
|
|
import com.jjt.common.utils.StringUtils;
|
|
@@ -71,6 +73,8 @@ public class BizObjMetricsServiceImpl implements IBizObjMetricsService {
|
|
|
private IBizObjMcService mcService;
|
|
|
@Resource
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
+ @Resource
|
|
|
+ private RedisCache redisCache;
|
|
|
|
|
|
/**
|
|
|
* 查询业务对象指标
|
|
@@ -91,7 +95,17 @@ public class BizObjMetricsServiceImpl implements IBizObjMetricsService {
|
|
|
*/
|
|
|
@Override
|
|
|
public List<BizObjMetrics> selectBizObjMetricsList(BizObjMetrics bizObjMetrics) {
|
|
|
- return bizObjMetricsMapper.selectBizObjMetricsList(bizObjMetrics);
|
|
|
+ List<BizObjMetrics> list = bizObjMetricsMapper.selectBizObjMetricsList(bizObjMetrics);
|
|
|
+ list.forEach(om -> {
|
|
|
+ String redisKey = CacheConstants.METRICS_D_VALUE + om.getObjMetricsId();
|
|
|
+ String dValue = redisCache.getCacheObject(redisKey);
|
|
|
+ if (StringUtils.isNotEmpty(dValue)) {
|
|
|
+ om.setDValue(new BigDecimal(dValue));
|
|
|
+ } else {
|
|
|
+ om.setDValue(null);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -454,7 +468,32 @@ public class BizObjMetricsServiceImpl implements IBizObjMetricsService {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- batchUpdate(metricsToUpdate, dataList, addRList, updateRList, addEList, updateEList);
|
|
|
+ batchUpdate(null, dataList, addRList, updateRList, addEList, updateEList);
|
|
|
+// Map<Long, BigDecimal> updateMap = new HashMap<>();
|
|
|
+ metricsToUpdate.forEach(mo -> {
|
|
|
+ String redisKey = CacheConstants.METRICS_D_VALUE + mo.getObjMetricsId();
|
|
|
+ redisCache.setCacheObject(redisKey, mo.getDValue().toString());
|
|
|
+// updateMap.put(up.getObjMetricsId(), up.getDValue());
|
|
|
+ });
|
|
|
+// if (updateMap.size() > 0) {
|
|
|
+// // 使用Redis存储最新指标数据,避免数据库死锁问题
|
|
|
+// // 批量更新Redis中的指标值
|
|
|
+// updateMap.forEach((metricsId, value) -> {
|
|
|
+//// Map<String, String> metricData = new HashMap<>();
|
|
|
+//// metricData.put("dValue", value.toString());
|
|
|
+//// metricData.put("updateTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, updateTime));
|
|
|
+// // 存储到Redis,设置过期时间(例如:1小时)
|
|
|
+// // 注意:这里需要注入RedisTemplate或相关Redis操作类
|
|
|
+//// redisTemplate.opsForHash().putAll(redisKey, metricData);
|
|
|
+// // redisTemplate.expire(redisKey, 3600, TimeUnit.SECONDS);
|
|
|
+// });
|
|
|
+
|
|
|
+ // 同时更新数据库(可选,根据业务需求决定是否保留)
|
|
|
+// jdbcTemplate.batchUpdate("update biz_obj_metrics set d_value = ?, UPDATE_TIME = ? where obj_metrics_id = ?",
|
|
|
+// updateMap.entrySet().stream()
|
|
|
+// .map(entry -> new Object[]{entry.getValue(), updateTime, entry.getKey()})
|
|
|
+// .collect(Collectors.toList()));
|
|
|
+// }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -539,7 +578,7 @@ public class BizObjMetricsServiceImpl implements IBizObjMetricsService {
|
|
|
updateEList.add(eMap.get("update"));
|
|
|
}
|
|
|
});
|
|
|
- batchUpdate(metricsToUpdate, dataList, addRList, updateRList, addEList, updateEList);
|
|
|
+ batchUpdate(null, dataList, addRList, updateRList, addEList, updateEList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -798,10 +837,14 @@ public class BizObjMetricsServiceImpl implements IBizObjMetricsService {
|
|
|
updateJvmMetrics(objId, agentVOList, date, recordMap, eventMap, updateMap);
|
|
|
updateLinkMetrics(objId, pinpointVOList, date, recordMap, eventMap, updateMap);
|
|
|
if (updateMap.size() > 0) {
|
|
|
- jdbcTemplate.batchUpdate("update biz_obj_metrics set d_value = ?, UPDATE_TIME = ? where obj_metrics_id = ?",
|
|
|
- updateMap.entrySet().stream()
|
|
|
- .map(entry -> new Object[]{entry.getValue(), new Date(), entry.getKey()})
|
|
|
- .collect(Collectors.toList()));
|
|
|
+ updateMap.forEach((key, value) -> {
|
|
|
+ String redisKey = CacheConstants.METRICS_D_VALUE + key;
|
|
|
+ redisCache.setCacheObject(redisKey, value.toString());
|
|
|
+ });
|
|
|
+// jdbcTemplate.batchUpdate("update biz_obj_metrics set d_value = ?, UPDATE_TIME = ? where obj_metrics_id = ?",
|
|
|
+// updateMap.entrySet().stream()
|
|
|
+// .map(entry -> new Object[]{entry.getValue(), new Date(), entry.getKey()})
|
|
|
+// .collect(Collectors.toList()));
|
|
|
}
|
|
|
}
|
|
|
|