wu-sheng commented on a change in pull request #7069:
URL: https://github.com/apache/skywalking/pull/7069#discussion_r649209600



##########
File path: 
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMUtil.java
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.skywalking.apm.agent.core.jvm;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import java.lang.management.ManagementFactory;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.apache.skywalking.apm.agent.core.logging.api.ILog;
+import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
+import org.apache.skywalking.apm.agent.core.util.CollectionUtil;
+import org.apache.skywalking.apm.network.common.v3.KeyStringValuePair;
+
+public class JVMUtil {
+
+    private static final ILog LOGGER = LogManager.getLogger(JVMUtil.class);
+    private final static String PATH_SEPARATOR = "/";
+    private final static String JAR_SEPARATOR = "!";
+    private static List<String> LAST_LIB_JAR_NAMES = new ArrayList<>();
+    private static Set<ClassLoader> CURRENT_CLASSLOADER_LIST = new HashSet<>();
+
+    public static Set<ClassLoader> getCurrentClassloaderList() {
+        return CURRENT_CLASSLOADER_LIST;
+    }
+
+    /**
+     * Build the required JVM information to add to the instance properties
+     */
+    public static List<KeyStringValuePair> buildJVMInfo() {
+        List<KeyStringValuePair> jvmInfo = new ArrayList<>();
+        jvmInfo.add(KeyStringValuePair.newBuilder().setKey("Start 
Time").setValue(getVmStartTime()).build());
+        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
+        jvmInfo.add(KeyStringValuePair.newBuilder().setKey("JVM 
Arguments").setValue(gson.toJson(getVmArgs())).build());
+        List<String> libJarNames = getLibJarNames();
+        if (isLibJarNamesUpdated(libJarNames)) {
+            jvmInfo.add(KeyStringValuePair.newBuilder().setKey("Jar 
Dependencies").setValue(gson.toJson(libJarNames)).build());
+            LAST_LIB_JAR_NAMES.clear();
+            LAST_LIB_JAR_NAMES.addAll(libJarNames);
+        }
+        return jvmInfo;
+    }
+
+    private static String getVmStartTime() {
+        long startTime = ManagementFactory.getRuntimeMXBean().getStartTime();
+        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new 
Date(startTime));

Review comment:
       Take a look at `InstanceTraffic#combine`, there are some update logic 
existing.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to