[agent] - start test get system info

This commit is contained in:
IceDerce
2022-11-28 14:04:37 +08:00
parent f18941e80e
commit 13b87b15cb
2 changed files with 56 additions and 0 deletions

View File

@@ -7,6 +7,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import javax.annotation.Resource;
import java.net.InetAddress;
import java.util.Properties;
@Configuration
public class collectSystemInfo {
@@ -21,10 +23,32 @@ public class collectSystemInfo {
@Bean
public void initialReadingEnvironment(){
// https://zhuanlan.zhihu.com/p/449416472
// https://cloud.tencent.com/developer/article/1919814
// https://blog.51cto.com/binghe001/5244823
try{
Properties props =System.getProperties();
InetAddress ip = InetAddress.getLocalHost();
String localName = ip.getHostName();
String osName = System.getProperty("os.name");
String userName = System.getProperty("user.name");
String osVersion = System.getProperty("os.version");
String osArch = System.getProperty("os.arch");
System.out.println("当前用户:" + userName);
System.out.println("用户的主目录:"+props.getProperty("user.home"));
System.out.println("用户的当前工作目录:"+props.getProperty("user.dir"));
System.out.println("主机名称:" + localName);
System.out.println("主机系统:" + osName);
System.out.println("系统版本:" + osVersion);
System.out.println("系统架构:" + osArch);
} catch (Exception e) {
e.printStackTrace();
}
}

View File

@@ -3,11 +3,43 @@ package io.wdd.agent;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.net.InetAddress;
import java.util.Properties;
@SpringBootTest
class AgentApplicationTests {
@Test
void contextLoads() {
// https://zhuanlan.zhihu.com/p/449416472
// https://cloud.tencent.com/developer/article/1919814
// https://blog.51cto.com/binghe001/5244823
try{
Properties props =System.getProperties();
InetAddress ip = InetAddress.getLocalHost();
String localName = ip.getHostName();
String osName = System.getProperty("os.name");
String userName = System.getProperty("user.name");
String osVersion = System.getProperty("os.version");
String osArch = System.getProperty("os.arch");
System.out.println("当前用户:" + userName);
System.out.println("用户的主目录:"+props.getProperty("user.home"));
System.out.println("用户的当前工作目录:"+props.getProperty("user.dir"));
System.out.println("主机名称:" + localName);
System.out.println("主机系统:" + osName);
System.out.println("系统版本:" + osVersion);
System.out.println("系统架构:" + osArch);
} catch (Exception e) {
e.printStackTrace();
}
}
}