From 13b87b15cbf828df98fa9c8944e616d343946a06 Mon Sep 17 00:00:00 2001 From: IceDerce Date: Mon, 28 Nov 2022 14:04:37 +0800 Subject: [PATCH] [agent] - start test get system info --- .../initial/bootup/collectSystemInfo.java | 24 ++++++++++++++ .../io/wdd/agent/AgentApplicationTests.java | 32 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/agent/src/main/java/io/wdd/agent/initial/bootup/collectSystemInfo.java b/agent/src/main/java/io/wdd/agent/initial/bootup/collectSystemInfo.java index de63177..65f29e4 100644 --- a/agent/src/main/java/io/wdd/agent/initial/bootup/collectSystemInfo.java +++ b/agent/src/main/java/io/wdd/agent/initial/bootup/collectSystemInfo.java @@ -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(); + } } diff --git a/agent/src/test/java/io/wdd/agent/AgentApplicationTests.java b/agent/src/test/java/io/wdd/agent/AgentApplicationTests.java index de178f6..53a9bda 100644 --- a/agent/src/test/java/io/wdd/agent/AgentApplicationTests.java +++ b/agent/src/test/java/io/wdd/agent/AgentApplicationTests.java @@ -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(); + } + + } }