Search in sources :

Example 6 with DtpContext

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);
}
Also used : DtpContext(com.dtp.core.context.DtpContext) NotifyPlatform(com.dtp.common.dto.NotifyPlatform)

Example 7 with DtpContext

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);
}
Also used : DtpContext(com.dtp.core.context.DtpContext) NotifyPlatform(com.dtp.common.dto.NotifyPlatform)

Example 8 with DtpContext

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);
}
Also used : lombok.val(lombok.val) DtpExecutor(com.dtp.core.thread.DtpExecutor) DtpContext(com.dtp.core.context.DtpContext)

Example 9 with DtpContext

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());
}
Also used : NotifyItem(com.dtp.common.dto.NotifyItem) DtpContext(com.dtp.core.context.DtpContext) DtpProperties(com.dtp.common.config.DtpProperties) AlarmInfo(com.dtp.common.dto.AlarmInfo)

Example 10 with DtpContext

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);
}
Also used : DtpContext(com.dtp.core.context.DtpContext) NotifyPlatform(com.dtp.common.dto.NotifyPlatform)

Aggregations

DtpContext (com.dtp.core.context.DtpContext)16 NotifyPlatform (com.dtp.common.dto.NotifyPlatform)10 NotifyItem (com.dtp.common.dto.NotifyItem)3 lombok.val (lombok.val)3 DtpProperties (com.dtp.common.config.DtpProperties)2 DtpMainProp (com.dtp.common.dto.DtpMainProp)2 DtpExecutor (com.dtp.core.thread.DtpExecutor)2 FieldInfo (com.github.dadiyang.equator.FieldInfo)2 AlarmInfo (com.dtp.common.dto.AlarmInfo)1