修改钉钉通知消息体, 增加应用实例标识.

pull/10/head
chen.ma 3 years ago
parent a65df935ea
commit a84e1b4fa9

@ -69,6 +69,7 @@ public class DingSendMessageHandler implements SendMessageHandler {
"<font color='#FF0000'>[警报] </font>%s - 动态线程池运行告警 \n\n" + "<font color='#FF0000'>[警报] </font>%s - 动态线程池运行告警 \n\n" +
" --- \n\n " + " --- \n\n " +
"<font color='#708090' size=2>线程池ID%s</font> \n\n " + "<font color='#708090' size=2>线程池ID%s</font> \n\n " +
"<font color='#708090' size=2>应用名称:%s</font> \n\n " +
"<font color='#778899' size=2>应用实例:%s</font> \n\n " + "<font color='#778899' size=2>应用实例:%s</font> \n\n " +
" --- \n\n " + " --- \n\n " +
"<font color='#708090' size=2>核心线程数:%d</font> \n\n " + "<font color='#708090' size=2>核心线程数:%d</font> \n\n " +
@ -94,8 +95,10 @@ public class DingSendMessageHandler implements SendMessageHandler {
active.toUpperCase(), active.toUpperCase(),
// 线程池ID // 线程池ID
pool.getThreadPoolId(), pool.getThreadPoolId(),
// 节点信息 // 应用名称
instanceInfo.getIpApplicationName(), instanceInfo.getAppName(),
// 实例信息
instanceInfo.getIdentify(),
// 核心线程数 // 核心线程数
pool.getCorePoolSize(), pool.getCorePoolSize(),
// 最大线程数 // 最大线程数
@ -150,6 +153,7 @@ public class DingSendMessageHandler implements SendMessageHandler {
"<font color='#2a9d8f'>[通知] </font>%s - 动态线程池参数变更 \n\n" + "<font color='#2a9d8f'>[通知] </font>%s - 动态线程池参数变更 \n\n" +
" --- \n\n " + " --- \n\n " +
"<font color='#708090' size=2>线程池ID%s</font> \n\n " + "<font color='#708090' size=2>线程池ID%s</font> \n\n " +
"<font color='#708090' size=2>应用名称:%s</font> \n\n " +
"<font color='#778899' size=2>应用实例:%s</font> \n\n " + "<font color='#778899' size=2>应用实例:%s</font> \n\n " +
" --- \n\n " + " --- \n\n " +
"<font color='#708090' size=2>核心线程数:%s</font> \n\n " + "<font color='#708090' size=2>核心线程数:%s</font> \n\n " +
@ -170,8 +174,10 @@ public class DingSendMessageHandler implements SendMessageHandler {
active.toUpperCase(), active.toUpperCase(),
// 线程池名称 // 线程池名称
threadPoolId, threadPoolId,
// 节点信息 // 应用名称
instanceInfo.getIpApplicationName(), instanceInfo.getAppName(),
// 实例信息
instanceInfo.getIdentify(),
// 核心线程数 // 核心线程数
customPool.getCorePoolSize() + " ➲ " + parameter.getCoreSize(), customPool.getCorePoolSize() + " ➲ " + parameter.getCoreSize(),
// 最大线程数 // 最大线程数

@ -35,8 +35,8 @@ public class DiscoveryConfig {
@SneakyThrows @SneakyThrows
public InstanceInfo instanceConfig() { public InstanceInfo instanceConfig() {
InstanceInfo instanceInfo = new InstanceInfo(); InstanceInfo instanceInfo = new InstanceInfo();
instanceInfo.setInstanceId(getDefaultInstanceId(environment)) instanceInfo.setInstanceId(getDefaultInstanceId(environment, inetUtils))
.setIpApplicationName(getIpApplicationName(environment)) .setIpApplicationName(getIpApplicationName(environment, inetUtils))
.setHostName(InetAddress.getLocalHost().getHostAddress()) .setHostName(InetAddress.getLocalHost().getHostAddress())
.setGroupKey(properties.getItemId() + "+" + properties.getNamespace()) .setGroupKey(properties.getItemId() + "+" + properties.getNamespace())
.setAppName(environment.getProperty("spring.application.name")) .setAppName(environment.getProperty("spring.application.name"))

@ -1,10 +1,9 @@
package cn.hippo4j.starter.toolkit; package cn.hippo4j.starter.toolkit;
import cn.hippo4j.starter.toolkit.inet.InetUtils;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.springframework.core.env.PropertyResolver; import org.springframework.core.env.PropertyResolver;
import java.net.InetAddress;
/** /**
* Cloud common id util. * Cloud common id util.
* *
@ -16,16 +15,15 @@ public class CloudCommonIdUtil {
private static final String SEPARATOR = ":"; private static final String SEPARATOR = ":";
@SneakyThrows @SneakyThrows
public static String getDefaultInstanceId(PropertyResolver resolver) { public static String getDefaultInstanceId(PropertyResolver resolver, InetUtils inetUtils) {
String namePart = getIpApplicationName(resolver); String namePart = getIpApplicationName(resolver, inetUtils);
String indexPart = resolver.getProperty("spring.application.instance_id", resolver.getProperty("server.port")); String indexPart = resolver.getProperty("spring.application.instance_id", resolver.getProperty("server.port"));
return combineParts(namePart, SEPARATOR, indexPart); return combineParts(namePart, SEPARATOR, indexPart);
} }
@SneakyThrows @SneakyThrows
public static String getIpApplicationName(PropertyResolver resolver) { public static String getIpApplicationName(PropertyResolver resolver, InetUtils inetUtils) {
InetAddress host = InetAddress.getLocalHost(); String hostname = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
String hostname = host.getHostAddress();
String appName = resolver.getProperty("spring.application.name"); String appName = resolver.getProperty("spring.application.name");
return combineParts(hostname, SEPARATOR, appName); return combineParts(hostname, SEPARATOR, appName);
} }

Loading…
Cancel
Save