Search in sources :

Example 1 with NotifyItem

use of com.dtp.common.dto.NotifyItem in project dynamic-tp by lyh200.

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.getExecutor(dtpName);
    List<String> receivers = StrUtil.split(platform.getReceivers(), ',');
    String receivesStr = Joiner.on(", @").join(receivers);
    NotifyItem notifyItem = contextWrapper.getNotifyItem();
    String content = String.format(template, getInstance().getServiceName(), getInstance().getIp() + ":" + getInstance().getPort(), getInstance().getEnv(), executor.getThreadPoolName(), 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(), executor.getRejectCount(), receivesStr, DateUtil.now(), notifyItem.getInterval());
    return highlightAlarmContent(content, typeEnum);
}
Also used : NotifyItem(com.dtp.common.dto.NotifyItem) DtpExecutor(com.dtp.core.thread.DtpExecutor) DtpContext(com.dtp.core.context.DtpContext)

Example 2 with NotifyItem

use of com.dtp.common.dto.NotifyItem in project dynamic-tp by lyh200.

the class AlarmManager method checkReject.

private static boolean checkReject(DtpExecutor executor) {
    NotifyItem notifyItem = NotifyHelper.getNotifyItem(executor, NotifyTypeEnum.REJECT);
    if (Objects.isNull(notifyItem)) {
        return false;
    }
    int rejectCount = executor.getRejectCount();
    return satisfyBaseCondition(notifyItem) && rejectCount >= notifyItem.getThreshold();
}
Also used : NotifyItem(com.dtp.common.dto.NotifyItem)

Example 3 with NotifyItem

use of com.dtp.common.dto.NotifyItem in project dynamic-tp by dromara.

the class NotifyHelper method getNotifyItem.

public static NotifyItem getNotifyItem(DtpExecutor dtpExecutor, NotifyTypeEnum typeEnum) {
    List<NotifyItem> notifyItems = dtpExecutor.getNotifyItems();
    val notifyItemOpt = notifyItems.stream().filter(x -> typeEnum.getValue().equalsIgnoreCase(x.getType()) && x.isEnabled()).findFirst();
    if (!notifyItemOpt.isPresent()) {
        log.debug("DynamicTp notify, no such [{}] notify item configured, threadPoolName: {}", typeEnum.getValue(), dtpExecutor.getThreadPoolName());
        return null;
    }
    return notifyItemOpt.get();
}
Also used : lombok.val(lombok.val) DtpExecutor(com.dtp.core.thread.DtpExecutor) java.util(java.util) NotifyPlatform(com.dtp.common.dto.NotifyPlatform) lombok.val(lombok.val) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) StreamUtil(com.dtp.common.util.StreamUtil) CollUtil(cn.hutool.core.collection.CollUtil) NotifyItem(com.dtp.common.dto.NotifyItem) Slf4j(lombok.extern.slf4j.Slf4j) Collectors.toList(java.util.stream.Collectors.toList) Lists(com.google.common.collect.Lists) ThreadPoolProperties(com.dtp.common.config.ThreadPoolProperties) DtpProperties(com.dtp.common.config.DtpProperties) NotifyTypeEnum(com.dtp.common.em.NotifyTypeEnum) NotifyItem(com.dtp.common.dto.NotifyItem)

Example 4 with NotifyItem

use of com.dtp.common.dto.NotifyItem in project dynamic-tp by dromara.

the class AlarmManager method checkCapacity.

private static boolean checkCapacity(DtpExecutor executor) {
    BlockingQueue<Runnable> workQueue = executor.getQueue();
    if (CollUtil.isEmpty(workQueue)) {
        return false;
    }
    NotifyItem notifyItem = NotifyHelper.getNotifyItem(executor, NotifyTypeEnum.CAPACITY);
    if (Objects.isNull(notifyItem)) {
        return false;
    }
    int queueCapacity = executor.getQueueCapacity();
    double div = NumberUtil.div(workQueue.size(), queueCapacity, 2) * 100;
    return satisfyBaseCondition(notifyItem) && div >= notifyItem.getThreshold();
}
Also used : NotifyItem(com.dtp.common.dto.NotifyItem)

Example 5 with NotifyItem

use of com.dtp.common.dto.NotifyItem 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)

Aggregations

NotifyItem (com.dtp.common.dto.NotifyItem)15 AlarmInfo (com.dtp.common.dto.AlarmInfo)4 DtpProperties (com.dtp.common.config.DtpProperties)3 DtpContext (com.dtp.core.context.DtpContext)3 DtpExecutor (com.dtp.core.thread.DtpExecutor)2 CollUtil (cn.hutool.core.collection.CollUtil)1 ThreadPoolProperties (com.dtp.common.config.ThreadPoolProperties)1 NotifyPlatform (com.dtp.common.dto.NotifyPlatform)1 NotifyTypeEnum (com.dtp.common.em.NotifyTypeEnum)1 StreamUtil (com.dtp.common.util.StreamUtil)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Slf4j (lombok.extern.slf4j.Slf4j)1 lombok.val (lombok.val)1