update: starter-logback-exts 增加主机名等信息的记录

This commit is contained in:
Wizzercn 2019-02-25 16:52:02 +08:00
parent 4b0b42b9b8
commit 32ddcd1060
2 changed files with 86 additions and 0 deletions

View File

@ -14,6 +14,9 @@ import org.nutz.lang.Times;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import java.io.File;
import java.net.InetAddress;
@IocBean
public class LogbackStarter implements ServerFace {
private static final Log log = Logs.get();
@ -37,6 +40,12 @@ public class LogbackStarter implements ServerFace {
@PropDoc(value = "缓存时间", type = "int", defaultValue = "30")
public static final String PROP_LOGLEVEL_KEEPALIVE = PRE + "loglevel.keepalive";
@PropDoc(value = "启用部署监控", defaultValue = "false", type = "boolean")
public static final String PROP_DEPLOY_ENABLED = PRE + "deploy.enabled";
@PropDoc(value = "部署根目录", type = "string")
public static final String PROP_DEPLOY_ROOT = PRE + "deploy.root";
private void initLoglevelConfig() throws Exception {
String name = conf.get(PROP_LOGLEVEL_NAME, conf.get("nutz.application.name", ""));
if (Strings.isBlank(name)) {
@ -48,6 +57,31 @@ public class LogbackStarter implements ServerFace {
loglevelProperty.setHeartbeat(conf.getInt(PROP_LOGLEVEL_HEARTBEAT, 5));
loglevelProperty.setKeepalive(conf.getInt(PROP_LOGLEVEL_KEEPALIVE, 30));
loglevelProperty.setUptime(Times.getTS());
InetAddress addr = InetAddress.getLocalHost();
loglevelProperty.setHostName(addr.getHostName());
loglevelProperty.setHostAddress(addr.getHostAddress());
if (conf.getBoolean(PROP_DEPLOY_ENABLED, false)) {
//为运维中心提供版本信息支持
String root = conf.get(PROP_DEPLOY_ROOT, "/");
loglevelProperty.setAppVersion(getVersion(root, loglevelProperty.getName(), "app"));
loglevelProperty.setConfVersion(getVersion(root, loglevelProperty.getName(), "conf"));
}
}
public String getVersion(String root, String name, String type) {
File f = new File(root, name + "/" + type);
String version = "";
if (f.exists() && f.isDirectory()) {
File[] subDir = f.listFiles();
for (File dir : subDir) {
File versionFile = new File(dir.getAbsolutePath() + "/" + "version");
if (versionFile.exists() && versionFile.isFile()) {
version = dir.getName();
break;
}
}
}
return version;
}
@Override

View File

@ -40,6 +40,26 @@ public class LoglevelProperty {
private long vmMax;
/**
* 主机地址
*/
private String hostAddress;
/**
* 主机名称
*/
private String hostName;
/**
* 启动的jar包版本号
*/
private String appVersion;
/**
* 加载的配置文件版本号
*/
private String confVersion;
public boolean isEnabled() {
return enabled;
}
@ -127,4 +147,36 @@ public class LoglevelProperty {
public void setVmMax(long vmMax) {
this.vmMax = vmMax;
}
public String getHostAddress() {
return hostAddress;
}
public void setHostAddress(String hostAddress) {
this.hostAddress = hostAddress;
}
public String getHostName() {
return hostName;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
public String getAppVersion() {
return appVersion;
}
public void setAppVersion(String appVersion) {
this.appVersion = appVersion;
}
public String getConfVersion() {
return confVersion;
}
public void setConfVersion(String confVersion) {
this.confVersion = confVersion;
}
}