Search in sources :

Example 6 with JVMAgentInfo

use of com.creditease.agent.helpers.jvmtool.JVMAgentInfo in project uavstack by uavorg.

the class JVMToolHelper method getAllVMsInfo.

/**
 * @param filter
 * @param needLocalAttachSupport
 * @param jvmPropertiesList
 * @param allVMs
 */
@SuppressWarnings("rawtypes")
private static void getAllVMsInfo(JVMPropertyFilter filter, boolean needLocalAttachSupport, List<JVMAgentInfo> jvmPropertiesList, List allVMs, Set<String> skipLocalAttachSupport) {
    for (Object vmInstance : allVMs) {
        /**
         * now we only support 64bit JVM, in case the 32bit JVM is attached with exception
         */
        try {
            String id = (String) method_VMId.invoke(vmInstance, (Object[]) null);
            // if the jvm is not started by the same user as MA, do not attach it (just in case of linux)
            if (isLinux() && !username.equals(Files.getOwner(Paths.get(("/proc/" + id))).getName())) {
                continue;
            }
            Object vm = method_AttachToVM.invoke(null, id);
            if (vm == null) {
                continue;
            }
            // agent properties
            Properties jvmProperties = (Properties) method_GetAgentProperties.invoke(vm, (Object[]) null);
            // system properties
            Properties systemProperties = (Properties) method_GetSystemProperties.invoke(vm, (Object[]) null);
            if (jvmProperties != null) {
                if (filter != null && (!filter.isMatchAgentProperties(jvmProperties) || !filter.isMatchSystemProperties(systemProperties))) {
                    continue;
                }
                boolean isNeedLocalAttachSupport = needLocalAttachSupport;
                if (skipLocalAttachSupport != null) {
                    isNeedLocalAttachSupport = (skipLocalAttachSupport.contains(id) == true) ? false : needLocalAttachSupport;
                }
                jvmProperties = fillJVMProperties(isNeedLocalAttachSupport, vm, jvmProperties);
                jvmPropertiesList.add(new JVMAgentInfo(id, jvmProperties, systemProperties));
            }
            method_DetachFromVM.invoke(vm);
        } catch (Exception e) {
            // ignore
            continue;
        }
    }
}
Also used : Properties(java.util.Properties) JVMAgentInfo(com.creditease.agent.helpers.jvmtool.JVMAgentInfo) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MBeanException(javax.management.MBeanException)

Aggregations

JVMAgentInfo (com.creditease.agent.helpers.jvmtool.JVMAgentInfo)6 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Properties (java.util.Properties)3 AttributeNotFoundException (javax.management.AttributeNotFoundException)3 InstanceNotFoundException (javax.management.InstanceNotFoundException)3 MBeanException (javax.management.MBeanException)3 ReflectionException (javax.management.ReflectionException)3 BaseMonitorDataCatchWorker (com.creditease.agent.feature.monitoragent.datacatch.BaseMonitorDataCatchWorker)1 DetectorManager (com.creditease.agent.feature.monitoragent.detect.DetectorManager)1 JVMPropertyFilter (com.creditease.agent.helpers.jvmtool.JVMPropertyFilter)1 AgentFeatureComponent (com.creditease.agent.spi.AgentFeatureComponent)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 HashSet (java.util.HashSet)1 List (java.util.List)1