mirror of
https://github.com/dromara/hertzbeat.git
synced 2026-09-17 09:40:58 +00:00
[feature] add column version and public Ip on collector page (#2072)
Co-authored-by: tomsun28 <tomsun28@outlook.com>
This commit is contained in:
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hertzbeat.collector.dispatch;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Collector info configuration Properties
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = CollectorInfoProperties.INFO_PREFIX)
|
||||
public class CollectorInfoProperties {
|
||||
protected static final String INFO_PREFIX = "collector.info";
|
||||
|
||||
private String version;
|
||||
private String ip;
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
}
|
||||
+29
-4
@@ -24,6 +24,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.hertzbeat.collector.dispatch.CollectorInfoProperties;
|
||||
import org.apache.hertzbeat.collector.dispatch.DispatchProperties;
|
||||
import org.apache.hertzbeat.collector.dispatch.entrance.internal.CollectJobService;
|
||||
import org.apache.hertzbeat.collector.dispatch.entrance.processor.CollectCyclicDataProcessor;
|
||||
@@ -66,10 +67,13 @@ public class CollectServer implements CommandLineRunner {
|
||||
|
||||
private ScheduledExecutorService scheduledExecutor;
|
||||
|
||||
private Info info;
|
||||
|
||||
public CollectServer(final CollectJobService collectJobService,
|
||||
final TimerDispatch timerDispatch,
|
||||
final DispatchProperties properties,
|
||||
final CommonThreadPool threadPool) {
|
||||
final CommonThreadPool threadPool,
|
||||
final CollectorInfoProperties infoProperties) {
|
||||
if (properties == null || properties.getEntrance() == null || properties.getEntrance().getNetty() == null) {
|
||||
log.error("init error, please config dispatch entrance netty props in application.yml");
|
||||
throw new IllegalArgumentException("please config dispatch entrance netty props");
|
||||
@@ -81,14 +85,15 @@ public class CollectServer implements CommandLineRunner {
|
||||
this.collectJobService = collectJobService;
|
||||
this.timerDispatch = timerDispatch;
|
||||
this.collectJobService.setCollectServer(this);
|
||||
this.init(properties, threadPool);
|
||||
this.init(properties, threadPool, infoProperties);
|
||||
}
|
||||
|
||||
private void init(final DispatchProperties properties, final CommonThreadPool threadPool) {
|
||||
private void init(final DispatchProperties properties, final CommonThreadPool threadPool, final CollectorInfoProperties infoProperties) {
|
||||
NettyClientConfig nettyClientConfig = new NettyClientConfig();
|
||||
DispatchProperties.EntranceProperties.NettyProperties nettyProperties = properties.getEntrance().getNetty();
|
||||
nettyClientConfig.setServerHost(nettyProperties.getManagerHost());
|
||||
nettyClientConfig.setServerPort(nettyProperties.getManagerPort());
|
||||
this.initInfo(infoProperties);
|
||||
this.remotingClient = new NettyRemotingClient(nettyClientConfig, new CollectNettyEventListener(), threadPool);
|
||||
|
||||
this.remotingClient.registerProcessor(ClusterMsg.MessageType.HEARTBEAT, new HeartbeatProcessor());
|
||||
@@ -130,8 +135,9 @@ public class CollectServer implements CommandLineRunner {
|
||||
String mode = CollectServer.this.collectJobService.getCollectorMode();
|
||||
CollectorInfo collectorInfo = CollectorInfo.builder()
|
||||
.name(identity)
|
||||
.ip(IpDomainUtil.getLocalhostIp())
|
||||
.ip(info.ip)
|
||||
.mode(mode)
|
||||
.version(info.version)
|
||||
// todo more info
|
||||
.build();
|
||||
timerDispatch.goOnline();
|
||||
@@ -175,4 +181,23 @@ public class CollectServer implements CommandLineRunner {
|
||||
log.info("handle idle event triggered. collector is going offline.");
|
||||
}
|
||||
}
|
||||
|
||||
private void initInfo(final CollectorInfoProperties infoProperties) {
|
||||
info = new Info();
|
||||
info.setVersion(infoProperties.getVersion());
|
||||
info.setIp(IpDomainUtil.getIpFromEnvOrDefault(infoProperties.getIp(), IpDomainUtil.getLocalhostIp()));
|
||||
}
|
||||
|
||||
private static class Info {
|
||||
private String version;
|
||||
private String ip;
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,9 @@ spring:
|
||||
on-profile: cluster
|
||||
|
||||
collector:
|
||||
info:
|
||||
version: 1.5.0
|
||||
ip: IP
|
||||
dispatch:
|
||||
entrance:
|
||||
netty:
|
||||
|
||||
@@ -40,7 +40,9 @@ public class CollectorInfo {
|
||||
|
||||
@NotNull
|
||||
private String ip;
|
||||
|
||||
|
||||
private String version;
|
||||
|
||||
@NotNull
|
||||
private String mode = CommonConstants.MODE_PUBLIC;
|
||||
}
|
||||
|
||||
@@ -64,6 +64,9 @@ public class Collector {
|
||||
@NotNull
|
||||
private String ip;
|
||||
|
||||
@Schema(title = "collector version", description = "collector version")
|
||||
private String version;
|
||||
|
||||
@Schema(title = "collector status: 0-online 1-offline")
|
||||
@Min(0)
|
||||
private byte status;
|
||||
|
||||
@@ -107,6 +107,10 @@ public final class IpDomainUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getIpFromEnvOrDefault(String env, String defaultIp) {
|
||||
return System.getenv().getOrDefault(env, defaultIp);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ipDomain ip domain
|
||||
|
||||
+3
@@ -107,6 +107,7 @@ public class CollectorJobScheduler implements CollectorScheduling, CollectJobSch
|
||||
if (collectorInfo != null) {
|
||||
collector.setIp(collectorInfo.getIp());
|
||||
collector.setMode(collectorInfo.getMode());
|
||||
collector.setVersion(collectorInfo.getVersion());
|
||||
}
|
||||
} else {
|
||||
if (collectorInfo == null) {
|
||||
@@ -117,6 +118,7 @@ public class CollectorJobScheduler implements CollectorScheduling, CollectJobSch
|
||||
.name(identity)
|
||||
.ip(collectorInfo.getIp())
|
||||
.mode(collectorInfo.getMode())
|
||||
.version(collectorInfo.getVersion())
|
||||
.status(CommonConstants.COLLECTOR_STATUS_ONLINE)
|
||||
.build();
|
||||
}
|
||||
@@ -267,6 +269,7 @@ public class CollectorJobScheduler implements CollectorScheduling, CollectJobSch
|
||||
CollectorInfo collectorInfo = CollectorInfo.builder()
|
||||
.name(collector.getName())
|
||||
.ip(collector.getIp())
|
||||
.version(collector.getVersion())
|
||||
.mode(collector.getMode())
|
||||
.build();
|
||||
this.collectorGoOnline(identity, collectorInfo);
|
||||
|
||||
@@ -57,7 +57,8 @@ public class SchedulerInit implements CommandLineRunner {
|
||||
private CollectJobScheduling collectJobScheduling;
|
||||
|
||||
private static final String MAIN_COLLECTOR_NODE_IP = "127.0.0.1";
|
||||
|
||||
private static final String DEFAULT_COLLECTOR_VERSION = "DEBUG";
|
||||
|
||||
@Autowired
|
||||
private AppService appService;
|
||||
|
||||
@@ -84,6 +85,7 @@ public class SchedulerInit implements CommandLineRunner {
|
||||
CollectorInfo collectorInfo = CollectorInfo.builder()
|
||||
.name(CommonConstants.MAIN_COLLECTOR_NODE)
|
||||
.ip(MAIN_COLLECTOR_NODE_IP)
|
||||
.version(DEFAULT_COLLECTOR_VERSION)
|
||||
.build();
|
||||
collectorScheduling.collectorGoOnline(CommonConstants.MAIN_COLLECTOR_NODE, collectorInfo);
|
||||
// init jobs
|
||||
|
||||
@@ -21,6 +21,7 @@ export class Collector {
|
||||
id!: number;
|
||||
name!: string;
|
||||
ip!: string;
|
||||
version!: string;
|
||||
// public or private
|
||||
mode!: string;
|
||||
// collector status: 0-online 1-offline
|
||||
|
||||
@@ -90,6 +90,7 @@
|
||||
<th nzAlign="center" nzWidth="9%">{{ 'collector.pinned' | i18n }}</th>
|
||||
<th nzAlign="center" nzWidth="9%">{{ 'collector.dispatched' | i18n }}</th>
|
||||
<th nzAlign="center" nzWidth="12%">{{ 'collector.ip' | i18n }}</th>
|
||||
<th nzAlign="center" nzWidth="12%">{{ 'collector.version' | i18n }}</th>
|
||||
<th nzAlign="center" nzWidth="12%">{{ 'collector.start-time' | i18n }}</th>
|
||||
<th nzAlign="center" nzWidth="13%">{{ 'common.edit' | i18n }}</th>
|
||||
</tr>
|
||||
@@ -130,6 +131,7 @@
|
||||
</nz-tag>
|
||||
</td>
|
||||
<td nzAlign="center">{{ data.collector.ip }}</td>
|
||||
<td nzAlign="center">{{ data.collector.version }}</td>
|
||||
<td nzAlign="center">
|
||||
{{ (data.collector.gmtUpdate | date : 'YYYY-MM-dd HH:mm:ss')?.trim() }}
|
||||
</td>
|
||||
|
||||
@@ -573,6 +573,7 @@
|
||||
"collector.task": "Total Tasks",
|
||||
"collector.start-time": "Start Time",
|
||||
"collector.ip": "IP Address",
|
||||
"collector.version": "Version",
|
||||
"collector.node": "Node Name",
|
||||
"collector.pinned": "Pinned Tasks",
|
||||
"collector.dispatched": "Dispatched Tasks",
|
||||
|
||||
@@ -574,6 +574,7 @@
|
||||
"collector.task": "总任务数量",
|
||||
"collector.start-time": "启动时间",
|
||||
"collector.ip": "IP地址",
|
||||
"collector.version": "版本",
|
||||
"collector.node": "节点名称",
|
||||
"collector.pinned": "固定任务",
|
||||
"collector.dispatched": "调度任务",
|
||||
|
||||
@@ -571,6 +571,7 @@
|
||||
"collector.mode.private": "私有云邊模式",
|
||||
"collector.start-time": "啟動時間",
|
||||
"collector.ip": "IP地址",
|
||||
"collector.version": "版本",
|
||||
"collector.node": "節點名稱",
|
||||
"collector.pinned": "固定任務",
|
||||
"collector.dispatched": "調度任務",
|
||||
|
||||
Reference in New Issue
Block a user