kezhenxu94 commented on a change in pull request #7069: URL: https://github.com/apache/skywalking/pull/7069#discussion_r647925154
########## 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: > cc @kezhenxu94 If you accept the start time, should we detect the changes base on the `start time` unchanged? We can detect from start time along with other properties, such as service instance name, this can be discussed in another issue or PR that focuses on event (changes detector). > And another 2 questions > > 1. Should we have a document to list all property keys? > 2. Should we consider a value holder or some mechanism to indicate value no change? Refer https://github.com/apache/skywalking/pull/7069/files#r647909609 This PR is related to events, but is not specifically only for events, right? Those unchanged properties are also to be displayed in UI and I feel like they must be reported no matter they changed or not. I don't think we want to do something in OAP like, "if this property (`libs`) is not changed, we query the previous one and copy its value to this record" (otherwise UI could get nothing for this property), no? -- 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]
