Search in sources :

Example 1 with JVMPropertyFilter

use of com.creditease.agent.helpers.jvmtool.JVMPropertyFilter 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)

Aggregations

JVMAgentInfo (com.creditease.agent.helpers.jvmtool.JVMAgentInfo)1 JVMPropertyFilter (com.creditease.agent.helpers.jvmtool.JVMPropertyFilter)1 Enumeration (java.util.Enumeration)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1