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);
}
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();
}
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();
}
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();
}
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());
}
Aggregations