Compare commits
13 Commits
dev-3.3
...
rel-22.10.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de3347b3c5 | ||
|
|
27f46633fc | ||
|
|
bdede80059 | ||
|
|
12a9e25835 | ||
|
|
77394e8ab9 | ||
|
|
128d4f8418 | ||
|
|
d23a48be48 | ||
|
|
e70e687298 | ||
|
|
4eddf0e0dc | ||
|
|
fca66d553f | ||
|
|
1b998e9100 | ||
|
|
b47a61f605 | ||
|
|
42589f6477 |
@@ -2,7 +2,7 @@
|
||||
image: git.mesalab.cn:7443/nezha/nz-build-env:1.3
|
||||
# 定义全局变量
|
||||
variables:
|
||||
MINIO_HOST: 'http://192.168.41.160:2020/'
|
||||
MINIO_HOST: 'http://192.168.40.48:2020/'
|
||||
MINIO_USER: 'admin'
|
||||
MINIO_PWD: "Nezha@02!"
|
||||
MAVEN_REPO: "/etc/maven/repository/"
|
||||
@@ -55,8 +55,19 @@ dev_build:
|
||||
script:
|
||||
- env | sort
|
||||
- pwd
|
||||
- export FILE_NAME=$CI_PROJECT_NAME-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA.tar.gz
|
||||
- export BRANCH_ARRAY=(${CI_COMMIT_REF_NAME//-/ })
|
||||
- echo -e "version=${BRANCH_ARRAY[1]}\ncommit=$CI_COMMIT_SHORT_SHA\nbuildDate=`date +'%Y%m%d%H%m%S'`" >>./src/main/resources/version.properties
|
||||
- mvn clean install -Dxjar.password=111111 -Dxjar.excludes=/db/*,/static/**/*
|
||||
- cd ./target && go build xjar.go && cd ..
|
||||
- cd ./target
|
||||
- go build xjar.go
|
||||
- chmod +x xjar
|
||||
- "git log -100 --pretty=format:'%ad : %s' >> git-log.html"
|
||||
- tar -zcvf $FILE_NAME xjar nz-talon.xjar git-log.html
|
||||
- mc alias set nz $MINIO_HOST $MINIO_USER $MINIO_PWD
|
||||
- mc cp $FILE_NAME nz/ci-cd/nz-talon/$FILE_NAME
|
||||
- mc cp $FILE_NAME nz/ci-cd/nz-talon/$CI_PROJECT_NAME-$CI_COMMIT_REF_NAME-latest.tar.gz
|
||||
- cd ../
|
||||
artifacts:
|
||||
name: "$CI_PROJECT_NAME-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA"
|
||||
when: on_success
|
||||
|
||||
7
pom.xml
7
pom.xml
@@ -48,6 +48,11 @@
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.45</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.oshi</groupId>
|
||||
<artifactId>oshi-core</artifactId>
|
||||
<version>6.2.2</version>
|
||||
</dependency>
|
||||
<!-- 添加 XJar 依赖 -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.github.core-lib</groupId>-->
|
||||
@@ -144,7 +149,7 @@
|
||||
<pluginRepository>
|
||||
<id>nexus</id>
|
||||
<name>Team Nexus Repository</name>
|
||||
<url>http://192.168.40.125:8099/content/groups/public/</url>
|
||||
<url>http://192.168.40.153:8099/content/groups/public/</url>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>public</id>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package net.geedge.confagent.controller;
|
||||
|
||||
|
||||
import net.geedge.confagent.util.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
public class OSHIController extends BaseController{
|
||||
|
||||
@GetMapping("/oshi/info")
|
||||
public R getSystemInfo(HttpServletRequest request){
|
||||
|
||||
Map<String, Object> systemInfo = OSHIUtils.getSystemInfo();
|
||||
|
||||
return R.ok(systemInfo);
|
||||
}
|
||||
|
||||
@GetMapping("/oshi/process")
|
||||
public R getProcessInfo(HttpServletRequest request) throws InterruptedException {
|
||||
|
||||
List<Map> result = OSHIUtils.getProcessInfo();
|
||||
HashMap<Object, Object> data = Tool.MapUtil.newHashMap();
|
||||
data.put("list" ,result);
|
||||
|
||||
return R.ok(data);
|
||||
}
|
||||
|
||||
@GetMapping("/oshi/netstat")
|
||||
public R getNetstatInfo(HttpServletRequest request) throws UnknownHostException {
|
||||
List<Map> result = OSHIUtils.getNetInfo();
|
||||
HashMap<Object, Object> data = Tool.MapUtil.newHashMap();
|
||||
data.put("list" ,result);
|
||||
|
||||
return R.ok(data);
|
||||
}
|
||||
}
|
||||
226
src/main/java/net/geedge/confagent/util/OSHIUtils.java
Normal file
226
src/main/java/net/geedge/confagent/util/OSHIUtils.java
Normal file
@@ -0,0 +1,226 @@
|
||||
package net.geedge.confagent.util;
|
||||
|
||||
import cn.hutool.log.Log;
|
||||
import oshi.SystemInfo;
|
||||
import oshi.hardware.*;
|
||||
import oshi.software.os.*;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class OSHIUtils {
|
||||
|
||||
private static Log log = Log.get();
|
||||
|
||||
private static final SystemInfo si = new SystemInfo();
|
||||
private static final OperatingSystem operatingSystem = si.getOperatingSystem();
|
||||
private static final HardwareAbstractionLayer hal = si.getHardware();
|
||||
|
||||
|
||||
/**
|
||||
* 系统信息
|
||||
* @return result
|
||||
*/
|
||||
public static Map<String,Object> getSystemInfo(){
|
||||
|
||||
HashMap<Object, Object> os = Tool.MapUtil.newHashMap();
|
||||
NetworkParams networkParams = operatingSystem.getNetworkParams();
|
||||
os.put("versionInfo",operatingSystem.getVersionInfo().toString());
|
||||
os.put("platform",si.getCurrentPlatform());
|
||||
os.put("family",operatingSystem.getFamily());
|
||||
os.put("manufacturer",operatingSystem.getManufacturer());
|
||||
os.put("bitness",operatingSystem.getBitness());
|
||||
os.put("bootTime",operatingSystem.getSystemBootTime());
|
||||
os.put("hostName",networkParams.getHostName());
|
||||
os.put("ipv4DefaultGateway",networkParams.getIpv4DefaultGateway());
|
||||
os.put("ipv6DefaultGateway",networkParams.getIpv6DefaultGateway());
|
||||
os.put("dnsServers",networkParams.getDnsServers());
|
||||
|
||||
HashMap<Object, Object> system = Tool.MapUtil.newHashMap();
|
||||
ComputerSystem computerSystem = hal.getComputerSystem();
|
||||
system.put("serialNumber",computerSystem.getSerialNumber());
|
||||
system.put("model",computerSystem.getModel());
|
||||
system.put("manufacturer",computerSystem.getManufacturer());
|
||||
system.put("hardwareUUID",computerSystem.getHardwareUUID());
|
||||
|
||||
|
||||
HashMap<Object, Object> baseBoardMap = Tool.MapUtil.newHashMap();
|
||||
Baseboard baseboard = computerSystem.getBaseboard();
|
||||
baseBoardMap.put("serialNumber",baseboard.getSerialNumber());
|
||||
baseBoardMap.put("model",baseboard.getModel());
|
||||
baseBoardMap.put("manufacturer",baseboard.getManufacturer());
|
||||
baseBoardMap.put("version",baseboard.getVersion());
|
||||
|
||||
HashMap<Object, Object> cpu = Tool.MapUtil.newHashMap();
|
||||
CentralProcessor processor = hal.getProcessor();
|
||||
cpu.put("physicalPackageCount",processor.getPhysicalPackageCount());
|
||||
cpu.put("physicalProcessorCount",processor.getPhysicalProcessorCount());
|
||||
cpu.put("logicalProcessorCount",processor.getLogicalProcessorCount());
|
||||
cpu.put("contextSwitches",processor.getContextSwitches());
|
||||
cpu.put("interrupts",processor.getInterrupts());
|
||||
cpu.put("maxFreq",processor.getMaxFreq());
|
||||
CentralProcessor.ProcessorIdentifier processorIdentifier = processor.getProcessorIdentifier();
|
||||
cpu.put("family",processorIdentifier.getFamily());
|
||||
cpu.put("identifier",processorIdentifier.getIdentifier());
|
||||
cpu.put("microarchitecture",processorIdentifier.getMicroarchitecture());
|
||||
cpu.put("model",processorIdentifier.getModel());
|
||||
cpu.put("name",processorIdentifier.getName());
|
||||
cpu.put("vendor",processorIdentifier.getVendor());
|
||||
cpu.put("stepping",processorIdentifier.getStepping());
|
||||
cpu.put("cpu64bit",processorIdentifier.isCpu64bit());
|
||||
|
||||
HashMap<Object, Object> memory = Tool.MapUtil.newHashMap();
|
||||
GlobalMemory memoryInfo = hal.getMemory();
|
||||
VirtualMemory virtualMemory = memoryInfo.getVirtualMemory();
|
||||
memory.put("total",memoryInfo.getTotal());
|
||||
memory.put("swapTotal",virtualMemory.getSwapTotal());
|
||||
memory.put("virtualMax",virtualMemory.getVirtualMax());
|
||||
memory.put("pageSize",memoryInfo.getPageSize());
|
||||
|
||||
List<HashMap<Object, Object>> disk = Tool.ListUtil.list(false);
|
||||
List<HWDiskStore> diskStores = hal.getDiskStores();
|
||||
for(HWDiskStore diskStore : diskStores) {
|
||||
if ( diskStore.getSize() > 0){
|
||||
HashMap<Object, Object> diskData = Tool.MapUtil.newHashMap();
|
||||
diskData.put("name",diskStore.getName());
|
||||
diskData.put("model",diskStore.getModel());
|
||||
diskData.put("serial",diskStore.getSerial());
|
||||
diskData.put("size",diskStore.getSize());
|
||||
disk.add(diskData);
|
||||
}
|
||||
}
|
||||
|
||||
List<HashMap<Object, Object>> network = Tool.ListUtil.list(false);
|
||||
List<NetworkIF> networkIFs = hal.getNetworkIFs();
|
||||
for (NetworkIF networkIF : networkIFs) {
|
||||
HashMap<Object, Object> networkData = Tool.MapUtil.newHashMap();
|
||||
networkData.put("index", networkIF.getIndex());
|
||||
networkData.put("name",networkIF.getName());
|
||||
networkData.put("ifAlias",networkIF.getIfAlias());
|
||||
networkData.put("ifType",networkIF.getIfType());
|
||||
networkData.put("speed",networkIF.getSpeed());
|
||||
networkData.put("mtu",networkIF.getMTU());
|
||||
networkData.put("ifOperStatus",networkIF.getIfOperStatus().getValue());
|
||||
networkData.put("macaddr",networkIF.getMacaddr());
|
||||
networkData.put("iPv4addr",networkIF.getIPv4addr());
|
||||
networkData.put("subnetMasks",networkIF.getSubnetMasks());
|
||||
networkData.put("iPv6addr",networkIF.getIPv6addr());
|
||||
network.add(networkData);
|
||||
}
|
||||
|
||||
HashMap<Object, Object> sensor = Tool.MapUtil.newHashMap();
|
||||
Sensors sensors = hal.getSensors();
|
||||
sensor.put("cpuTemperature",sensors.getCpuTemperature());
|
||||
sensor.put("cpuVoltage",sensors.getCpuVoltage());
|
||||
sensor.put("fanSpeeds",sensors.getFanSpeeds());
|
||||
|
||||
HashMap<String, Object> result = Tool.MapUtil.newHashMap();
|
||||
result.put("os",os);
|
||||
result.put("system",system);
|
||||
result.put("baseBoard",baseBoardMap);
|
||||
result.put("cpu",cpu);
|
||||
result.put("memory",memory);
|
||||
result.put("disk",disk);
|
||||
result.put("networkIF",network);
|
||||
result.put("sensor",sensor);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 进程信息
|
||||
* @return result
|
||||
*/
|
||||
public static List<Map> getProcessInfo() throws InterruptedException {
|
||||
|
||||
List<Map> result = Tool.ListUtil.list(false);
|
||||
List<OSProcess> oldProcess = operatingSystem.getProcesses();
|
||||
Thread.sleep(500);
|
||||
List<OSProcess> currentProcess = operatingSystem.getProcesses();
|
||||
Map<Integer, Object> cpuUsage = getCpuUsage(currentProcess, oldProcess);
|
||||
GlobalMemory memory = hal.getMemory();
|
||||
|
||||
for (OSProcess proc : currentProcess) {
|
||||
HashMap<String, Object> procsData = Tool.MapUtil.newHashMap();
|
||||
procsData.put("name",proc.getName());
|
||||
procsData.put("commandLine",proc.getCommandLine());
|
||||
procsData.put("processID",proc.getProcessID());
|
||||
procsData.put("parentProcessID",proc.getParentProcessID());
|
||||
procsData.put("startTime",proc.getStartTime());
|
||||
procsData.put("priority",proc.getPriority());
|
||||
procsData.put("cpuUsage",(double)cpuUsage.get(proc.getProcessID()) * 100d);
|
||||
procsData.put("memUsage",Tool.NumberUtil.div(proc.getResidentSetSize(), memory.getTotal()) * 100d);
|
||||
procsData.put("state",proc.getState().toString());
|
||||
procsData.put("openFiles",proc.getOpenFiles());
|
||||
procsData.put("threadCount",proc.getThreadCount());
|
||||
procsData.put("user",proc.getUser());
|
||||
procsData.put("group",proc.getGroup());
|
||||
procsData.put("path",proc.getPath());
|
||||
procsData.put("virtualSize",proc.getVirtualSize());
|
||||
procsData.put("residentSetSize",proc.getResidentSetSize());
|
||||
procsData.put("runTime",proc.getUpTime());
|
||||
result.add(procsData);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取进程cpu利用率
|
||||
* @param currentProc
|
||||
* @param oldProcess
|
||||
* @return
|
||||
*/
|
||||
private static Map<Integer,Object> getCpuUsage(List<OSProcess> currentProc, List<OSProcess> oldProcess) {
|
||||
|
||||
Map<Integer, OSProcess> procs = oldProcess.stream().collect(Collectors.toMap(OSProcess::getProcessID, Function.identity()));
|
||||
HashMap<Integer, Object> map = Tool.MapUtil.newHashMap();
|
||||
for (OSProcess proc : currentProc) {
|
||||
OSProcess old = procs.get(proc.getProcessID());
|
||||
map.put(proc.getProcessID(),proc.getProcessCpuLoadBetweenTicks(old));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 网络连接信息
|
||||
* @return result
|
||||
*/
|
||||
public static List<Map> getNetInfo() throws UnknownHostException {
|
||||
|
||||
List<Map> result = Tool.ListUtil.list(false);
|
||||
InternetProtocolStats internetProtocolStats = operatingSystem.getInternetProtocolStats();
|
||||
//获取网络连接
|
||||
List<InternetProtocolStats.IPConnection> connections = internetProtocolStats.getConnections();
|
||||
for (InternetProtocolStats.IPConnection connection : connections) {
|
||||
HashMap<String, Object> map = Tool.MapUtil.newHashMap();
|
||||
map.put("type",connection.getType());
|
||||
map.put("localAddress", InetAddress.getByAddress(connection.getLocalAddress()).toString().substring(1));
|
||||
map.put("localPort",connection.getLocalPort());
|
||||
map.put("foreignAddress",InetAddress.getByAddress(connection.getForeignAddress()).toString().substring(1));
|
||||
map.put("foreignPort",connection.getForeignPort());
|
||||
map.put("state",connection.getState().toString());
|
||||
map.put("transmitQueue",connection.getTransmitQueue());
|
||||
map.put("receiveQueue",connection.getReceiveQueue());
|
||||
if (connection.getowningProcessId() == -1 ){
|
||||
//未知进程 getowningProcessId 返回 -1 为避免获取进程name error
|
||||
map.put("processId",-1);
|
||||
map.put("processName","");
|
||||
map.put("processCmd","");
|
||||
}else {
|
||||
map.put("processId",connection.getowningProcessId());
|
||||
map.put("processName",operatingSystem.getProcess(connection.getowningProcessId()).getName());
|
||||
map.put("processCmd",operatingSystem.getProcess(connection.getowningProcessId()).getCommandLine());
|
||||
}
|
||||
|
||||
result.add(map);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
WORK_DIR=/opt/nezha/nz-talon
|
||||
|
||||
# Find Java
|
||||
if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
|
||||
if [[ -x "$WORK_DIR/jdk/bin/java" ]]; then
|
||||
JAVA_EXE="$WORK_DIR/jdk/bin/java"
|
||||
elif [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
|
||||
JAVA_EXE="$JAVA_HOME/bin/java"
|
||||
elif type -p java > /dev/null 2>&1; then
|
||||
JAVA_EXE=$(type -p java)
|
||||
|
||||
@@ -11,6 +11,8 @@ if [[ "${BRANCH_ARRAY[0]}" == "rel" ]] ; then
|
||||
fi
|
||||
RPM_FULL_NAME=${PACKAGE_NAME}-${PACKAGE_VERSION}-${ITERATION}.x86_64.rpm
|
||||
|
||||
# 依赖jdk 文件名
|
||||
JDK_FILENAME=jdk-8u202-linux-x64.tar.gz
|
||||
|
||||
# 初始化 minio
|
||||
mc alias set nz $MINIO_HOST $MINIO_USER $MINIO_PWD
|
||||
@@ -19,9 +21,11 @@ mc alias set nz $MINIO_HOST $MINIO_USER $MINIO_PWD
|
||||
BUILD_PATH=$CUR_PWD/build
|
||||
RPM_TALON_PATH=$BUILD_PATH/opt/nezha/nz-talon
|
||||
RPM_PROMTAIL_PATH=$BUILD_PATH/opt/nezha/promtail
|
||||
RPM_JDK_PATH=$RPM_TALON_PATH/jdk
|
||||
|
||||
mkdir -p $RPM_TALON_PATH $RPM_PROMTAIL_PATH
|
||||
mkdir -p $RPM_TALON_PATH/config
|
||||
mkdir -p $RPM_JDK_PATH
|
||||
|
||||
echo 'packaging nz-talon ...'
|
||||
#添加版本信息
|
||||
@@ -41,6 +45,10 @@ cp -f ./target/xjar $RPM_TALON_PATH
|
||||
cp -f ./src/main/resources/{application-prod.yml,application.yml,logback-spring.xml,config/auth.yml,config/token.auth,config/promtail.version} ${RPM_TALON_PATH}/config
|
||||
sed -i 's/<property name="log.path" value=".*"/<property name="log.path" value="\/var\/log\/nezha\/nz-talon\/"/g' ${RPM_TALON_PATH}/config/logback-spring.xml
|
||||
|
||||
# 准备 jdk 编译目录
|
||||
mc cp nz/depends/jdk/$JDK_FILENAME ./
|
||||
tar -xzf ./$JDK_FILENAME --strip-components 1 -C $RPM_JDK_PATH
|
||||
|
||||
# 下载 promtail
|
||||
mc cp nz/depends/loki/promtail-linux-amd64.zip ./
|
||||
unzip -o promtail-linux-amd64.zip -d $RPM_PROMTAIL_PATH
|
||||
|
||||
Reference in New Issue
Block a user