Search in sources :

Example 1 with JVMAgentInfo

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

the class JVMLocalOSDetector method run.

@Override
public void run() {
    /**
     * step 1: build the skip local attach support set which contains those jvm with management.jar attached
     */
    Set<String> skipLocalAttachSupportSet = new HashSet<String>();
    for (JVMAgentInfo agentInfo : jvmAgentInfos.values()) {
        skipLocalAttachSupportSet.add(agentInfo.getId());
    }
    /**
     * step 2: scan out all java processes
     */
    List<JVMAgentInfo> appServerJVMInfos = JVMToolHelper.getAllLocalJvmInfo(new JVMPropertyFilter() {

        @Override
        public boolean isMatchAgentProperties(Properties jvmProperties) {
            /**
             * exclude all java tools
             */
            Enumeration<?> e = jvmProperties.propertyNames();
            while (e.hasMoreElements()) {
                String key = (String) e.nextElement();
                String val = jvmProperties.getProperty(key);
                for (String t : excludeJavaProc) {
                    if (val.indexOf(t) > -1) {
                        return false;
                    }
                }
            }
            return true;
        }

        @Override
        public boolean isMatchSystemProperties(Properties systemProperties) {
            return true;
        }
    }, true, skipLocalAttachSupportSet);
    if (appServerJVMInfos.isEmpty()) {
        return;
    }
    /**
     * step 3: see if need start a new worker to catch data for each JVM
     */
    for (JVMAgentInfo appServerInfo : appServerJVMInfos) {
        try {
            addWorker(appServerInfo);
        } catch (Exception e) {
            log.err(this, "JVMLocalOSDetector[" + this.cName + "] start worker FAIL: java process id=" + appServerInfo.getId(), e);
        }
    }
}
Also used : Enumeration(java.util.Enumeration) JVMAgentInfo(com.creditease.agent.helpers.jvmtool.JVMAgentInfo) Properties(java.util.Properties) HashSet(java.util.HashSet) JVMPropertyFilter(com.creditease.agent.helpers.jvmtool.JVMPropertyFilter)

Example 2 with JVMAgentInfo

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

the class JVMToolHelper method getLocalJvmInfo.

public static JVMAgentInfo getLocalJvmInfo(String procId, boolean needLocalAttachSupport) {
    if (procId == null || "".equals(procId)) {
        return null;
    }
    initJVMToolJarClassLoader();
    try {
        Object vm = method_AttachToVM.invoke(null, procId);
        if (vm != null) {
            if (needLocalAttachSupport) {
                startVMAgent(vm);
            }
            Properties jvmProperties = (Properties) method_GetAgentProperties.invoke(vm, (Object[]) null);
            // system properties
            Properties systemProperties = (Properties) method_GetSystemProperties.invoke(vm, (Object[]) null);
            method_DetachFromVM.invoke(vm);
            return new JVMAgentInfo(procId, jvmProperties, systemProperties);
        }
    } catch (Exception e) {
    // ignore
    }
    return null;
}
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)

Example 3 with JVMAgentInfo

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

the class JVMToolHelper method getAllLocalJvmInfo.

public static List<JVMAgentInfo> getAllLocalJvmInfo(JVMPropertyFilter filter, boolean needLocalAttachSupport, Set<String> skipLocalAttachSupport) {
    if (!isOracleJVM()) {
        return Collections.emptyList();
    }
    List<JVMAgentInfo> jvmPropertiesList = new ArrayList<JVMAgentInfo>();
    try {
        initJVMToolJarClassLoader();
        @SuppressWarnings("rawtypes") List allVMs = (List) method_VMList.invoke(null, (Object[]) null);
        getAllVMsInfo(filter, needLocalAttachSupport, jvmPropertiesList, allVMs, skipLocalAttachSupport);
    } catch (Exception e) {
    // ignore
    }
    return jvmPropertiesList;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) 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)

Example 4 with JVMAgentInfo

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

the class JVMContainerOSDetector method workerExist.

/**
 * check if the worker for this appServer exist
 */
public boolean workerExist(String pid, String url, List<String> urlList) {
    String JVMAccessURL = url + UAV_MOF_ROOT;
    for (BaseMonitorDataCatchWorker worker : workers.values()) {
        JVMAgentInfo appServerInfo = jvmAgentInfos.get(worker.getWorkerId());
        if (appServerInfo != null && JVMAccessURL.equals((appServerInfo.getJVMAccessURL()))) {
            urlList.clear();
            if (!pid.equals(appServerInfo.getId())) {
                // remove worker whose JVMAccessURL is the same but pid changes(usually restart)
                removeWorker(worker.getName());
                urlList.add(url);
            }
            return true;
        }
    }
    urlList.add(url);
    return false;
}
Also used : BaseMonitorDataCatchWorker(com.creditease.agent.feature.monitoragent.datacatch.BaseMonitorDataCatchWorker) JVMAgentInfo(com.creditease.agent.helpers.jvmtool.JVMAgentInfo)

Example 5 with JVMAgentInfo

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

the class LogProfileDataNotifyHandler method handle.

@Override
public void handle(MonitorDataFrame profileData) {
    /**
     * find out the logagent feature component and exchange the MDF
     */
    AgentFeatureComponent afc = (AgentFeatureComponent) this.getConfigManager().getComponent("logagent", "LogAgent");
    /**
     * NOTEļ¼šboth JMX and Http Scan supported
     */
    DetectorManager asmd = (DetectorManager) this.getConfigManager().getComponent(this.feature, "AppServerMonitorDetector_TimerWorker");
    if (null != afc && null != asmd) {
        JVMAgentInfo jvmAgentInfo = asmd.getJVMAgentInfo(profileData.getServerId());
        if (null == jvmAgentInfo) {
            log.warn(this, "can't find jvm agent info for serverid [" + profileData.getServerId() + "], the jvm may be dead.");
            return;
        }
        afc.exchange("logagent.profiledata.notify", profileData, jvmAgentInfo);
    } else {
        log.warn(this, "can't find agent feature component [logagent], this feature may not start. LogAgent-null(" + (afc == null) + "), DetectorManager-null(" + (asmd == null) + ")");
    }
}
Also used : JVMAgentInfo(com.creditease.agent.helpers.jvmtool.JVMAgentInfo) DetectorManager(com.creditease.agent.feature.monitoragent.detect.DetectorManager) AgentFeatureComponent(com.creditease.agent.spi.AgentFeatureComponent)

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