use of com.dtp.core.context.DtpContext in project dynamic-tp by dromara.
the class DtpLarkNotifier method sendAlarmMsg.
@Override
public void sendAlarmMsg(NotifyTypeEnum typeEnum) {
DtpContext contextWrapper = DtpContextHolder.get();
NotifyPlatform platform = contextWrapper.getPlatform(NotifyPlatformEnum.LARK.name());
String content = buildAlarmContent(platform, typeEnum, LARK_ALARM_JSON_STR);
if (StringUtils.isBlank(content)) {
return;
}
doSend(platform, content);
}
use of com.dtp.core.context.DtpContext in project dynamic-tp by dromara.
the class DtpWechatNotifier method sendAlarmMsg.
@Override
public void sendAlarmMsg(NotifyTypeEnum typeEnum) {
DtpContext contextWrapper = DtpContextHolder.get();
NotifyPlatform platform = contextWrapper.getPlatform(NotifyPlatformEnum.WECHAT.name());
String content = buildAlarmContent(platform, typeEnum, WECHAT_ALARM_TEMPLATE);
if (StringUtils.isBlank(content)) {
return;
}
doSend(platform, content);
}
use of com.dtp.core.context.DtpContext in project dynamic-tp by dromara.
the class AbstractNotifier method buildAlarmContent.
public String buildAlarmContent(NotifyPlatform platform, NotifyTypeEnum typeEnum, String template) {
DtpContext contextWrapper = DtpContextHolder.get();
String dtpName = contextWrapper.getDtpExecutor().getThreadPoolName();
DtpExecutor executor = DtpRegistry.getDtpExecutor(dtpName);
String receivesStr = getReceives(platform.getPlatform(), platform.getReceivers());
NotifyItem notifyItem = contextWrapper.getNotifyItem();
AlarmInfo alarmInfo = contextWrapper.getAlarmInfo();
val triple = AlarmCounter.countNotifyItems(dtpName);
String content = String.format(template, getInstance().getServiceName(), getInstance().getIp() + ":" + getInstance().getPort(), getInstance().getEnv(), populatePoolName(executor), typeEnum.getValue(), notifyItem.getThreshold(), executor.getCorePoolSize(), executor.getMaximumPoolSize(), executor.getPoolSize(), executor.getActiveCount(), executor.getLargestPoolSize(), executor.getTaskCount(), executor.getCompletedTaskCount(), executor.getQueue().size(), executor.getQueueName(), executor.getQueueCapacity(), executor.getQueue().size(), executor.getQueue().remainingCapacity(), executor.getRejectHandlerName(), triple.getLeft() + "/" + executor.getRejectCount(), triple.getMiddle() + "/" + executor.getRunTimeoutCount(), triple.getRight() + "/" + executor.getQueueTimeoutCount(), alarmInfo.getLastAlarmTime() == null ? UNKNOWN : alarmInfo.getLastAlarmTime(), DateUtil.now(), receivesStr, notifyItem.getInterval());
return highlightAlarmContent(content, typeEnum);
}
use of com.dtp.core.context.DtpContext in project dynamic-tp by dromara.
the class AlarmManager method doAlarm.
public static void doAlarm(DtpExecutor executor, NotifyTypeEnum typeEnum) {
if (!preCheck(executor, typeEnum)) {
return;
}
boolean ifAlarm = AlarmLimiter.ifAlarm(executor, typeEnum.getValue());
if (!ifAlarm) {
log.debug("DynamicTp notify, alarm limit, dtpName: {}, type: {}", executor.getThreadPoolName(), typeEnum.getValue());
return;
}
DtpProperties dtpProperties = ApplicationContextHolder.getBean(DtpProperties.class);
NotifyItem notifyItem = NotifyHelper.getNotifyItem(executor, typeEnum);
if (Objects.isNull(notifyItem)) {
return;
}
synchronized (SEND_LOCK) {
// recheck alarm limit.
ifAlarm = AlarmLimiter.ifAlarm(executor, typeEnum.getValue());
if (!ifAlarm) {
log.warn("DynamicTp notify, concurrent send, alarm limit, dtpName: {}, type: {}", executor.getThreadPoolName(), typeEnum.getValue());
return;
}
AlarmLimiter.putVal(executor, typeEnum.getValue());
}
AlarmInfo alarmInfo = AlarmCounter.getAlarmInfo(executor.getThreadPoolName(), notifyItem.getType());
DtpContext dtpContext = DtpContext.builder().dtpExecutor(executor).platforms(dtpProperties.getPlatforms()).notifyItem(notifyItem).alarmInfo(alarmInfo).build();
DtpContextHolder.set(dtpContext);
NotifierHandler.getInstance().sendAlarm(typeEnum);
AlarmCounter.reset(executor.getThreadPoolName(), notifyItem.getType());
}
use of com.dtp.core.context.DtpContext in project dynamic-tp by dromara.
the class DtpDingNotifier method sendChangeMsg.
@Override
public void sendChangeMsg(DtpMainProp oldProp, List<String> diffs) {
DtpContext contextWrapper = DtpContextHolder.get();
NotifyPlatform platform = contextWrapper.getPlatform(NotifyPlatformEnum.DING.name());
String content = buildNoticeContent(platform, DING_CHANGE_NOTICE_TEMPLATE, oldProp, diffs);
if (StringUtils.isBlank(content)) {
return;
}
List<String> receivesList = StrUtil.split(platform.getReceivers(), ',');
doSend(platform, DING_NOTICE_TITLE, content, receivesList);
}
Aggregations