mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: optimize server info
This commit is contained in:
parent
d9b1272802
commit
1c60f17b1b
@ -15,5 +15,7 @@ public class ServerInfo {
|
||||
|
||||
private String ip;
|
||||
|
||||
private long bornTime;
|
||||
|
||||
private String version = "UNKNOWN";
|
||||
}
|
||||
|
@ -1,22 +1,20 @@
|
||||
package tech.powerjob.server.remote.server.self;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.info.BuildProperties;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tech.powerjob.common.exception.PowerJobException;
|
||||
import tech.powerjob.common.utils.CommonUtils;
|
||||
import tech.powerjob.common.utils.NetUtils;
|
||||
import tech.powerjob.server.common.constants.PJThreadPool;
|
||||
import tech.powerjob.server.common.module.ServerInfo;
|
||||
import tech.powerjob.server.extension.LockService;
|
||||
import tech.powerjob.server.persistence.remote.model.ServerInfoDO;
|
||||
import tech.powerjob.server.persistence.remote.repository.ServerInfoRepository;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@ -50,6 +48,7 @@ public class ServerInfoServiceImpl implements ServerInfoService {
|
||||
|
||||
String ip = NetUtils.getLocalHost();
|
||||
serverInfo.setIp(ip);
|
||||
serverInfo.setBornTime(System.currentTimeMillis());
|
||||
this.serverInfoRepository = serverInfoRepository;
|
||||
|
||||
Stopwatch sw = Stopwatch.createStarted();
|
||||
|
@ -11,6 +11,8 @@ import tech.powerjob.common.request.ServerDiscoveryRequest;
|
||||
import tech.powerjob.common.response.ResultDTO;
|
||||
import tech.powerjob.common.utils.CommonUtils;
|
||||
import tech.powerjob.common.utils.NetUtils;
|
||||
import tech.powerjob.server.common.aware.ServerInfoAware;
|
||||
import tech.powerjob.server.common.module.ServerInfo;
|
||||
import tech.powerjob.server.persistence.remote.model.AppInfoDO;
|
||||
import tech.powerjob.server.persistence.remote.repository.AppInfoRepository;
|
||||
import tech.powerjob.server.remote.server.election.ServerElectionService;
|
||||
@ -30,8 +32,9 @@ import java.util.TimeZone;
|
||||
@RestController
|
||||
@RequestMapping("/server")
|
||||
@RequiredArgsConstructor
|
||||
public class ServerController {
|
||||
public class ServerController implements ServerInfoAware {
|
||||
|
||||
private ServerInfo serverInfo;
|
||||
private final TransportService transportService;
|
||||
|
||||
private final ServerElectionService serverElectionService;
|
||||
@ -56,15 +59,25 @@ public class ServerController {
|
||||
public ResultDTO<JSONObject> ping(@RequestParam(required = false) boolean debug) {
|
||||
JSONObject res = new JSONObject();
|
||||
res.put("localHost", NetUtils.getLocalHost());
|
||||
res.put("defaultAddress", transportService.defaultProtocol());
|
||||
res.put("serverInfo", serverInfo);
|
||||
res.put("serverTime", CommonUtils.formatTime(System.currentTimeMillis()));
|
||||
res.put("serverTimeTs", System.currentTimeMillis());
|
||||
res.put("serverTimeZone", TimeZone.getDefault().getDisplayName());
|
||||
res.put("appIds", workerClusterQueryService.getAppId2ClusterStatus().keySet());
|
||||
if (debug) {
|
||||
res.put("appId2ClusterInfo", JSON.parseObject(JSON.toJSONString(workerClusterQueryService.getAppId2ClusterStatus())));
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
res.put("defaultAddress", JSONObject.toJSON(transportService.defaultProtocol()));
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
|
||||
return ResultDTO.success(res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setServerInfo(ServerInfo serverInfo) {
|
||||
this.serverInfo = serverInfo;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user